2024-08-02 11:05:02 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -e
|
|
|
|
set -u
|
|
|
|
# DEBUG
|
|
|
|
set -x
|
|
|
|
|
|
|
|
check_app_is_there() {
|
|
|
|
if [ ! -f "./manage.py" ]; then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
deploy() {
|
|
|
|
# detect if existing deployment (TODO only works with sqlite)
|
|
|
|
if [ -f "${program_dir}/db/db.sqlite3" ]; then
|
|
|
|
echo "INFO: detected EXISTING deployment"
|
|
|
|
./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
|
2024-09-24 12:52:18 +00:00
|
|
|
INIT_ORG="${INIT_ORG:-example-org}"
|
|
|
|
INIT_USER="${INIT_USER:-user@example.org}"
|
|
|
|
INIT_PASSWD="${INIT_PASSWD:-1234}"
|
2024-10-16 19:09:16 +00:00
|
|
|
ADMIN='True'
|
2024-10-16 19:54:54 +00:00
|
|
|
PREDEFINED_TOKEN="${PREDEFINED_TOKEN:-}"
|
2024-09-24 12:52:18 +00:00
|
|
|
./manage.py add_institution "${INIT_ORG}"
|
2024-09-19 17:05:28 +00:00
|
|
|
# TODO: one error on add_user, and you don't add user anymore
|
2024-10-16 19:54:54 +00:00
|
|
|
./manage.py add_user "${INIT_ORG}" "${INIT_USER}" "${INIT_PASSWD}" "${ADMIN}" "${PREDEFINED_TOKEN}"
|
2024-09-24 12:52:18 +00:00
|
|
|
|
2024-10-16 20:07:40 +00:00
|
|
|
if [ "${DEMO:-}" = 'true' ]; then
|
2024-09-24 12:52:18 +00:00
|
|
|
./manage.py up_snapshots example/snapshots/ "${INIT_USER}"
|
2024-09-24 12:50:57 +00:00
|
|
|
fi
|
2024-08-02 11:05:02 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
runserver() {
|
|
|
|
PORT="${PORT:-8000}"
|
2024-09-24 12:52:18 +00:00
|
|
|
if [ "${DEBUG:-}" ]; then
|
2024-08-02 11:05:02 +00:00
|
|
|
./manage.py runserver 0.0.0.0:${PORT}
|
|
|
|
else
|
|
|
|
# TODO
|
|
|
|
#./manage.py collectstatic
|
|
|
|
true
|
2024-09-24 12:52:18 +00:00
|
|
|
if [ "${EXPERIMENTAL:-}" ]; then
|
2024-08-02 11:05:02 +00:00
|
|
|
# TODO
|
|
|
|
# reloading on source code changing is a debugging future, maybe better then use debug
|
|
|
|
# src https://stackoverflow.com/questions/12773763/gunicorn-autoreload-on-source-change/24893069#24893069
|
|
|
|
# gunicorn with 1 worker, with more than 1 worker this is not expected to work
|
|
|
|
#gunicorn --access-logfile - --error-logfile - -b :${PORT} trustchain_idhub.wsgi:application
|
|
|
|
true
|
|
|
|
else
|
|
|
|
./manage.py runserver 0.0.0.0:${PORT}
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
|
|
|
program_dir='/opt/devicehub-django'
|
|
|
|
cd "${program_dir}"
|
|
|
|
deploy
|
|
|
|
runserver
|
|
|
|
}
|
|
|
|
|
|
|
|
main "${@}"
|