Browse Source

dockerfile: split `pipenv install` into two stages to speed up image builds

https://github.com/fphammerle/wireless-sensor-mqtt/blob/3d9e2169b28b85d6d88ba1049fc1ca57c9464c83/Dockerfile
Fabian Peter Hammerle 3 years ago
parent
commit
3436c4744f
2 changed files with 11 additions and 1 deletions
  1. 2 0
      CHANGELOG.md
  2. 9 1
      Dockerfile

+ 2 - 0
CHANGELOG.md

@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
 ## [Unreleased]
+### Fixed
+- dockerfile: split `pipenv install` into two stages to speed up image builds
 
 ## [0.5.0] - 2020-11-06
 ### Added

+ 9 - 1
Dockerfile

@@ -1,3 +1,5 @@
+# sync with https://github.com/fphammerle/wireless-sensor-mqtt/blob/master/Dockerfile
+
 # not using python:3.*-alpine cause glib-dev package depends on python3
 # https://pkgs.alpinelinux.org/package/v3.11/main/aarch64/glib-dev
 ARG BASE_IMAGE=alpine:3.13.1
@@ -14,6 +16,7 @@ RUN apk add --no-cache \
         git `# setuptools_scm` \
         glib-dev `# dbus-python` \
         gobject-introspection-dev `# PyGObject` \
+        jq `# edit Pipfile.lock` \
         make `# dbus-python` \
         musl-dev `# dbus-python` \
         py3-certifi `# pipenv` \
@@ -26,11 +29,16 @@ USER build
 RUN pip3 install --user --no-cache-dir pipenv==2020.6.2
 
 ARG SOURCE_DIR_PATH
-COPY --chown=build:1234 . $SOURCE_DIR_PATH
+COPY --chown=build:nobody Pipfile Pipfile.lock $SOURCE_DIR_PATH/
 WORKDIR $SOURCE_DIR_PATH
 ENV PIPENV_CACHE_DIR=/tmp/pipenv-cache \
     PIPENV_VENV_IN_PROJECT=yes-please \
     PATH=/home/build/.local/bin:$PATH
+# `sponge` is not pre-installed
+RUN jq 'del(.default."systemctl-mqtt")' Pipfile.lock > Pipfile.lock~ \
+    && mv Pipfile.lock~ Pipfile.lock \
+    && pipenv install --deploy --verbose
+COPY --chown=build:nobody . $SOURCE_DIR_PATH
 RUN pipenv install --deploy --verbose \
     && pipenv graph \
     && pipenv run pip freeze \