bake-action icon indicating copy to clipboard operation
bake-action copied to clipboard

Cache not being hit when using TAG workflows

Open Nithos opened this issue 3 years ago • 0 comments

Behaviour

When using a workflow that triggers on a TAG it fails to hit the cache when triggering the workflow with a follow on version tag. Removing the tag and deploying again does hit the cache correctly however.

This is similar/same to the issue currently found in the build_pull_action here

Note this is a multi-platform build as well in case that adds extra complexity

Expected behaviour

Cache should be hit and used appropriately on all tags.

Actual behaviour

Cache is not hit on subsequent tags and invocation of the workflow.

Configuration

Sample Workflow


name: Docker CI Bake

on:
  push:
    tags:
      - 'v*.*.*'
      - 'v*.*.*-*'

env:
  REGISTRY: ghcr.io
  BAKE_FILE: docker-bake-gh.hcl

jobs:
  targets:
    runs-on: ubuntu-22.04
    outputs:
      matrix: ${{ steps.targets.outputs.matrix }}
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      # Generate a matrix output of all the default targets
      - name: Create matrix
        id: targets
        run: |
          echo ::set-output name=matrix::$(docker buildx bake -f ${{ env.BAKE_FILE }} --print | jq -cr '.group.default.targets')

      - name: Show matrix
        run: |
          echo ${{ steps.targets.outputs.matrix }}

  build-push:
    name: Buid and push Docker image to GitHub Container registry
    if: ${{ github.ref_type == 'tag' }}
    runs-on: ubuntu-22.04
    permissions:
      packages: write
      contents: read
    needs:
      - targets

    strategy:
      fail-fast: true
      matrix:
        target: ${{ fromJson(needs.targets.outputs.matrix) }}

    steps:
      # Checkout the repository
      - name: Checkout the repository
        uses: actions/checkout@v3

      # Login against the docker registry
      - name: Login to registry ${{ env.REGISTRY }}
        uses: docker/login-action@v2
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: set env variables for bakefile
        run: |
          echo "VERSION=$( echo ${{ github.ref_name }} | sed 's/^.//' )" >>${GITHUB_ENV}
          echo "DOCKER_ORG=${{ env.REGISTRY }}" >> ${GITHUB_ENV}
          echo "DOCKER_PREFIX=${{ github.repository_owner }}" >> ${GITHUB_ENV}

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v2

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2

      # Build and push Docker Images
      - name: Build Images using BuildX Bake
        uses: docker/bake-action@v2
        with:
          files: ./${{ env.BAKE_FILE }}
          targets: ${{ matrix.target }}
          push: true
          set: |
            *.cache-from=type=gha,scope=build-${{ matrix.target }}
            *.cache-to=type=gha,scope=build-${{ matrix.target }},mode=max

Nithos avatar Oct 18 '22 18:10 Nithos