forked from github/plane
dev: instance configuration
This commit is contained in:
parent
97b7a27695
commit
485e3e6a0f
31
apiserver/bin/instance_configuration.py
Normal file
31
apiserver/bin/instance_configuration.py
Normal file
@ -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()
|
@ -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 -
|
||||
|
@ -1 +1 @@
|
||||
from .instance import Instance
|
||||
from .instance import Instance, InstanceConfiguration
|
@ -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",)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user