-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathboot_server_in_docker
More file actions
executable file
·119 lines (99 loc) · 4.52 KB
/
boot_server_in_docker
File metadata and controls
executable file
·119 lines (99 loc) · 4.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env bash
function error_handler() {
echo >&2 "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
function log_info() {
echo "BOOT SERVER IN DOCKER ($(date +"%Y-%m-%d %H:%M:%S")): $1"
}
# example command:
# SPIFFWORKFLOW_BACKEND_PERMISSIONS_FILE_NAME=example.yml SPIFFWORKFLOW_BACKEND_DATABASE_TYPE=sqlite SPIFFWORKFLOW_BACKEND_ENV=local_docker SPIFFWORKFLOW_BACKEND_RUN_BACKGROUND_SCHEDULER_IN_CREATE_APP=true FLASK_DEBUG=0 FLASK_SESSION_SECRET_KEY=HEY SPIFFWORKFLOW_BACKEND_BPMN_SPEC_ABSOLUTE_DIR="${HOME}/projects/github/sartography/sample-process-models/" ./bin/boot_server_in_docker
if [[ -z "${FLASK_DEBUG:-}" ]]; then
export FLASK_DEBUG=0
fi
export UV_NO_SYNC=true
if [[ "${SPIFFWORKFLOW_BACKEND_WAIT_FOR_DB_TO_BE_READY:-}" == "true" ]]; then
echo 'Waiting for db to be ready...'
uv run python ./bin/wait_for_db_to_be_ready.py
fi
if [[ "${SPIFFWORKFLOW_BACKEND_DOWNGRADE_DB:-}" == "true" ]]; then
echo 'Downgrading database...'
uv run flask db downgrade
fi
if [[ "${SPIFFWORKFLOW_BACKEND_UPGRADE_DB:-}" == "true" ]]; then
echo 'Upgrading database...'
uv run flask db upgrade
fi
if [[ -z "${UVICORN_LOG_LEVEL:-}" ]]; then
UVICORN_LOG_LEVEL=debug
fi
if [[ -z "${GUNICORN_LOG_LEVEL:-}" ]]; then
GUNICORN_LOG_LEVEL=debug
fi
if [[ -z "${GUNICORN_TIMEOUT_SECONDS:-}" ]]; then
GUNICORN_TIMEOUT_SECONDS=90
fi
port="${SPIFFWORKFLOW_BACKEND_PORT:-}"
if [[ -z "$port" ]]; then
port=7000
fi
additional_args=""
app_root="${SPIFFWORKFLOW_BACKEND_APPLICATION_ROOT:-}"
if [[ -n "$app_root" ]] && [[ "${app_root}" != "/" ]]; then
echo >&2 "ERROR: SPIFFWORKFLOW_BACKEND_APPLICATION_ROOT has been set. This variable has been renamed to SPIFFWORKFLOW_BACKEND_WSGI_PATH_PREFIX. Please use that instead."
exit 1
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
worker_count=4
if [[ "${SPIFFWORKFLOW_BACKEND_LOAD_FIXTURE_DATA:-}" == "true" ]]; then
worker_count=1
fi
export SERVER_WORKER_COUNT="$worker_count"
if [[ -z "${SPIFFWORKFLOW_BACKEND_GIT_SSH_PRIVATE_KEY_PATH:-}" ]]; then
if [[ -n "${SPIFFWORKFLOW_BACKEND_GIT_SSH_PRIVATE_KEY:-}" ]]; then
export SPIFFWORKFLOW_BACKEND_GIT_SSH_PRIVATE_KEY_PATH=$(mktemp /tmp/ssh_private_key.XXXXXX)
chmod 600 "${SPIFFWORKFLOW_BACKEND_GIT_SSH_PRIVATE_KEY_PATH}"
echo "${SPIFFWORKFLOW_BACKEND_GIT_SSH_PRIVATE_KEY}" >"${SPIFFWORKFLOW_BACKEND_GIT_SSH_PRIVATE_KEY_PATH}"
fi
fi
if [[ "${SPIFFWORKFLOW_BACKEND_GIT_CLONE_PROCESS_MODELS:-}" == "true" ]]; then
./bin/clone_process_models
fi
if ! git -C "$SPIFFWORKFLOW_BACKEND_BPMN_SPEC_ABSOLUTE_DIR" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
# ensure that the Process Models Directory is initialized as a git repo
log_info "Running git init"
git init "${SPIFFWORKFLOW_BACKEND_BPMN_SPEC_ABSOLUTE_DIR}"
fi
# # VersionOneThree and the process_instance_file_data db => filesystem migration have run on all necessary environments,
# so commenting out run_all.py.
# one day we might have another blocking-style data migration that we want to complete before the app boots.
# in that case, probably update run_all.py to not run VersionOneThree and filesystem migration, but instead the new function.
# we also might want to build a db-backed system to let other non-api containers know when this long-running migration is
# happening (somewhat like schema migrations (storing versions in a db table) to handle data migrations),
# so it could poll some table and not start its work until the database is fully migrated.
# log_info "Running data migrations"
# uv run python ./bin/data_migrations/run_all.py
##### DO THIS right before starting the server
if [[ "${SPIFFWORKFLOW_BACKEND_RUN_DATA_SETUP:-}" != "false" ]]; then
if [[ -z "${SPIFFWORKFLOW_BACKEND_FAIL_ON_INVALID_PROCESS_MODELS:-}" ]]; then
export SPIFFWORKFLOW_BACKEND_FAIL_ON_INVALID_PROCESS_MODELS=false
fi
uv run python bin/refresh_all_caches.py
fi
log_info "Starting gunicorn server"
export IS_GUNICORN="true"
# THIS MUST BE THE LAST COMMAND!
# Run with gunicorn as per recommendation from uvicorn
# https://www.uvicorn.org/deployment/
exec uv run gunicorn ${additional_args} \
--bind "0.0.0.0:$port" \
--workers="$worker_count" \
--limit-request-line 8192 \
--timeout "$GUNICORN_TIMEOUT_SECONDS" \
--capture-output \
--access-logfile '-' \
--worker-class uvicorn_worker.UvicornWorker \
--log-level "$GUNICORN_LOG_LEVEL" spiff_web_server:connexion_app