diff --git a/apiserver/bin/takeoff.ee b/apiserver/bin/takeoff.ee new file mode 100644 index 0000000000..18feb40875 --- /dev/null +++ b/apiserver/bin/takeoff.ee @@ -0,0 +1,28 @@ +#!/bin/bash +set -e +python manage.py wait_for_db +python manage.py migrate + +# Create the default bucket +#!/bin/bash + +# Collect system information +HOSTNAME=$(hostname) +MAC_ADDRESS=$(ip link show | awk '/ether/ {print $2}' | head -n 1) +CPU_INFO=$(cat /proc/cpuinfo) +MEMORY_INFO=$(free -h) +DISK_INFO=$(df -h) + +# Concatenate information and compute SHA-256 hash +SIGNATURE=$(echo "$HOSTNAME$MAC_ADDRESS$CPU_INFO$MEMORY_INFO$DISK_INFO" | sha256sum | awk '{print $1}') + +# Export the variables +export MACHINE_SIGNATURE=$SIGNATURE + +# Register instance +python manage.py setup_instance $INSTANCE_ADMIN_EMAIL + +# Create the default bucket +python manage.py create_bucket + +exec gunicorn -w $GUNICORN_WORKERS -k uvicorn.workers.UvicornWorker plane.asgi:application --bind 0.0.0.0:${PORT:-8000} --max-requests 1200 --max-requests-jitter 1000 --access-logfile - diff --git a/apiserver/plane/app/management/commands/__init__.py b/apiserver/plane/app/management/commands/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/apiserver/plane/app/management/commands/cloud_instance.py b/apiserver/plane/license/management/commands/setup_instance.py similarity index 75% rename from apiserver/plane/app/management/commands/cloud_instance.py rename to apiserver/plane/license/management/commands/setup_instance.py index 8e08f597ca..36d06c5b14 100644 --- a/apiserver/plane/app/management/commands/cloud_instance.py +++ b/apiserver/plane/license/management/commands/setup_instance.py @@ -1,8 +1,10 @@ # Python imports import json import secrets +import uuid # Django imports +from django.contrib.auth.hashers import make_password from django.core.management.base import BaseCommand, CommandError from django.utils import timezone @@ -32,7 +34,11 @@ class Command(BaseCommand): user = User.objects.filter(email=admin_email).first() if user is None: - raise CommandError("User not found") + user = User.objects.create( + email=admin_email, + username=uuid.uuid4().hex, + password=make_password(uuid.uuid4().hex), + ) try: # Check if the instance is registered @@ -40,7 +46,7 @@ class Command(BaseCommand): if instance is None: instance = Instance.objects.create( - instance_name="Plane Cloud US", + instance_name="Plane Enterprise", instance_id=secrets.token_hex(12), license_key=None, api_key=secrets.token_hex(8), @@ -53,20 +59,16 @@ class Command(BaseCommand): ) # Get or create an instance admin - _ , created = InstanceAdmin.objects.get_or_create( + _, created = InstanceAdmin.objects.get_or_create( user=user, instance=instance, role=20, is_verified=True ) if not created: - raise CommandError("given email is already an instance admin") - - self.stdout.write( - self.style.SUCCESS( - f"Successful" + self.stdout.write( + self.style.WARNING("given email is already an instance admin") ) - ) + + self.stdout.write(self.style.SUCCESS(f"Successful")) except Exception as e: print(e) - raise CommandError( - "Failure" - ) \ No newline at end of file + raise CommandError("Failure")