Skip to content

Instantly share code, notes, and snippets.

@adrienjoly
Last active October 14, 2021 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adrienjoly/5914607598f2a78770cf6d3ac54b260f to your computer and use it in GitHub Desktop.
Save adrienjoly/5914607598f2a78770cf6d3ac54b260f to your computer and use it in GitHub Desktop.
Cache Docker layers when (re)building a Docker image on GitHub Actions.
# source: https://github.com/docker/buildx/pull/535#issuecomment-869022231
e2e:
name: End-to-end tests against Docker containers
runs-on: ubuntu-latest
env:
DOCKER_BUILDKIT: '1' # to enable persistent docker cache
COMPOSE_DOCKER_CLI_BUILD: '1' # so docker-compose commands benefits from buildkit/buildx's docker cache
steps:
- uses: actions/checkout@v2
# Use GitHub's Docker registry to cache layers and reduce image build time from a run to the other
- run: echo ${{ secrets.GITHUB_TOKEN }} | docker login docker.pkg.github.com -u $GITHUB_ACTOR --password-stdin
- run: docker pull docker.pkg.github.com/$GITHUB_REPOSITORY/admin-api-cached-build || true
- run: docker build . --file Dockerfile-local --tag admin-api --cache-from=docker.pkg.github.com/$GITHUB_REPOSITORY/admin-api-cached-build --build-arg BUILDKIT_INLINE_CACHE=1
- run: docker tag admin-api docker.pkg.github.com/$GITHUB_REPOSITORY/admin-api-cached-build && docker push docker.pkg.github.com/$GITHUB_REPOSITORY/admin-api-cached-build || true
# source: https://dev.to/dtinth/caching-docker-builds-in-github-actions-which-approach-is-the-fastest-a-research-18ei
- name: 'Build admin-api with docker-compose' # so the test suite does not have to
run: docker-compose -f docker-compose-local.yml build admin-api
- name: Run end-to-end tests
run: yarn test:e2e:docker # starts the APIs and services with docker-compose before running tests
- name: "Push Docker images to cache"
run: docker push --all-tags ghcr.io/$GITHUB_REPOSITORY/admin-api-cached-build || true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment