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/*
diff --git a/testrail_bot/control/celery_tasks/tasks.py b/testrail_bot/control/celery_tasks/tasks.py
index 8566653..4b3d5e9 100644
--- a/testrail_bot/control/celery_tasks/tasks.py
+++ b/testrail_bot/control/celery_tasks/tasks.py
@@ -27,7 +27,6 @@
data = filters.filter_uuid(data)
if test_run.filter_func:
- import rpdb;rpdb.set_trace()
exec(test_run.filter_func)
data = locals()["custom_filter"](data)
return data
diff --git a/testrail_bot/control/forms.py b/testrail_bot/control/forms.py
index 9375f42..1236d6d 100644
--- a/testrail_bot/control/forms.py
+++ b/testrail_bot/control/forms.py
@@ -7,7 +7,7 @@
model = TestRun
fields = "__all__"
labels = {
- "project_name": "Name of the project",
+ "project_name": "Name of the project",
"plan_name": "Name of the Test Plan without date",
"run_name": "Name of the run",
"created_by": "Test Run created by",
diff --git a/testrail_bot/control/views.py b/testrail_bot/control/views.py
index ee582eb..68738c5 100644
--- a/testrail_bot/control/views.py
+++ b/testrail_bot/control/views.py
@@ -74,9 +74,7 @@
report.save()
process_run.delay(run_id, report.id, path)
- return render(
- request, "control/report.html",
- {"report": report.path.read().decode("utf-8"), "report_id": report.id})
+ return redirect("single_report", report.id)
def show_help(request):