Add multi-staged docker build and flake8
Adds multi-staged docker build that reduces final image size 5x. Adds
flake8 checks during docker image build. Changes submit run response
from render to redirect.
Change-Id: Iadd278b4922ee223517b0ea1ffdf75c4a7dac719
diff --git a/testrail_bot/Dockerfile b/testrail_bot/Dockerfile
index 508de46..dac7066 100644
--- a/testrail_bot/Dockerfile
+++ b/testrail_bot/Dockerfile
@@ -1,9 +1,41 @@
+###########
+# BUILDER #
+###########
+
+# pull official base image
+FROM python:3.8.3-alpine as builder
+
+# set work directory
+WORKDIR /tmp
+
+
+# set environment variables
+ENV PYTHONDONTWRITEBYTECODE 1
+ENV PYTHONUNBUFFERED 1
+
+# install psycopg2 and uWSGI dependencies
+RUN apk update \
+ && apk add postgresql-dev gcc python3-dev musl-dev linux-headers
+
+# lint
+RUN pip install --upgrade pip
+RUN pip install flake8
+COPY . .
+RUN flake8 --ignore=E501,F401 .
+
+# install dependencies
+RUN pip wheel --no-cache-dir --no-deps --wheel-dir /tmp/wheels -r requirements.txt
+
+#########
+# FINAL #
+#########
+
FROM python:3.8.3-alpine
ENV PYTHONUNBUFFERED 1
COPY . /testrail_bot/
WORKDIR /testrail_bot
-RUN apk update
-RUN apk add postgresql-dev gcc python3-dev musl-dev linux-headers
-
-RUN pip install -r requirements.txt
+RUN apk update && apk add libpq
+COPY --from=builder /tmp/wheels /wheels
+COPY --from=builder /tmp/requirements.txt .
+RUN pip install --no-cache /wheels/*