Skip to content

Commit aa8721a

Browse files
committed
fix: switch to gunicorn WSGI server
1 parent 8a28715 commit aa8721a

File tree

9 files changed

+37
-59
lines changed

9 files changed

+37
-59
lines changed

Dockerfile

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.9-slim-buster
1+
FROM python:3.10-slim-buster
22

33
ENV PYTHONUNBUFFERED 1
44
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
@@ -15,11 +15,7 @@ ENV WEBUI_VERSION=8.7.0
1515
ENV NGINX_WORKER_PROCESSES=1
1616
ENV NGINX_WORKER_CONNECTIONS=1024
1717

18-
ENV UWSGI_PROCESSES=5
19-
ENV UWSGI_LISTEN=100
20-
ENV UWSGI_BUFFER_SIZE=8192
21-
ENV UWSGI_MAX_WORKER_LIFETIME=30
22-
ENV UWSGI_WORKER_LIFETIME_DELTA=3
18+
ENV GUNICORN_WORKERS=5
2319

2420
ENV HEARTBEAT_SEVERITY=major
2521
ENV HK_EXPIRED_DELETE_HRS=2
@@ -77,7 +73,7 @@ COPY requirements*.txt /app/
7773
# hadolint ignore=DL3013
7874
RUN pip install --no-cache-dir pip virtualenv jinja2 && \
7975
python3 -m venv /venv && \
80-
/venv/bin/pip install --no-cache-dir --upgrade setuptools && \
76+
/venv/bin/pip install --no-cache-dir --upgrade setuptools wheel && \
8177
/venv/bin/pip install --no-cache-dir --requirement /app/requirements.txt && \
8278
/venv/bin/pip install --no-cache-dir --requirement /app/requirements-docker.txt
8379
ENV PATH $PATH:/venv/bin

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ API to ease deployment more generally:
126126
`NGINX_WORKER_CONNECTIONS`
127127
- maximum number of simultaneous connections that can be opened by a worker process (default:`1024`)
128128

129-
`UWSGI_PROCESSES`
130-
- number of processes for uWSGI (default:`5`)
129+
`GUNICORN_WORKERS`
130+
- number of worker processes for Gunicorn (default:`5`)
131131

132132
`UWSGI_LISTEN`
133133
- max number of concurrent connections (default:`100`)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
bind = '127.0.0.1:29000'
3+
4+
chdir = '/app'
5+
daemon = False
6+
raw_env = [
7+
'SCRIPT_NAME=/api',
8+
]
9+
worker_tmp_dir = '/dev/shm'
10+
workers = {{ env.GUNICORN_WORKERS }}
11+
12+
{%- if env.DEBUG %}
13+
loglevel = 'debug'
14+
{%- endif %}

config/templates/app/nginx.conf.j2

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,12 @@ http {
4747
access_log /dev/stdout main;
4848

4949
location /api {
50-
include /etc/nginx/uwsgi_params;
51-
uwsgi_pass backend;
50+
proxy_pass http://backend;
5251

53-
uwsgi_param Host $host;
54-
uwsgi_param X-Real-IP $remote_addr;
55-
uwsgi_param X-Forwarded-For $proxy_add_x_forwarded_for;
56-
uwsgi_param X-Forwarded-Proto $http_x_forwarded_proto;
52+
proxy_set_header Host $host;
53+
proxy_set_header X-Real-IP $remote_addr;
54+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
55+
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
5756
}
5857

5958
root /web;

config/templates/app/supervisord.conf.j2

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ logfile=/tmp/supervisord.log
44
loglevel={{ env.SUPERVISORD_LOG_LEVEL|lower or 'debug' }}
55
pidfile=/tmp/supervisord.pid
66

7-
[program:uwsgi]
8-
command=/venv/bin/uwsgi --ini /app/uwsgi.ini
7+
[program:gunicorn]
8+
command=/venv/bin/gunicorn wsgi:app -c /app/gunicorn.conf.py
9+
autostart=true
10+
autorestart=true
911
redirect_stderr=true
1012

1113
[program:nginx]

config/templates/app/uwsgi.ini.j2

Lines changed: 0 additions & 34 deletions
This file was deleted.

contrib/kubernetes/backend/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ RUN apt-get update && apt-get install -y \
1010

1111
RUN pip install --no-cache-dir virtualenv && \
1212
virtualenv --python=python3 /venv && \
13-
/venv/bin/pip install uwsgi alerta alerta-server==$VERSION
13+
/venv/bin/pip install gunicorn alerta alerta-server==$VERSION
1414

1515
ENV PATH $PATH:/venv/bin
1616

docker-entrypoint.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ALERTA_CONF_FILE=${ALERTA_CONF_FILE:-/app/alerta.conf}
77
ALERTA_SVR_CONF_FILE=${ALERTA_SVR_CONF_FILE:-/app/alertad.conf}
88
ALERTA_WEB_CONF_FILE=${ALERTA_WEB_CONF_FILE:-/web/config.json}
99
NGINX_CONF_FILE=/app/nginx.conf
10-
UWSGI_CONF_FILE=/app/uwsgi.ini
10+
GUNICORN_CONF_FILE=/app/gunicorn.conf.py
1111
SUPERVISORD_CONF_FILE=/app/supervisord.conf
1212

1313
ADMIN_USER=${ADMIN_USERS%%,*}
@@ -67,12 +67,13 @@ if [ ! -f "${NGINX_CONF_FILE}" ]; then
6767
echo "# Create nginx configuration file."
6868
python3 -c "${JINJA2}" < ${NGINX_CONF_FILE}.j2 >${NGINX_CONF_FILE}
6969
fi
70+
cat ${NGINX_CONF_FILE}
7071
nginx -t -c ${NGINX_CONF_FILE}
7172

72-
# Generate uWSGI config, if not supplied.
73-
if [ ! -f "${UWSGI_CONF_FILE}" ]; then
74-
echo "# Create uWSGI configuration file."
75-
python3 -c "${JINJA2}" < ${UWSGI_CONF_FILE}.j2 >${UWSGI_CONF_FILE}
73+
# Generate Gunicorn config, if not supplied.
74+
if [ ! -f "${GUNICORN_CONF_FILE}" ]; then
75+
echo "# Create Gunicorn configuration file."
76+
python3 -c "${JINJA2}" < ${GUNICORN_CONF_FILE}.j2 >${GUNICORN_CONF_FILE}
7677
fi
7778

7879
# Generate web config, if not supplied.
@@ -88,7 +89,7 @@ echo Alerta Client ${CLIENT_VERSION}
8889
echo Alerta WebUI ${WEBUI_VERSION}
8990

9091
nginx -v
91-
echo uwsgi $(uwsgi --version)
92+
gunicorn --version
9293
mongo --version | grep MongoDB
9394
psql --version
9495
python3 --version

requirements-docker.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
lxml==4.9.2
22
pysaml2==7.2.1
33
python-ldap==3.4.3
4-
uWSGI==2.0.21
4+
gunicorn==21.2.0

0 commit comments

Comments
 (0)