Skip to content

Commit 53eead6

Browse files
authored
Set dynamic env variables for Gunicorn workers and port in Docker entrypoint script (#166)
* fix(docker): set default values for Gunicorn workers and port in entrypoint script * fix(docker): update default number of Gunicorn workers to 3 in entrypoint script's comment
1 parent 79fcb57 commit 53eead6

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

docker/server/entrypoint.sh

+12-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,18 @@ fi
4040
# ===================
4141
if [ "${APP_ENV^^}" = "PRODUCTION" ]; then
4242

43+
# if the number of workers is not set, default to 3
44+
if [ -z "${GUNICORN_WORKERS}" ]; then
45+
GUNICORN_WORKERS=3
46+
fi
47+
48+
# if the port is not set, default to 8081
49+
if [ -z "${GUNICORN_PORT}" ]; then
50+
GUNICORN_PORT=8081
51+
fi
52+
4353
# Run Gunicorn / Django
4454
printf "\n" && echo " Running Gunicorn / Django"
45-
echo "Running: gunicorn api.wsgi -b 0.0.0.0:8081 --workers=1 --keep-alive 20 --log-file=- --log-level debug --access-logfile=/var/log/accesslogs/gunicorn --capture-output --timeout 50"
46-
gunicorn api.wsgi -b 0.0.0.0:8081 --workers=1 --keep-alive 20 --log-file=- --log-level debug --access-logfile=/var/log/accesslogs/gunicorn --capture-output --timeout 50
55+
echo "Running: gunicorn api.wsgi -b 0.0.0.0:$GUNICORN_PORT --workers=$GUNICORN_WORKERS --keep-alive 20 --log-file=- --log-level debug --access-logfile=/var/log/accesslogs/gunicorn --capture-output --timeout 50"
56+
gunicorn api.wsgi -b 0.0.0.0:"$GUNICORN_PORT" --workers="$GUNICORN_WORKERS" --keep-alive 20 --log-file=- --log-level debug --access-logfile=/var/log/accesslogs/gunicorn --capture-output --timeout 50
4757
fi

server/.env.example

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ API_SECRET_KEY="supersecretkey"
55
API_ALLOWED_HOSTS=".localhost 127.0.0.1 [::1]"
66
API_CORS_ALLOWED_ORIGINS="http://localhost:3000 https://localhost:3000"
77

8+
# need to set POSTGRES_HOST to the name of the container in docker-compose when using docker on production
89
POSTGRES_HOST=localhost
910
POSTGRES_NAME=postgres
1011
POSTGRES_USER=postgres
@@ -15,4 +16,8 @@ DJANGO_SUPERUSER_PASSWORD=Password123
1516
DJANGO_SUPERUSER_EMAIL=admin@test.com
1617
DJANGO_SUPERUSER_USERNAME=admin
1718

19+
# production
20+
GUNICORN_WORKERS=3
21+
GUNICORN_PORT=8081
22+
1823
FRONTEND_URL="http://localhost:3000"

0 commit comments

Comments
 (0)