tests: Cache the docker image on GitHub Packages

This speeds up the workflow from cca 9 minutes to less than 4 minutes,
as the 5 minute docker build is replaced with a 10 second docker pull.
This commit is contained in:
Tomas Janousek 2020-07-06 17:14:26 +02:00 committed by Tomas Babej
parent 8e69ea52fb
commit ae588783c1

View file

@ -24,19 +24,39 @@ jobs:
- uses: actions/checkout@v2
- name: Prepare docker image
run: |
docker-compose build \
set -ex -o pipefail
shopt -s lastpipe
(
echo ALPINE_VERSION="$ALPINE_VERSION"
echo PYTHON_VERSION="$PYTHON_VERSION"
echo TASK_VERSION="$TASK_VERSION"
echo VIM_VERSION="$VIM_VERSION"
echo VIMWIKI_VERSION="$VIMWIKI_VERSION"
cat Dockerfile
) | sha256sum | read -r tag _
docker login "$DOCKER_REGISTRY" -u "$GITHUB_USER" -p "$GITHUB_TOKEN" || :
docker pull "$DOCKER_CACHE_IMAGE":"$tag" || :
docker build \
--cache-from "$DOCKER_CACHE_IMAGE":"$tag" \
${ALPINE_VERSION:+--build-arg ALPINE_VERSION="$ALPINE_VERSION"} \
${PYTHON_VERSION:+--build-arg PYTHON_VERSION="$PYTHON_VERSION"} \
${TASK_VERSION:+--build-arg TASK_VERSION="$TASK_VERSION"} \
${VIM_VERSION:+--build-arg VIM_VERSION="$VIM_VERSION"} \
${VIMWIKI_VERSION:+--build-arg VIMWIKI_VERSION="$VIMWIKI_VERSION"} \
tests
-t taskwiki_tests \
.
docker tag taskwiki_tests "$DOCKER_CACHE_IMAGE":"$tag"
docker push "$DOCKER_CACHE_IMAGE":"$tag" || :
env:
ALPINE_VERSION: ${{ matrix.ALPINE_VERSION }}
PYTHON_VERSION: ${{ matrix.PYTHON_VERSION }}
TASK_VERSION: ${{ matrix.TASK_VERSION }}
VIM_VERSION: ${{ matrix.VIM_VERSION }}
VIMWIKI_VERSION: ${{ matrix.VIMWIKI_VERSION }}
DOCKER_REGISTRY: docker.pkg.github.com
DOCKER_CACHE_IMAGE: docker.pkg.github.com/${{ github.repository }}/taskwiki_tests
GITHUB_USER: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Test
run: make test PYTEST_FLAGS="-n8"
env: