2023-10-31 10:00:08 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -e
|
|
|
|
set -u
|
|
|
|
set -x
|
|
|
|
|
|
|
|
main() {
|
2023-12-01 09:10:11 +00:00
|
|
|
idhub_dir='/opt/idhub'
|
|
|
|
cd "${idhub_dir}"
|
2023-10-31 10:00:08 +00:00
|
|
|
|
2023-12-01 09:10:11 +00:00
|
|
|
if [ ! -f "./manage.py" ]; then
|
|
|
|
cat <<END
|
|
|
|
ERROR: you need to map your idhub git repo volume to docker, suggested volume mapping is:
|
|
|
|
|
|
|
|
volumes:
|
|
|
|
- ./IdHub:/opt/idhub
|
|
|
|
END
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# detect if existing deployment
|
|
|
|
if [ -f "${idhub_dir}/db.sqlite3" ]; then
|
|
|
|
echo "INFO: detected EXISTING deployment"
|
|
|
|
./manage.py makemigrations
|
|
|
|
./manage.py migrate
|
|
|
|
else
|
|
|
|
# move the migrate thing in docker entrypoint
|
|
|
|
# inspired by https://medium.com/analytics-vidhya/django-with-docker-and-docker-compose-python-part-2-8415976470cc
|
|
|
|
echo "INFO detected NEW deployment"
|
|
|
|
./manage.py migrate
|
|
|
|
|
|
|
|
if [ "${DEPLOYMENT}" = 'DEVELOPMENT' ]; then
|
|
|
|
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
|
|
|
|
fi
|
2023-11-16 16:03:19 +00:00
|
|
|
|
2023-10-31 10:00:08 +00:00
|
|
|
# enable dev flags when DEVELOPMENT deployment
|
|
|
|
if [ "${DEPLOYMENT}" = 'DEVELOPMENT' ]; then
|
|
|
|
export DEBUG=True
|
|
|
|
export DEVELOPMENT=True
|
2023-11-16 16:03:19 +00:00
|
|
|
fi
|
2023-10-31 10:00:08 +00:00
|
|
|
|
2023-11-16 16:03:19 +00:00
|
|
|
#./manage.py collectstatic
|
2023-10-31 10:00:08 +00:00
|
|
|
|
|
|
|
./manage.py runserver 0.0.0.0:${PORT}
|
|
|
|
}
|
|
|
|
|
|
|
|
main "${@}"
|