tests: Refactor Dockerfile to multi-stage (more caching during development)

The previous refactor traded build step caching for smaller image size,
which in turn made fast caching of built images possible, and allowed us
to speed up CI builds. But almost any change in Dockerfile required full
rebuild of everything (vim & taskwarrior), so changes to the Dockerfile
became more painful.

This commit refactors the Dockerfile to use multi-stage builds, which
brings build caching back: vim & taskwarrior are built in separate
stages, which are cached step by step, and then the build artifacts are
copied into the main tests image and runtime dependencies are installed.

There's a catch, of course: --cache-from doesn't work with multi-stage
images unless the experimental BuildKit backend and its inline cache
export are enabled. This requires docker 19.03, which shouldn't be hard
to obtain but isn't installed by default on Travis CI.
This commit is contained in:
Tomas Janousek 2020-07-07 19:33:57 +02:00 committed by Tomas Babej
parent ae588783c1
commit 13ee57540e
2 changed files with 65 additions and 78 deletions

View file

@ -36,7 +36,8 @@ jobs:
) | sha256sum | read -r tag _
docker login "$DOCKER_REGISTRY" -u "$GITHUB_USER" -p "$GITHUB_TOKEN" || :
docker pull "$DOCKER_CACHE_IMAGE":"$tag" || :
docker build \
DOCKER_BUILDKIT=1 docker build \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--cache-from "$DOCKER_CACHE_IMAGE":"$tag" \
${ALPINE_VERSION:+--build-arg ALPINE_VERSION="$ALPINE_VERSION"} \
${PYTHON_VERSION:+--build-arg PYTHON_VERSION="$PYTHON_VERSION"} \