Skip to content

Commit

Permalink
port gunicorn setup from #354.
Browse files Browse the repository at this point in the history
  • Loading branch information
c0c0n3 committed Sep 4, 2020
1 parent 960a148 commit 6b84e35
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
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
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"]
10 changes: 10 additions & 0 deletions conf/supervisord.conf
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions src/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python
from utils.hosts import LOCAL


Expand All @@ -10,3 +11,4 @@
# validate_responses=True, strict_validation=True
)
app.run(host=LOCAL, port=8668)
application = app.app
3 changes: 3 additions & 0 deletions src/gunicorn.conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import multiprocessing

workers = multiprocessing.cpu_count() * 4 + 1
8 changes: 8 additions & 0 deletions src/uwsgi.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6b84e35

Please sign in to comment.