From e2e74926ca82c463d12dd819f9eb656430a7bc40 Mon Sep 17 00:00:00 2001 From: pedro Date: Thu, 16 Nov 2023 17:03:19 +0100 Subject: [PATCH] docker: put init data as part of dev deployment use django default env vars on a production deployment --- .env.example | 9 ++++++--- docker-compose_idhub-temp.yml | 2 +- docker/idhub.entrypoint.sh | 26 ++++++++++++++------------ 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/.env.example b/.env.example index 4cf5538..fcf9230 100644 --- a/.env.example +++ b/.env.example @@ -15,9 +15,6 @@ IDHUB_TIME_ZONE='Europe/Madrid' #IDHUB_SECRET_KEY='uncomment-it-and-fill-this' -IDHUB_USER='admin' -IDHUB_PASSWD='admin' -IDHUB_EMAIL='admin@example.org' # enable dev flags when DEVELOPMENT deployment IDHUB_DEPLOYMENT='DEVELOPMENT' # adapt to your domain in a production/reverse proxy env @@ -31,3 +28,9 @@ IDHUB_EMAIL_HOST_PASSWORD="smtp_passwd" IDHUB_EMAIL_PORT=25 IDHUB_EMAIL_USE_TLS=True IDHUB_EMAIL_BACKEND="django.core.mail.backends.smtp.EmailBackend" + +# replace with production data +# this is used when IDHUB_DEPLOYMENT is not equal to DEVELOPMENT +IDHUB_USER='admin' +IDHUB_PASSWD='admin' +IDHUB_EMAIL='admin@example.org' diff --git a/docker-compose_idhub-temp.yml b/docker-compose_idhub-temp.yml index b3ed1e3..1d0d274 100644 --- a/docker-compose_idhub-temp.yml +++ b/docker-compose_idhub-temp.yml @@ -5,6 +5,7 @@ services: init: true image: dkr-dsg.ac.upc.edu/trustchain-oc1-orchestral/idhub:latest environment: + - DEPLOYMENT=${IDHUB_DEPLOYMENT} - SECRET_KEY=${IDHUB_SECRET_KEY:-publicsecretisnotsecureVtmKBfxpVV47PpBCF2Nzz2H6qnbd} - ALLOWED_HOSTS=${IDHUB_ALLOWED_HOSTS:-*} - STATIC_ROOT=${IDHUB_STATIC_ROOT:-/static/} @@ -13,7 +14,6 @@ services: - DJANGO_SUPERUSER_USERNAME=${IDHUB_USER} - DJANGO_SUPERUSER_PASSWORD=${IDHUB_PASSWD} - DJANGO_SUPERUSER_EMAIL=${IDHUB_EMAIL} - - DEPLOYMENT=${IDHUB_DEPLOYMENT} - CSRF_TRUSTED_ORIGINS=${IDHUB_CSRF_TRUSTED_ORIGINS} - DEFAULT_FROM_EMAIL=${IDHUB_DEFAULT_FROM_EMAIL} - EMAIL_HOST=${IDHUB_EMAIL_HOST} diff --git a/docker/idhub.entrypoint.sh b/docker/idhub.entrypoint.sh index a2cbc22..62b444f 100755 --- a/docker/idhub.entrypoint.sh +++ b/docker/idhub.entrypoint.sh @@ -8,23 +8,25 @@ main() { # go to the same path as the script cd "$(dirname ${0})" - # enable dev flags when DEVELOPMENT deployment - if [ "${DEPLOYMENT}" = 'DEVELOPMENT' ]; then - export DEBUG=True - export DEVELOPMENT=True - fi - # move the migrate thing in docker entrypoint # inspired by https://medium.com/analytics-vidhya/django-with-docker-and-docker-compose-python-part-2-8415976470cc ./manage.py migrate - printf "creating initial Datas\n" >&2 - ./manage.py initial_datas - #./manage.py collectstatic + # enable dev flags when DEVELOPMENT deployment + if [ "${DEPLOYMENT}" = 'DEVELOPMENT' ]; then + export DEBUG=True + export DEVELOPMENT=True - printf "creating superuser \n user: ${DJANGO_SUPERUSER_USERNAME}\n password: ${DJANGO_SUPERUSER_PASSWORD}\n email: ${DJANGO_SUPERUSER_EMAIL}\n" >&2 - # thanks https://stackoverflow.com/questions/6244382/how-to-automate-createsuperuser-on-django/59467533#59467533 - ./manage.py createsuperuser --no-input + printf "This is DEVELOPMENT DEPLOYMENT: including demo hardcoded data\n creating initial Datas\n" >&2 + ./manage.py initial_datas + + else + printf "creating superuser \n user: ${DJANGO_SUPERUSER_USERNAME}\n password: ${DJANGO_SUPERUSER_PASSWORD}\n email: ${DJANGO_SUPERUSER_EMAIL}\n" >&2 + ## thanks https://stackoverflow.com/questions/6244382/how-to-automate-createsuperuser-on-django/59467533#59467533 + ./manage.py createsuperuser --no-input + fi + + #./manage.py collectstatic ./manage.py runserver 0.0.0.0:${PORT} }