This repository has been archived by the owner on Nov 14, 2023. It is now read-only.
forked from cvat-ai/cvat
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework the backend entrypoint (cvat-ai#6750)
* Make it possible to run migrations without starting the server, and vice versa. This is not yet used, but it will be needed later to enable database initialization/upgrade in a configuration with multiple server containers. * Wait for migrations to complete in worker containers, to be safe. Workers also use the database. * Add a help message and a way to run the shell (useful for development). * Add support for initialization scripts, which helps simplify the smokescreen hack needed for the webhook tests.
- Loading branch information
1 parent
ea9ce9f
commit 994f84c
Showing
15 changed files
with
98 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,68 @@ | ||
#!/bin/sh | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
set -eu | ||
|
||
${HOME}/wait-for-it.sh ${CVAT_POSTGRES_HOST}:5432 -t 0 | ||
python3 ${HOME}/manage.py migrate | ||
python3 ${HOME}/manage.py collectstatic --no-input | ||
exec /usr/bin/supervisord -c supervisord/server.conf | ||
fail() { | ||
printf >&2 "%s: %s\n" "$0" "$1" | ||
exit 1 | ||
} | ||
|
||
wait_for_db() { | ||
~/wait-for-it.sh "${CVAT_POSTGRES_HOST}:5432" -t 0 | ||
} | ||
|
||
cmd_bash() { | ||
exec bash "$@" | ||
} | ||
|
||
cmd_init() { | ||
wait_for_db | ||
~/manage.py migrate | ||
} | ||
|
||
cmd_run() { | ||
if [ "$#" -ne 1 ]; then | ||
fail "run: expected 1 argument" | ||
fi | ||
|
||
if [ "$1" = "server" ]; then | ||
~/manage.py collectstatic --no-input | ||
fi | ||
|
||
wait_for_db | ||
|
||
echo "waiting for migrations to complete..." | ||
while ! ~/manage.py migrate --check; do | ||
sleep 1 | ||
done | ||
|
||
exec supervisord -c "supervisord/$1.conf" | ||
} | ||
|
||
if [ $# -eq 0 ]; then | ||
echo >&2 "$0: at least one subcommand required" | ||
echo >&2 "" | ||
echo >&2 "available subcommands:" | ||
echo >&2 " bash <bash args...>" | ||
echo >&2 " init" | ||
echo >&2 " run <config name>" | ||
exit 1 | ||
fi | ||
|
||
for init_script in /etc/cvat/init.d/*; do | ||
if [ -r "$init_script" ]; then | ||
. "$init_script" | ||
fi | ||
done | ||
|
||
while [ $# -ne 0 ]; do | ||
if [ "$(type -t "cmd_$1")" != "function" ]; then | ||
fail "unknown subcommand: $1" | ||
fi | ||
|
||
cmd_name="$1" | ||
|
||
shift | ||
|
||
"cmd_$cmd_name" "$@" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# We want to exclude webhooks_receiver from SSRF protection, | ||
# so that the server can access it. | ||
# --allow-address doesn't allow hostnames, so we have to resolve | ||
# the IP address ourselves. | ||
webhooks_ip_addr="$(getent hosts webhooks | head -1 | awk '{ print $1 }')" | ||
export SMOKESCREEN_OPTS="$SMOKESCREEN_OPTS --allow-address=\"$webhooks_ip_addr\"" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters