From 50a46b5cf11317d12d872b54ecd276ede52d5d0c Mon Sep 17 00:00:00 2001
From: Jacek Kowalski <Jacek@jacekk.info>
Date: Fri, 22 May 2020 16:00:34 +0000
Subject: [PATCH] Replace uwsgi with waitress due to 400 Bad Request issues

---
 config.json      |    6 +++++-
 Dockerfile       |    4 ++--
 /dev/null        |   16 ----------------
 requirements.txt |    1 +
 run.py           |    7 ++++++-
 5 files changed, 14 insertions(+), 20 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index d31ab7a..98b66ff 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,6 +1,6 @@
 FROM alpine
 
-RUN apk add uwsgi-python3 python3 py3-pip
+RUN apk add python3 py3-pip
 RUN mkdir -p /run/docker/plugins /usr/src/app \
 	&& chown -R nobody:nobody /run/docker/plugins /usr/src/app
 USER nobody
@@ -12,4 +12,4 @@
 
 COPY --chown=nobody:nobody . .
 
-CMD [ "uwsgi", "--ini", "uwsgi.ini" ]
+CMD [ "./run.py" ]
diff --git a/config.json b/config.json
index 353cd2c..0de7978 100644
--- a/config.json
+++ b/config.json
@@ -2,9 +2,13 @@
 	"description": "pyveth - veth network driver in Python",
 	"documentation": "https://github.com/jacekkow/docker-plugin-pyveth",
 	"workdir": "/usr/src/app",
-	"entrypoint": ["uwsgi", "--ini", "uwsgi.ini"],
+	"entrypoint": ["./run.py"],
 	"env": [
 		{
+			"name": "ENVIRONMENT",
+			"value": "production"
+		},
+		{
 			"name": "HOME",
 			"value": "/usr/src/app"
 		}
diff --git a/requirements.txt b/requirements.txt
index 7e33f4e..f2bb7be 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,3 +1,4 @@
 docker-plugin-api>=0.3
 Flask
 pyroute2
+waitress
diff --git a/run.py b/run.py
index c8692a8..40bb62c 100755
--- a/run.py
+++ b/run.py
@@ -1,9 +1,11 @@
 #!/usr/bin/env python3
 
 import logging
+import os
 
 import docker_plugin_api.Plugin
 import flask
+import waitress
 
 app = flask.Flask('pyveth')
 app.logger.setLevel(logging.DEBUG)
@@ -15,4 +17,7 @@
 app.register_blueprint(lib.NetworkDriver.app)
 
 if __name__ == '__main__':
-    app.run(debug=True)
+	if os.environ.get('ENVIRONMENT', 'dev') == 'dev':
+		app.run(debug=True)
+	else:
+		waitress.serve(app, unix_socket='/run/docker/plugins/pyveth.sock', threads=1)
diff --git a/uwsgi.ini b/uwsgi.ini
deleted file mode 100644
index a389a2d..0000000
--- a/uwsgi.ini
+++ /dev/null
@@ -1,16 +0,0 @@
-[uwsgi]
-shared-socket = /run/docker/plugins/pyveth.sock
-http-socket = =0
-;uid = 65534
-;gid = 65534
-
-die-on-term = true
-honour-stdin = true
-
-master = true
-processes = 1
-single-interpreter = true
-
-plugins = python3
-module = run
-callable = app

--
Gitblit v1.9.1