Install dependencies in separate layer in Dockerfile #142
+16
−9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This resolves the conversation at #117 (comment)
Currently we install the build dependencies like g++ (
RUN apk add...) in a separate layer. We try and purge them in a later step but this doesn't achieve anything because docker caches everything on a layer by layer basis, i.e. the previous layer will still contain them and hang around.This fixes it by making sure they are installed and purged in the same layer, which reduces the image size by ~500MB:
This patch also only copies over the minimal source files required so as to make sure the dependencies layer is invalidated as infrequently as possible. E.g. here is an example of building the image after touching a regular python source file. We no longer need to rebuild or redownload the dependencies, that layer is cached:
We need to copy the cperf ext-module sources over and build that up front while we still have g++, and we need to copy over pyproject.toml to satisfy setuptools_scm. We also need to use a mock version for setuptools_scm, since it looks for a .git folder and we want to avoid copying that. That would cause the layer to be invalidated on every commit.