Skip to content

Commit

Permalink
refactor(start)!: add new docker entrypoint options
Browse files Browse the repository at this point in the history
  • Loading branch information
pl-buiquang committed Nov 26, 2024
1 parent e1c2fb7 commit 4c7a3f3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
5 changes: 3 additions & 2 deletions admin_cohort/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@

logging.captureWarnings(True)

SOCKET_LOGGER_HOST = env("SOCKET_LOGGER_URL", default="localhost")
LOGGING = dict(version=1,
disable_existing_loggers=False,
loggers={
Expand Down Expand Up @@ -90,14 +91,14 @@
'info_handler': {
'level': "INFO",
'class': "admin_cohort.tools.logging.CustomSocketHandler",
'host': "localhost",
'host': SOCKET_LOGGER_HOST,
'port': DEFAULT_TCP_LOGGING_PORT,
'filters': ["request_headers_interceptor"]
},
'error_handler': {
'level': "ERROR",
'class': "admin_cohort.tools.logging.CustomSocketHandler",
'host': "localhost",
'host': SOCKET_LOGGER_HOST,
'port': DEFAULT_TCP_LOGGING_PORT,
'filters': ["request_headers_interceptor"]
},
Expand Down
40 changes: 30 additions & 10 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
WITH_CELERY_BEAT=""
WITH_KERBEROS=false
WITH_INIT=false
WITH_LOGGING=false
WITHOUT_APP_SERVER=false
WITH_DB_MIGRATION=false

# Parse options using getopts
while getopts "bki" opt; do
while getopts "bkilnd" opt; do
case $opt in
b)
WITH_CELERY_BEAT="-B"
Expand All @@ -17,6 +20,15 @@ while getopts "bki" opt; do
i)
WITH_INIT=true
;;
l)
WITH_LOGGING=true
;;
n)
WITHOUT_APP_SERVER=true
;;
d)
WITH_DB_MIGRATION=true
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
Expand All @@ -40,8 +52,11 @@ sed -i s/{{BACK_HOST}}/"$BACK_HOST"/g /etc/nginx/nginx.conf;
service nginx restart

source $VIRTUAL_ENV/bin/activate
python manage.py migrate --database="default"
python manage.py collectstatic --noinput

if [ "$WITH_DB_MIGRATION" = true ]; then
python manage.py migrate --database="default"
python manage.py collectstatic --noinput
fi

if [ "$WITH_INIT" = true ]; then
set +e
Expand All @@ -56,16 +71,21 @@ if [ "$WITH_KERBEROS" = true ]; then
cron
fi

celery -A admin_cohort worker $WITH_CELERY_BEAT --loglevel=INFO --logfile=/app/log/celery.log &
sleep 5
if [ "$WITH_LOGGING" = true ]; then
python setup_logging.py &
fi

if [ "$WITHOUT_APP_SERVER" = false ]; then
celery -A admin_cohort worker $WITH_CELERY_BEAT --loglevel=INFO --logfile=/app/log/celery.log &
sleep 5

python setup_logging.py &
# For websockets
daphne -p 8005 admin_cohort.asgi:application &
# For websockets
daphne -p 8005 admin_cohort.asgi:application &

gunicorn admin_cohort.wsgi --config .conf/gunicorn.conf.py
gunicorn admin_cohort.wsgi --config .conf/gunicorn.conf.py

tail -f /app/log/django.error.log
tail -f /app/log/django.error.log
fi

# Wait for any process to exit
wait -n
Expand Down

0 comments on commit 4c7a3f3

Please sign in to comment.