From 6b84e35c51c64ec0b8993418b2e850231b0a2941 Mon Sep 17 00:00:00 2001 From: Andrea Falconi Date: Fri, 4 Sep 2020 17:07:55 +0200 Subject: [PATCH] port gunicorn setup from #354. --- Dockerfile | 13 +++++++------ conf/supervisord.conf | 10 ++++++++++ src/app.py | 2 ++ src/gunicorn.conf.py | 3 +++ src/uwsgi.py | 8 ++++++++ 5 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 conf/supervisord.conf create mode 100644 src/gunicorn.conf.py create mode 100644 src/uwsgi.py diff --git a/Dockerfile b/Dockerfile index 61bdb600..26eae99f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ FROM python:3.8.3-alpine3.12 as base FROM base as builder -RUN apk --no-cache --update-cache add gcc python3 python3-dev py-pip build-base wget +RUN apk --no-cache --update-cache add gcc python3 python3-dev py-pip build-base wget libffi-dev RUN ln -s /usr/include/locale.h /usr/include/xlocale.h -RUN pip install pipenv +RUN pip install pipenv gunicorn gevent RUN mkdir -p /src/ngsi-timeseries-api COPY Pipfile /src/ngsi-timeseries-api/Pipfile COPY Pipfile.lock /src/ngsi-timeseries-api/Pipfile.lock @@ -10,10 +10,11 @@ RUN cd /src/ngsi-timeseries-api && { pipenv lock -r > /requirements.txt; } RUN pip install -r /requirements.txt FROM base -RUN apk --no-cache add curl +RUN apk --no-cache add curl supervisor COPY --from=builder /usr/local /usr/local COPY . /src/ngsi-timeseries-api/ -WORKDIR /src/ngsi-timeseries-api/src -ENV PYTHONPATH=$PWD:$PYTHONPATH +COPY conf/supervisord.conf /etc/supervisord.conf -CMD python app.py +EXPOSE 8668 + +CMD ["supervisord", "-c", "/etc/supervisord.conf"] diff --git a/conf/supervisord.conf b/conf/supervisord.conf new file mode 100644 index 00000000..d456e71a --- /dev/null +++ b/conf/supervisord.conf @@ -0,0 +1,10 @@ +[supervisord] +nodaemon=true + +[program:quantumleap] +command=gunicorn -b 0.0.0.0:8668 uwsgi --log-level DEBUG --worker-class gevent --worker-connections 10000 --config gunicorn.conf.py +directory=/src/ngsi-timeseries-api/src +autostart=true +autorestart=true +startsecs=10 +startretries=3 diff --git a/src/app.py b/src/app.py index 7d88971f..c916f6f9 100644 --- a/src/app.py +++ b/src/app.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python from utils.hosts import LOCAL @@ -10,3 +11,4 @@ # validate_responses=True, strict_validation=True ) app.run(host=LOCAL, port=8668) + application = app.app diff --git a/src/gunicorn.conf.py b/src/gunicorn.conf.py new file mode 100644 index 00000000..984c16ef --- /dev/null +++ b/src/gunicorn.conf.py @@ -0,0 +1,3 @@ +import multiprocessing + +workers = multiprocessing.cpu_count() * 4 + 1 diff --git a/src/uwsgi.py b/src/uwsgi.py new file mode 100644 index 00000000..766494c7 --- /dev/null +++ b/src/uwsgi.py @@ -0,0 +1,8 @@ +import connexion +app = connexion.FlaskApp(__name__, port=8668, specification_dir='../specification/') +app.add_api('quantumleap.yml', + arguments={'title': 'QuantumLeap V2 API'}, + pythonic_params=True, + # validate_responses=True, strict_validation=True + ) +application = app.app