docker: put init data as part of dev deployment

use django default env vars on a production deployment
This commit is contained in:
pedro 2023-11-16 17:03:19 +01:00
parent 81a6398f02
commit e2e74926ca
3 changed files with 21 additions and 16 deletions

View File

@ -15,9 +15,6 @@
IDHUB_TIME_ZONE='Europe/Madrid' IDHUB_TIME_ZONE='Europe/Madrid'
#IDHUB_SECRET_KEY='uncomment-it-and-fill-this' #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 # enable dev flags when DEVELOPMENT deployment
IDHUB_DEPLOYMENT='DEVELOPMENT' IDHUB_DEPLOYMENT='DEVELOPMENT'
# adapt to your domain in a production/reverse proxy env # 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_PORT=25
IDHUB_EMAIL_USE_TLS=True IDHUB_EMAIL_USE_TLS=True
IDHUB_EMAIL_BACKEND="django.core.mail.backends.smtp.EmailBackend" 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'

View File

@ -5,6 +5,7 @@ services:
init: true init: true
image: dkr-dsg.ac.upc.edu/trustchain-oc1-orchestral/idhub:latest image: dkr-dsg.ac.upc.edu/trustchain-oc1-orchestral/idhub:latest
environment: environment:
- DEPLOYMENT=${IDHUB_DEPLOYMENT}
- SECRET_KEY=${IDHUB_SECRET_KEY:-publicsecretisnotsecureVtmKBfxpVV47PpBCF2Nzz2H6qnbd} - SECRET_KEY=${IDHUB_SECRET_KEY:-publicsecretisnotsecureVtmKBfxpVV47PpBCF2Nzz2H6qnbd}
- ALLOWED_HOSTS=${IDHUB_ALLOWED_HOSTS:-*} - ALLOWED_HOSTS=${IDHUB_ALLOWED_HOSTS:-*}
- STATIC_ROOT=${IDHUB_STATIC_ROOT:-/static/} - STATIC_ROOT=${IDHUB_STATIC_ROOT:-/static/}
@ -13,7 +14,6 @@ services:
- DJANGO_SUPERUSER_USERNAME=${IDHUB_USER} - DJANGO_SUPERUSER_USERNAME=${IDHUB_USER}
- DJANGO_SUPERUSER_PASSWORD=${IDHUB_PASSWD} - DJANGO_SUPERUSER_PASSWORD=${IDHUB_PASSWD}
- DJANGO_SUPERUSER_EMAIL=${IDHUB_EMAIL} - DJANGO_SUPERUSER_EMAIL=${IDHUB_EMAIL}
- DEPLOYMENT=${IDHUB_DEPLOYMENT}
- CSRF_TRUSTED_ORIGINS=${IDHUB_CSRF_TRUSTED_ORIGINS} - CSRF_TRUSTED_ORIGINS=${IDHUB_CSRF_TRUSTED_ORIGINS}
- DEFAULT_FROM_EMAIL=${IDHUB_DEFAULT_FROM_EMAIL} - DEFAULT_FROM_EMAIL=${IDHUB_DEFAULT_FROM_EMAIL}
- EMAIL_HOST=${IDHUB_EMAIL_HOST} - EMAIL_HOST=${IDHUB_EMAIL_HOST}

View File

@ -8,23 +8,25 @@ main() {
# go to the same path as the script # go to the same path as the script
cd "$(dirname ${0})" 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 # move the migrate thing in docker entrypoint
# inspired by https://medium.com/analytics-vidhya/django-with-docker-and-docker-compose-python-part-2-8415976470cc # inspired by https://medium.com/analytics-vidhya/django-with-docker-and-docker-compose-python-part-2-8415976470cc
./manage.py migrate ./manage.py migrate
printf "creating initial Datas\n" >&2 # enable dev flags when DEVELOPMENT deployment
./manage.py initial_datas if [ "${DEPLOYMENT}" = 'DEVELOPMENT' ]; then
#./manage.py collectstatic 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 printf "This is DEVELOPMENT DEPLOYMENT: including demo hardcoded data\n creating initial Datas\n" >&2
# thanks https://stackoverflow.com/questions/6244382/how-to-automate-createsuperuser-on-django/59467533#59467533 ./manage.py initial_datas
./manage.py createsuperuser --no-input
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} ./manage.py runserver 0.0.0.0:${PORT}
} }