Skip to content

Commit

Permalink
Fix entrypoint to use gunicorn configurations and fix variables from …
Browse files Browse the repository at this point in the history
…dockerfile
  • Loading branch information
nataliaweni committed Dec 28, 2023
1 parent ca4ddb1 commit 254764b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
32 changes: 12 additions & 20 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
#!/bin/bash

export GUNICORN_APP=${GUNICORN_APP:-"app.wsgi:application"}
export CELERY_APP=${CELERY_APP:-"app.wsgi:celery"}
export GUNICORN_LOG_CONF=${GUNICORN_LOG_CONF:-"${PROJECT_PATH}/docker/gunicorn/gunicorn-logging.conf"}
export GUNICORN_APP=${GUNICORN_APP:-"chats.asgi"}
export CELERY_APP=${CELERY_APP:-"chats"}
export GUNICORN_CONF=${GUNICORN_CONF:-"${PROJECT_PATH}/docker/gunicorn/gunicorn.conf.py"}
export LOG_LEVEL=${LOG_LEVEL:-"INFO"}
#export GUNICORN_CONF=${GUNICORN_CONF:-"python:app.gunicorn"
export CELERY_MAX_WORKERS=${CELERY_MAX_WORKERS:-'4'}
export CELERY_BEAT_DATABASE_FILE=${CELERY_BEAT_DATABASE_FILE:-'/tmp/celery_beat_database'}
export CELERY_MAX_WORKERS=${CELERY_MAX_WORKERS:-'6'}
# export CELERY_BEAT_DATABASE_FILE=${CELERY_BEAT_DATABASE_FILE:-'/tmp/celery_beat_database'}
export HEALTHCHECK_TIMEOUT=${HEALTHCHECK_TIMEOUT:-"10"}

echo "Running collectstatic"
python manage.py collectstatic --noinput

echo "Starting server"
exec gunicorn chats.asgi -c gunicorn.conf.py

do_gosu(){
user="$1"
shift 1
Expand Down Expand Up @@ -45,30 +37,30 @@ do_gosu(){


if [[ "start" == "$1" ]]; then
do_gosu "${APP_USER}:${APP_GROUP}" exec gunicorn "${GUNICORN_APP}" \
--name="${APP_NAME}" \
do_gosu "${PROJECT_USER}:${PROJECT_GROUP}" python manage.py collectstatic --noinput
do_gosu "${PROJECT_USER}:${PROJECT_GROUP}" exec gunicorn "${GUNICORN_APP}" \
--name="${APPLICATION_NAME}" \
--chdir="${PROJECT_PATH}" \
--bind=0.0.0.0:8080 \
--log-config="${GUNICORN_LOG_CONF}" \
--bind=0.0.0.0:8000 \
-c "${GUNICORN_CONF}"
elif [[ "celery-worker" == "$1" ]]; then
celery_queue="celery"
if [ "${2}" ] ; then
celery_queue="${2}"
fi
do_gosu "${APP_USER}:${APP_GROUP}" exec celery \
-A "${CELERY_APP}" --workdir="${APP_PATH}" worker \
do_gosu "${PROJECT_USER}:${PROJECT_GROUP}" exec celery \
-A "${CELERY_APP}" --workdir="${PROJECT_PATH}" worker \
-Q "${celery_queue}" \
-O fair \
-l "${LOG_LEVEL}" \
--autoscale=4,1
--autoscale=${CELERY_MAX_WORKERS},1
elif [[ "healthcheck-celery-worker" == "$1" ]]; then
celery_queue="celery"
if [ "${2}" ] ; then
celery_queue="${2}"
fi
HEALTHCHECK_OUT=$(
do_gosu "${APP_USER}:${APP_GROUP}" celery -A "${CELERY_APP}" \
do_gosu "${PROJECT_USER}:${PROJECT_GROUP}" celery -A "${CELERY_APP}" \
inspect ping \
-d "${celery_queue}@${HOSTNAME}" \
--timeout "${HEALTHCHECK_TIMEOUT}" 2>&1
Expand Down
1 change: 0 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ FROM python:${PYTHON_VERSION}-slim as base

ARG POETRY_VERSION

ARG APP_PORT="8000"
ARG APP_VERSION="0.1"

# set environment variables
Expand Down

0 comments on commit 254764b

Please sign in to comment.