From 28ba7b6ad0f19ce7ae2a528e3c9e8abd6b15b598 Mon Sep 17 00:00:00 2001
From: krateng <git.noreply@krateng.ch>
Date: Fri, 8 Apr 2022 17:23:56 +0200
Subject: [PATCH] Improved Containerfile

---
 .dockerignore                     |  3 ++-
 Containerfile                     | 10 ++++++++++
 dev/templates/Containerfile.jinja | 10 ++++++++++
 requirements_pre.txt              |  3 +++
 4 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 requirements_pre.txt

diff --git a/.dockerignore b/.dockerignore
index 04925ce..2af1e3c 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -1,6 +1,7 @@
 *
 !/maloja
-!Dockerfile
+!Containerfile
+!/requirements_pre.txt
 !/requirements.txt
 !/pyproject.toml
 !/README.md
diff --git a/Containerfile b/Containerfile
index e30dfa4..22b0b72 100644
--- a/Containerfile
+++ b/Containerfile
@@ -15,6 +15,16 @@ RUN \
 	apk add py3-pip && \
 	pip install wheel
 
+# these are more static than the real requirements, which means caching
+COPY ./requirements_pre.txt ./requirements_pre.txt
+
+RUN \
+	apk add --no-cache --virtual .build-deps gcc g++ python3-dev libxml2-dev libxslt-dev libffi-dev libc-dev py3-pip linux-headers && \
+	pip install --no-cache-dir -r requirements_pre.txt && \
+	apk del .build-deps
+
+
+# less likely to be cached
 COPY ./requirements.txt ./requirements.txt
 
 RUN \
diff --git a/dev/templates/Containerfile.jinja b/dev/templates/Containerfile.jinja
index 155c6a8..e180abd 100644
--- a/dev/templates/Containerfile.jinja
+++ b/dev/templates/Containerfile.jinja
@@ -15,6 +15,16 @@ RUN \
 	apk add py3-pip && \
 	pip install wheel
 
+# these are more static than the real requirements, which means caching
+COPY ./requirements_pre.txt ./requirements_pre.txt
+
+RUN \
+	apk add --no-cache --virtual .build-deps {{ tool.osreqs.alpine.build | join(' ') }} && \
+	pip install --no-cache-dir -r requirements_pre.txt && \
+	apk del .build-deps
+
+
+# less likely to be cached
 COPY ./requirements.txt ./requirements.txt
 
 RUN \
diff --git a/requirements_pre.txt b/requirements_pre.txt
new file mode 100644
index 0000000..c4c0dbe
--- /dev/null
+++ b/requirements_pre.txt
@@ -0,0 +1,3 @@
+# this is a more static file that enables container images to be cached
+# it should contain packages that take long to build and don't change frequently
+lxml