Skip to content

Commit

Permalink
Migrate to gunicorn instead of uwsgi
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit74 committed Sep 26, 2023
1 parent 3c5a520 commit e87d636
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
18 changes: 12 additions & 6 deletions dev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
image: postgres:15.2-bullseye
container_name: zf_postgresdb
ports:
- 5432:5432
- 127.0.0.1:5432:5432
volumes:
- pg_data_zimfarm:/var/lib/postgresql/data
- ./postgres-initdb:/docker-entrypoint-initdb.d
Expand All @@ -14,16 +14,22 @@ services:
backend:
build: ../dispatcher/backend
container_name: zf_backend
command: python main.py
command:
- gunicorn
- --conf
- /app/gunicorn_conf.py
- --bind
- 0.0.0.0:8000
- --reload
- main:application
volumes:
- ../dispatcher/backend/src:/app
- ../dispatcher/backend/prestart.sh:/app/prestart.sh
#- ../dispatcher/backend/prestart.sh:/app/prestart.sh
- ../dispatcher/backend/docs:/app/docs
- ../dispatcher/backend/maint-scripts:/app/maint-scripts
ports:
- 8000:8000
- 127.0.0.1:8000:8000
environment:
BINDING_HOST: 0.0.0.0
DEBUG: 1
JWT_SECRET: DH8kSxcflUVfNRdkEiJJCn2dOOKI3qfw
POSTGRES_URI: postgresql+psycopg://zimfarm:zimpass@postgresdb:5432/zimfarm
Expand All @@ -36,7 +42,7 @@ services:
volumes:
- ../dispatcher/frontend-ui/src:/app
ports:
- 8001:80
- 127.0.0.1:8001:80
environment:
ZIMFARM_WEBAPI: http://localhost:8000/v1
depends_on:
Expand Down
17 changes: 4 additions & 13 deletions dispatcher/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
FROM rgaudin/uwsgi-nginx:python3.8
FROM python:3.8-slim-bookworm
LABEL zimfarm=true
LABEL org.opencontainers.image.source https://github.com/openzim/zimfarm

RUN pip install --no-cache-dir -U pip
RUN pip install --no-cache-dir uwsgi==2.0.18
RUN pip install --no-cache-dir -U pip gunicorn==21.2.0

COPY requirements.txt /app/
RUN pip install --no-cache-dir -r /app/requirements.txt
Expand All @@ -16,16 +15,6 @@ WORKDIR /app/
ENV DOCS_DIR /app/docs
ENV INIT_PASSWORD admin

# from uwsgi-nginx
ENV UWSGI_INI /app/uwsgi.ini
ENV UWSGI_CHEAPER 4
ENV UWSGI_CHEAPER_STEP 2
ENV UWSGI_PROCESSES 32
ENV NGINX_MAX_UPLOAD 0
ENV NGINX_WORKER_PROCESSES 1
ENV LISTEN_PORT 80
ENV NGINV_ENABLE_GZIP 1

# mailgun for notifications
ENV MAILGUN_API_URL https://api.mailgun.net/v3/mg.farm.openzim.org
ENV MAILGUN_FROM Zimfarm <[email protected]>
Expand All @@ -52,3 +41,5 @@ RUN chmod +x /app/prestart.sh
COPY supervisor-listener.py /usr/local/bin/supervisor-listener
RUN chmod +x /usr/local/bin/supervisor-listener
COPY periodic.conf /etc/supervisor/conf.d/periodic.conf

CMD ["gunicorn", "--conf", "/app/gunicorn_conf.py", "--bind", "0.0.0.0:8000", "main:application"]
9 changes: 9 additions & 0 deletions dispatcher/backend/src/gunicorn_conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Gunicorn config variables
loglevel = "info"
errorlog = "-" # stderr
accesslog = "-" # stdout
worker_tmp_dir = "/dev/shm"
graceful_timeout = 60
timeout = 60
keepalive = 5
threads = 3

0 comments on commit e87d636

Please sign in to comment.