Skip to content

Commit 6971dd8

Browse files
committedJun 22, 2017
Use uWSGI to serve the app in production
1 parent 224def3 commit 6971dd8

File tree

3 files changed

+57
-7
lines changed

3 files changed

+57
-7
lines changed
 

‎docker/Dockerfile-prod

+43-7
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,53 @@
44

55
FROM python:3.5-alpine
66

7-
RUN addgroup -g 1001 app && \
8-
adduser -D -u 1001 -G app -s /usr/sbin/nologin app
7+
MAINTAINER mars@mozilla.com
8+
# These are unlikely to change from version to version of the container
9+
EXPOSE 8000
10+
CMD ["/usr/local/bin/uwsgi", "--http-auto-chunked", "--http-keepalive"]
11+
12+
RUN addgroup -g 10001 app && adduser -D -u 10001 -G app -h /app app
13+
14+
# uWSGI configuration
15+
ENV UWSGI_MODULE=landoapi.wsgi:app \
16+
UWSGI_HTTP=:8000 \
17+
UWSGI_MASTER=1 \
18+
UWSGI_WORKERS=2 \
19+
UWSGI_THREADS=8 \
20+
# Disable worker memory sharing optimizations. They can cause memory leaks
21+
# and issues with packages like Sentry.
22+
# See https://discuss.newrelic.com/t/newrelic-agent-produces-system-error/43446
23+
UWSGI_LAZY_APPS=1 \
24+
UWSGI_WSGI_ENV_BEHAVIOR=holy \
25+
# Make uWSGI die instead of reload when it gets SIGTERM (fixed in uWSGI 2.1)
26+
UWSGI_DIE_ON_TERM=1 \
27+
# Check that the options we gave uWSGI are sane
28+
UWSGI_STRICT=1 \
29+
# Die if the application threw an exception on startup
30+
UWSGI_NEED_APP=1
931

1032
COPY requirements.txt /requirements.txt
11-
RUN pip install --no-cache -r /requirements.txt
33+
34+
35+
RUN set -ex \
36+
&& apk add --no-cache --virtual .build-deps \
37+
gcc \
38+
libc-dev \
39+
musl-dev \
40+
linux-headers \
41+
pcre-dev \
42+
&& pip install --no-cache -r /requirements.txt \
43+
&& runDeps="$( \
44+
scanelf --needed --nobanner --recursive /usr/local \
45+
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
46+
| sort -u \
47+
| xargs -r apk info --installed \
48+
| sort -u \
49+
)" \
50+
&& apk add --virtual .python-rundeps $runDeps \
51+
&& apk del .build-deps
1252

1353
COPY . /app
1454
RUN pip install --no-cache /app
1555

16-
# run as non priviledged user
1756
USER app
18-
19-
# TODO allow ops to use this as a wsgi app
20-
WORKDIR /app

‎landoapi/wsgi.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
"""
6+
Construct an application instance that can be referenced by a WSGI server.
7+
"""
8+
import os
9+
10+
from .app import create_app
11+
12+
app = create_app(os.environ.get('VERSION_PATH', '/app/version.json'))

‎requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,5 @@ connexion==1.1.9 \
5050
requests-mock==1.3.0 \
5151
--hash=sha256:bd86970d6c52cc97071f5185aa594de6a997a5ca63b3bb36aceb9bb9db49294b \
5252
--hash=sha256:23edd6f7926aa13b88bf79cb467632ba2dd5a253034e9f41563f60ed305620c7
53+
uWSGI==2.0.15 \
54+
--hash=sha256:572ef9696b97595b4f44f6198fe8c06e6f4e6351d930d22e5330b071391272ff

0 commit comments

Comments
 (0)
Failed to load comments.