aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPjotr Prins2021-08-07 12:06:49 +0200
committerPjotr Prins2021-08-07 12:06:49 +0200
commite0476d51603432f60b6412b65486166deabe9e08 (patch)
treed201eb44bb0490dfeb3e9d87386adc866591db54
parent33700066452e3c5f341b790f015f85fb976d06be (diff)
downloadgenenetwork3-e0476d51603432f60b6412b65486166deabe9e08.tar.gz
Add gunicorn support for production
-rw-r--r--README.md23
-rw-r--r--gn3/api/general.py3
-rw-r--r--guix.scm3
-rw-r--r--main.py6
-rw-r--r--wsgi.py11
5 files changed, 42 insertions, 4 deletions
diff --git a/README.md b/README.md
index 108dcdb..c3a9848 100644
--- a/README.md
+++ b/README.md
@@ -61,12 +61,33 @@ mypy .
#### Running the flask app
-To spin up the server:
+To spin up the server on its own (for development):
```bash
env FLASK_DEBUG=1 FLASK_APP="main.py" flask run --port=8080
```
+And test with
+
+```
+curl localhost:8080/api/version
+"1.0"
+```
+
+To run with gunicorn
+
+```
+gunicorn --bind 0.0.0.0:8080 wsgi:app
+```
+
+consider the following options for development `--bind 0.0.0.0:$SERVER_PORT --workers=1 --timeout 180 --reload wsgi`.
+
+And for the scalable production version run
+
+```
+gunicorn --bind 0.0.0.0:8080 --workers 8 --keep-alive 6000 --max-requests 10 --max-requests-jitter 5 --timeout 1200 wsgi:app
+```
+
##### Using python-pip
IMPORTANT NOTE: we do not recommend using pip tools, use Guix instead
diff --git a/gn3/api/general.py b/gn3/api/general.py
index cebb2e3..86fb7b7 100644
--- a/gn3/api/general.py
+++ b/gn3/api/general.py
@@ -11,6 +11,9 @@ from gn3.commands import run_cmd
general = Blueprint("general", __name__)
+@general.route("/version")
+def version():
+ return jsonify("1.0")
@general.route("/metadata/upload/", methods=["POST"],
strict_slashes=False)
diff --git a/guix.scm b/guix.scm
index c18f329..f94fe1a 100644
--- a/guix.scm
+++ b/guix.scm
@@ -82,8 +82,9 @@
#:recursive? #t
#:select? git-file?))
(propagated-inputs `(("coreutils" ,coreutils)
- ("gemma-wrapper" ,gemma-wrapper)
("csvdiff" ,go-github-com-aswinkarthik-csvdiff)
+ ("gemma-wrapper" ,gemma-wrapper)
+ ("gunicorn" ,gunicorn)
("python" ,python-wrapper)
("python-bcrypt" ,python-bcrypt)
("python-flask" ,python-flask)
diff --git a/main.py b/main.py
index e3ca41a..a587697 100644
--- a/main.py
+++ b/main.py
@@ -2,6 +2,8 @@
from gn3.app import create_app
-
app = create_app()
-app.run(host="0.0.0.0")
+
+if __name__ == '__main__':
+ print("Starting app...")
+ app.run()
diff --git a/wsgi.py b/wsgi.py
new file mode 100644
index 0000000..d30bc49
--- /dev/null
+++ b/wsgi.py
@@ -0,0 +1,11 @@
+# import main
+
+print("STARTING WSGI APP")
+
+from gn3.app import create_app
+
+app = create_app()
+
+if __name__ == "__main__":
+ print("Starting wsgi app...")
+ app.run()