Skip to content

Commit

Permalink
feat: log commands in Docker entrypoint (#4826)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolodato authored Nov 12, 2024
1 parent cbd60d9 commit b2d7500
Showing 1 changed file with 15 additions and 13 deletions.
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

0 comments on commit b2d7500

Please sign in to comment.