2022-10-12 14:22:22 +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
|
|
|
|
|
2023-02-15 22:21:37 +00:00
|
|
|
if [[ "${SPIFFWORKFLOW_BACKEND_WAIT_FOR_DB_TO_BE_READY:-}" == "true" ]]; then
|
2022-10-17 02:32:16 +00:00
|
|
|
echo 'Waiting for db to be ready...'
|
|
|
|
poetry run python ./bin/wait_for_db_to_be_ready.py
|
|
|
|
fi
|
|
|
|
|
2023-02-15 22:21:37 +00:00
|
|
|
if [[ "${SPIFFWORKFLOW_BACKEND_DOWNGRADE_DB:-}" == "true" ]]; then
|
2022-10-12 14:22:22 +00:00
|
|
|
echo 'Downgrading database...'
|
|
|
|
poetry run flask db downgrade
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "${SPIFFWORKFLOW_BACKEND_UPGRADE_DB:-}" == "true" ]]; then
|
|
|
|
echo 'Upgrading database...'
|
|
|
|
poetry run flask db upgrade
|
|
|
|
fi
|
|
|
|
|
2023-02-07 20:38:29 +00:00
|
|
|
if [[ -z "${GUNICORN_LOG_LEVEL:-}" ]]; then
|
|
|
|
GUNICORN_LOG_LEVEL=debug
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z "${GUNICORN_TIMEOUT_SECONDS:-}" ]]; then
|
|
|
|
GUNICORN_TIMEOUT_SECONDS=90
|
|
|
|
fi
|
|
|
|
|
2022-10-12 14:22:22 +00:00
|
|
|
port="${SPIFFWORKFLOW_BACKEND_PORT:-}"
|
|
|
|
if [[ -z "$port" ]]; then
|
|
|
|
port=7000
|
|
|
|
fi
|
|
|
|
|
|
|
|
additional_args=""
|
|
|
|
|
2023-02-15 22:21:37 +00:00
|
|
|
if [[ "${SPIFFWORKFLOW_BACKEND_APPLICATION_ROOT:-}" != "/" ]]; then
|
|
|
|
additional_args="${additional_args} -e SCRIPT_NAME=${SPIFFWORKFLOW_BACKEND_APPLICATION_ROOT}"
|
2022-10-12 14:22:22 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# HACK: if loading fixtures for acceptance tests when we do not need multiple workers
|
|
|
|
# it causes issues with attempting to add duplicate data to the db
|
|
|
|
workers=3
|
|
|
|
if [[ "${SPIFFWORKFLOW_BACKEND_LOAD_FIXTURE_DATA:-}" == "true" ]]; then
|
|
|
|
workers=1
|
|
|
|
fi
|
|
|
|
|
2022-10-12 19:28:52 +00:00
|
|
|
if [[ "${SPIFFWORKFLOW_BACKEND_RUN_DATA_SETUP:-}" != "false" ]]; then
|
|
|
|
SPIFFWORKFLOW_BACKEND_FAIL_ON_INVALID_PROCESS_MODELS=false poetry run python bin/save_all_bpmn.py
|
|
|
|
fi
|
|
|
|
|
2023-02-21 19:02:16 +00:00
|
|
|
if [[ -n "${SPIFFWORKFLOW_BACKEND_GIT_SSH_PRIVATE_KEY:-}" ]]; then
|
|
|
|
if [[ -z "${SPIFFWORKFLOW_BACKEND_GIT_SSH_PRIVATE_KEY_PATH}" ]]; then
|
|
|
|
export SPIFFWORKFLOW_BACKEND_GIT_SSH_PRIVATE_KEY_PATH=$(mktemp /tmp/ssh_private_key.XXXXXX)
|
|
|
|
fi
|
|
|
|
chmod 600 "${SPIFFWORKFLOW_BACKEND_GIT_SSH_PRIVATE_KEY_PATH}"
|
|
|
|
echo "${SPIFFWORKFLOW_BACKEND_GIT_SSH_PRIVATE_KEY}" >"${SPIFFWORKFLOW_BACKEND_GIT_SSH_PRIVATE_KEY_PATH}"
|
|
|
|
fi
|
|
|
|
|
2023-01-25 20:09:05 +00:00
|
|
|
# Assure that the the Process Models Directory is initialized as a git repo
|
2023-02-15 22:07:12 +00:00
|
|
|
git init "${SPIFFWORKFLOW_BACKEND_BPMN_SPEC_ABSOLUTE_DIR}"
|
|
|
|
git config --global --add safe.directory "${SPIFFWORKFLOW_BACKEND_BPMN_SPEC_ABSOLUTE_DIR}"
|
2022-10-12 14:22:22 +00:00
|
|
|
|
2023-01-25 20:09:05 +00:00
|
|
|
export IS_GUNICORN="true"
|
2022-10-12 14:22:22 +00:00
|
|
|
# THIS MUST BE THE LAST COMMAND!
|
2023-02-07 20:38:29 +00:00
|
|
|
exec poetry run gunicorn ${additional_args} \
|
|
|
|
--bind "0.0.0.0:$port" \
|
|
|
|
--workers="$workers" \
|
|
|
|
--limit-request-line 8192 \
|
|
|
|
--timeout "$GUNICORN_TIMEOUT_SECONDS" \
|
|
|
|
--capture-output \
|
|
|
|
--access-logfile '-' \
|
|
|
|
--log-level "$GUNICORN_LOG_LEVEL" wsgi:app
|