Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: log commands in Docker entrypoint #4826

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions api/scripts/run-docker.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/bin/sh
set -e

function waitfordb() {
waitfordb() {
if [ -z "${SKIP_WAIT_FOR_DB}" ]; then
python manage.py waitfordb "$@"
fi
}

function migrate () {
migrate () {
waitfordb && python manage.py migrate && python manage.py createcachetable
}
function serve() {
serve() {
# configuration parameters for statsd. Docs can be found here:
# https://docs.gunicorn.org/en/stable/instrumentation.html
export STATSD_PORT=${STATSD_PORT:-8125}
Expand All @@ -31,9 +31,9 @@ function serve() {
${STATSD_HOST:+--statsd-prefix $STATSD_PREFIX} \
app.wsgi
}
function run_task_processor() {
run_task_processor() {
waitfordb --waitfor 30 --migrations
if [[ -n "$ANALYTICS_DATABASE_URL" || -n "$DJANGO_DB_NAME_ANALYTICS" ]]; then
if [ -n "$ANALYTICS_DATABASE_URL" ] || [ -n "$DJANGO_DB_NAME_ANALYTICS" ]; then
waitfordb --waitfor 30 --migrations --database analytics
fi
RUN_BY_PROCESSOR=1 exec python manage.py runprocessor \
Expand All @@ -42,29 +42,31 @@ function run_task_processor() {
--numthreads ${TASK_PROCESSOR_NUM_THREADS:-5} \
--queuepopsize ${TASK_PROCESSOR_QUEUE_POP_SIZE:-10}
}
function migrate_analytics_db(){
migrate_analytics_db(){
# if `$ANALYTICS_DATABASE_URL` or DJANGO_DB_NAME_ANALYTICS is set
# run the migration command
if [[ -z "$ANALYTICS_DATABASE_URL" && -z "$DJANGO_DB_NAME_ANALYTICS" ]]; then
if [ -z "$ANALYTICS_DATABASE_URL" ] && [ -z "$DJANGO_DB_NAME_ANALYTICS" ]; then
return 0
fi
python manage.py migrate --database analytics
}
function bootstrap(){
bootstrap(){
python manage.py bootstrap
}
function default(){
default(){
python manage.py "$@"
}

if [ "$1" == "migrate" ]; then
set -x

if [ "$1" = "migrate" ]; then
migrate
migrate_analytics_db
elif [ "$1" == "serve" ]; then
elif [ "$1" = "serve" ]; then
serve
elif [ "$1" == "run-task-processor" ]; then
elif [ "$1" = "run-task-processor" ]; then
run_task_processor
elif [ "$1" == "migrate-and-serve" ]; then
elif [ "$1" = "migrate-and-serve" ]; then
migrate
migrate_analytics_db
bootstrap
Expand Down
Loading