From 1fa0971b757c6daffc4a8fb42b9807a0af20cf2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20=C3=81lvaro?= Date: Thu, 10 Nov 2022 15:54:19 +0100 Subject: [PATCH] feat: Improve cache hit on build --- .github/workflows/publish.yml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 6718146..09c6331 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -18,7 +18,7 @@ on: env: IMAGE_NAME: cdalvaro/docker-salt-master PLATFORMS: linux/amd64,linux/arm64,linux/arm/v7 - CACHE_PATH: /tmp/.buildx-docker-salt-master-cache + CACHE_PATH: ${{ github.workspace }}/.buildx-cache EXTRA_REGISTRIES: ghcr.io quay.io jobs: @@ -46,6 +46,7 @@ jobs: echo "Docker image: '${DOCKER_IMAGE}'" echo "Tags: ${TAGS}" + # FIXME: set-output is deprecated echo ::set-output name=tags::${TAGS} - name: VCS ref @@ -53,6 +54,7 @@ jobs: run: | VCS_REF="${GITHUB_SHA::8}" echo "VCS ref: ${VCS_REF}" + # FIXME: set-output is deprecated echo ::set-output name=vcs_ref::${VCS_REF} - name: Created On @@ -60,6 +62,7 @@ jobs: run: | CREATED_ON="$(date -u +"%Y-%m-%dT%H:%M:%SZ")" echo "Created on: ${CREATED_ON}" + # FIXME: set-output is deprecated echo ::set-output name=created_on::${CREATED_ON} - name: Dump environment @@ -87,6 +90,7 @@ jobs: uses: docker/setup-buildx-action@v2.2.1 - name: Cache Docker layers + id: cache-docker-layers uses: actions/cache@v3 with: path: ${{ env.CACHE_PATH }} @@ -94,6 +98,17 @@ jobs: restore-keys: | ${{ runner.os }}-buildx- + - name: Cache hit + continue-on-error: true + env: + CACHE_HIT: ${{ steps.cache-docker-layers.outputs.cache-hit }} + run: | + if [[ "${CACHE_HIT}" != 'true' ]]; then + echo "No cache hit" >&2 + exit 1 + fi + echo "Cache contents available at: ${CACHE_PATH}" + - name: Login to Docker Container Registry uses: docker/login-action@v2.1.0 with: @@ -127,5 +142,6 @@ jobs: type=local,src=${{ env.CACHE_PATH }} ghcr.io/cdalvaro/docker-salt-master:latest cache-to: type=local,dest=${{ env.CACHE_PATH }} + pull: true push: true tags: ${{ needs.metadata.outputs.tags }}