From 15373ed00fdd59b00456548f0e3d1494b4032fe4 Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Mon, 20 Apr 2020 10:11:45 +0200 Subject: [PATCH] - Use gunicorn - Add env variable GUNICORN_WORKERS (default: 1) - new Port (8000) - You don't need to run "flask deploy" by hand anymore --- Dockerfile | 2 +- docker-entrypoint.sh | 12 +++++------- nopaque.env.tpl | 5 ++++- nopaque.py | 6 +----- requirements.txt | 1 + 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index d7c914ee..4ec86ea6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ ENV FLASK_APP=nopaque.py ENV LANG=C.UTF-8 -EXPOSE 5000 +EXPOSE 8000 RUN apt-get update \ diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index ebcfeb7e..90467b92 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -5,10 +5,8 @@ wait-for-it db:5432 --strict --timeout=0 echo "Waiting for redis..." wait-for-it redis:6379 --strict --timeout=0 -if [ $# -eq 0 ]; then - venv/bin/python nopaque.py -elif [ $1 == "flask" ]; then - venv/bin/python -m $@ -else - echo "Unknown command" -fi +GUNICORN_WORKERS="${GUNICORN_WORKERS:-1}" + +source venv/bin/activate +flask deploy +gunicorn --bind :5000 --workers "${GUNICORN_WORKERS}" --worker-class eventlet nopaque:app diff --git a/nopaque.env.tpl b/nopaque.env.tpl index 5197f158..4b10df20 100644 --- a/nopaque.env.tpl +++ b/nopaque.env.tpl @@ -14,7 +14,7 @@ GITLAB_PASSWORD= ### Flask ### FLASK_CONFIG= -# SECRET_KEY= +SECRET_KEY= ### Flask-Mail ### MAIL_SERVER= @@ -24,6 +24,9 @@ MAIL_USERNAME= MAIL_PASSWORD= MAIL_DEFAULT_SENDER= +### Gunicorn ### +GUNICORN_WORKERS= + ### nopaque ### NOPAQUE_ADMIN= NOPAQUE_STORAGE= diff --git a/nopaque.py b/nopaque.py index b1e5a2ec..57d41eef 100644 --- a/nopaque.py +++ b/nopaque.py @@ -1,6 +1,6 @@ import eventlet eventlet.monkey_patch() # noqa -from app import create_app, db, socketio +from app import create_app, db from app.models import Corpus, Job, Role, User from flask_migrate import Migrate, upgrade import os @@ -34,7 +34,3 @@ def test(): import unittest tests = unittest.TestLoader().discover('tests') unittest.TextTestRunner(verbosity=2).run(tests) - - -if __name__ == '__main__': - socketio.run(app, host='0.0.0.0') diff --git a/requirements.txt b/requirements.txt index f68e78f9..b0483a78 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,6 +7,7 @@ Flask-SocketIO Flask-SQLAlchemy Flask-Table Flask-WTF +gunicorn jsonpatch psycopg2 redis