2022-06-01 18:50:44 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
function error_handler() {
|
|
|
|
>&2 echo "Exited with BAD EXIT CODE '${2}' in ${0} script at line: ${1}."
|
|
|
|
exit "$2"
|
|
|
|
}
|
|
|
|
trap 'error_handler ${LINENO} $?' ERR
|
|
|
|
set -o errtrace -o errexit -o nounset -o pipefail
|
|
|
|
|
|
|
|
# run migrations
|
|
|
|
export FLASK_APP=/app/src/spiffworkflow_backend
|
|
|
|
|
2022-06-24 21:41:14 +00:00
|
|
|
if [[ "${DOWNGRADE_DB:-}" == "true" ]]; then
|
2022-06-01 18:50:44 +00:00
|
|
|
echo 'Downgrading database...'
|
|
|
|
poetry run flask db downgrade
|
|
|
|
fi
|
|
|
|
|
2022-06-23 18:53:13 +00:00
|
|
|
if [[ "${SPIFFWORKFLOW_BACKEND_UPGRADE_DB:-}" == "true" ]]; then
|
2022-06-01 18:50:44 +00:00
|
|
|
echo 'Upgrading database...'
|
|
|
|
poetry run flask db upgrade
|
|
|
|
fi
|
|
|
|
|
2022-06-23 18:53:13 +00:00
|
|
|
port="${SPIFFWORKFLOW_BACKEND_PORT:-}"
|
2022-06-01 18:50:44 +00:00
|
|
|
if [[ -z "$port" ]]; then
|
|
|
|
port=7000
|
|
|
|
fi
|
|
|
|
|
2022-06-01 19:49:05 +00:00
|
|
|
additional_args=""
|
|
|
|
|
|
|
|
if [[ "${APPLICATION_ROOT:-}" != "/" ]]; then
|
|
|
|
additional_args="${additional_args} -e SCRIPT_NAME=${APPLICATION_ROOT}"
|
2022-06-01 18:50:44 +00:00
|
|
|
fi
|
2022-06-01 19:49:05 +00:00
|
|
|
|
2022-07-07 18:44:19 +00:00
|
|
|
export IS_GUNICORN="true"
|
|
|
|
|
2022-06-01 19:49:05 +00:00
|
|
|
# THIS MUST BE THE LAST COMMAND!
|
2022-06-24 21:41:14 +00:00
|
|
|
exec poetry run gunicorn ${additional_args} --bind "0.0.0.0:$port" --workers=3 --timeout 90 --log-level debug wsgi:app
|