From 725dffc458eb073a5486a78af1d4cbaf907e9ecc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Sch=C3=A4fer?= Date: Sun, 31 Jan 2021 15:30:04 +0100 Subject: [PATCH] Reduce image size by approximately 65% --- Dockerfile | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/Dockerfile b/Dockerfile index bf37cdc..6d7a162 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,44 +3,28 @@ FROM debian:buster ARG BUILD_SERIES=dev ARG BUILD_ID=0 -ENV DEBIAN_FRONTEND noninteractive +COPY requirements.txt /opt/snikket-web-portal/requirements.txt +COPY build-requirements.txt /opt/snikket-web-portal/build-requirements.txt +COPY Makefile /opt/snikket-web-portal/Makefile +COPY snikket_web/ /opt/snikket-web-portal/snikket_web +COPY babel.cfg /opt/snikket-web-portal/babel.cfg -# This Dockerfile attempts to strike a balance between image size and time it -# takes to do an incremental build on changes. -# Improvements welcome. +WORKDIR /opt/snikket-web-portal RUN set -eu; \ + export DEBIAN_FRONTEND=noninteractive ; \ apt-get update ; \ apt-get install -y --no-install-recommends \ python3 python3-pip python3-setuptools python3-wheel \ libpython3-dev \ make build-essential \ ; \ - apt-get clean ; rm -rf /var/lib/apt/lists - -COPY requirements.txt /opt/snikket-web-portal/requirements.txt -COPY build-requirements.txt /opt/snikket-web-portal/build-requirements.txt - -WORKDIR /opt/snikket-web-portal - -RUN set -eu; \ pip3 install -r requirements.txt; \ pip3 install -r build-requirements.txt; \ - rm -rf /root/.cache; - -COPY Makefile /opt/snikket-web-portal/Makefile -COPY snikket_web/ /opt/snikket-web-portal/snikket_web -COPY babel.cfg /opt/snikket-web-portal/babel.cfg - -# NOTE: abusing true(1) as a terrible way to disable a specific command. If -# one merged all the RUN commands into one, one would want to run the -# uninstall/remove commands there, but with the split up RUN commands it is -# rather pointless. -RUN set -eu; \ make; \ - true pip3 uninstall -yr build-requirements.txt; \ - true apt-get remove -y build-essential make libpython3-dev; \ - true apt-get autoremove -y; \ + pip3 uninstall -yr build-requirements.txt; \ + apt-get remove -y build-essential make libpython3-dev; \ + apt-get autoremove -y; \ pip3 install hypercorn; \ rm -rf /root/.cache; \ apt-get clean ; rm -rf /var/lib/apt/lists