From 485e3e6a0ffbe217e83ef2c86d0c42a2ac490efa Mon Sep 17 00:00:00 2001 From: pablohashescobar Date: Wed, 8 Nov 2023 11:13:04 +0000 Subject: [PATCH] dev: instance configuration --- apiserver/bin/instance_configuration.py | 31 ++++++++++++++++++++++ apiserver/bin/takeoff | 2 ++ apiserver/plane/license/models/__init__.py | 2 +- apiserver/plane/license/models/instance.py | 15 ++++++++++- 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 apiserver/bin/instance_configuration.py diff --git a/apiserver/bin/instance_configuration.py b/apiserver/bin/instance_configuration.py new file mode 100644 index 000000000..159c5d397 --- /dev/null +++ b/apiserver/bin/instance_configuration.py @@ -0,0 +1,31 @@ +import os, sys + + +sys.path.append("/code") + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "plane.settings.production") + +import django + +django.setup() + +def load_config(): + from plane.license.models import InstanceConfiguration + # List of config keys to load from env + config_keys = ['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY', 'AWS_STORAGE_BUCKET_NAME', 'AWS_S3_ENDPOINT_URL', 'AWS_REGION_NAME'] + + for key in config_keys: + value = os.getenv(key) + if value is not None: + obj, created = InstanceConfiguration.objects.update_or_create( + key=key, + value=value + ) + action = 'Created' if created else 'Updated' + sys.stdout.write(sys.stdout.style.SUCCESS(f'{action} {key} with value from environment variable.')) + else: + sys.stdout.write(sys.stdout.style.WARNING(f'Environment variable {key} not set.')) + + +if __name__ == "__main__": + load_config() \ No newline at end of file diff --git a/apiserver/bin/takeoff b/apiserver/bin/takeoff index e43bd6219..e219adabc 100755 --- a/apiserver/bin/takeoff +++ b/apiserver/bin/takeoff @@ -3,4 +3,6 @@ set -e python manage.py wait_for_db python manage.py migrate +python bin/instance_configuration.py + exec gunicorn -w 8 -k uvicorn.workers.UvicornWorker plane.asgi:application --bind 0.0.0.0:8000 --max-requests 1200 --max-requests-jitter 1000 --access-logfile - diff --git a/apiserver/plane/license/models/__init__.py b/apiserver/plane/license/models/__init__.py index fe1f8009d..603ecb7af 100644 --- a/apiserver/plane/license/models/__init__.py +++ b/apiserver/plane/license/models/__init__.py @@ -1 +1 @@ -from .instance import Instance \ No newline at end of file +from .instance import Instance, InstanceConfiguration \ No newline at end of file diff --git a/apiserver/plane/license/models/instance.py b/apiserver/plane/license/models/instance.py index ef06e8780..8629390cc 100644 --- a/apiserver/plane/license/models/instance.py +++ b/apiserver/plane/license/models/instance.py @@ -4,7 +4,7 @@ from django.conf import settings # Module imports from plane.db.models import BaseModel - +from plane.db.mixins import AuditModel class Instance(BaseModel): instance_id = models.CharField(max_length=25, unique=True) @@ -27,3 +27,16 @@ class Instance(BaseModel): verbose_name_plural = "Instances" db_table = "instances" ordering = ("-created_at",) + + + +class InstanceConfiguration(AuditModel): + key = models.CharField(max_length=100, unique=True) + value = models.TextField() + + class Meta: + verbose_name = "Instance Configuration" + verbose_name_plural = "Instance Configurations" + db_table = "instance_configurations" + ordering = ("-created_at",) +