Skip to content

Commit

Permalink
feat: expose extra env variables for more flexible infra tuning (#1445)
Browse files Browse the repository at this point in the history
Expose extra variables for a more flexible infra tuning
  • Loading branch information
ab-smith authored Jan 28, 2025
1 parent 73570ee commit 4a867cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
5 changes: 4 additions & 1 deletion backend/ciso_assistant/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,11 +418,14 @@ def set_ciso_assistant_url(_, __, event_dict):
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
DEFAULT_FROM_EMAIL = "[email protected]"


## Huey settings
HUEY_FILE_PATH = os.environ.get("HUEY_FILE_PATH", BASE_DIR / "db" / "huey.db")

HUEY = {
"huey_class": "huey.SqliteHuey",
"name": "ciso_assistant",
"filename": BASE_DIR / "db" / "huey.db",
"filename": HUEY_FILE_PATH,
"results": True, # would be interesting for debug
"immediate": False, # set to False to run in "live" mode regardless of DEBUG, otherwise it will follow
}
17 changes: 12 additions & 5 deletions backend/startup.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#!/usr/bin/env bash
# wait for database to be ready

if [ ! -n "$DJANGO_SETTINGS_MODULE" ]; then
export DJANGO_SETTINGS_MODULE=ciso_assistant.settings
fi

if [ ! -n "$DJANGO_SECRET_KEY" ]; then
if [ ! -f db/django_secret_key ]; then
cat /proc/sys/kernel/random/uuid >db/django_secret_key
Expand All @@ -13,16 +11,25 @@ if [ ! -n "$DJANGO_SECRET_KEY" ]; then
export DJANGO_SECRET_KEY=$(<db/django_secret_key)
echo "Django secret key read from file"
fi

while ! python manage.py showmigrations iam >/dev/null; do
echo "database not ready; waiting"
sleep 15
done

poetry run python manage.py migrate --settings="${DJANGO_SETTINGS_MODULE}"
poetry run python manage.py storelibraries --settings="${DJANGO_SETTINGS_MODULE}"
if [ -n "$DJANGO_SUPERUSER_EMAIL" ]; then
poetry run python manage.py createsuperuser --noinput --settings="${DJANGO_SETTINGS_MODULE}"
fi

exec gunicorn --chdir ciso_assistant --bind :8000 --timeout 100 --keep-alive 30 --workers=3 --env RUN_MAIN=true ciso_assistant.wsgi:application
# Set default values for Gunicorn configuration
GUNICORN_WORKERS=${GUNICORN_WORKERS:-3}
GUNICORN_TIMEOUT=${GUNICORN_TIMEOUT:-100}
GUNICORN_KEEPALIVE=${GUNICORN_KEEPALIVE:-30}

exec gunicorn --chdir ciso_assistant \
--bind :8000 \
--timeout $GUNICORN_TIMEOUT \
--keep-alive $GUNICORN_KEEPALIVE \
--workers=$GUNICORN_WORKERS \
--env RUN_MAIN=true \
ciso_assistant.wsgi:application

0 comments on commit 4a867cf

Please sign in to comment.