Skip to content

Build should not fail on corrupted cache #577

@Meemaw

Description

@Meemaw

Expected behaviour

Building with build-push-action and buildx works as expected.

Actual behaviour

Yesterday we started seeing our docker build push action fail on every commit. This is not correlated to any specific code change that we did.

We temporary fixed this by removing the buildx from our workflow.

Configuration

  • Repository URL (if public): N/A
  • Build URL (if public): N/A
name: Build & Push Docker Next Image

on: push

jobs:
  docker:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3

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

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

      - name: Cache Docker layers
        uses: actions/cache@v3
        with:
          path: /tmp/.buildx-cache
          key: ${{ runner.os }}-buildx-next-prod-${{ github.sha }}
          restore-keys: |
            ${{ runner.os }}-buildx-next-prod
      - name: Login to GitHub Container Registry
        uses: docker/login-action@v1
        with:
          registry: ghcr.io
          username: ${{ secrets.GH_BOT_USER }}
          password: ${{ secrets.GH_PAT_TOKEN }}

      - name: Inject slug/short variables
        uses: rlespinasse/github-slug-action@v4

      - name: Build and push
        id: docker_build
        uses: docker/build-push-action@v2
        with:
          context: .
          push: true
          tags: |
            ghcr.io/companyx/next:${{ env.GITHUB_REF_SLUG }}
            ghcr.io/companyx/next:${{ github.sha }}
          cache-from: type=local,src=/tmp/.buildx-cache
          cache-to: type=local,dest=/tmp/.buildx-cache-new

      - name: Image digest
        run: echo ${{ steps.docker_build.outputs.digest }}

        # Temporary fix
        # https://github.com/docker/build-push-action/issues/252
        # https://github.com/moby/buildkit/issues/1896
      - name: Move cache
        run: |
          rm -rf /tmp/.buildx-cache
          mv /tmp/.buildx-cache-new /tmp/.buildx-cache
      - name: Trigger release workflow
        if: github.ref == 'refs/heads/master'
        uses: benc-uk/workflow-dispatch@v1
        with:
          workflow: release
          inputs: '{ "commit_sha": "${{ github.sha }}" }'
          token: ${{ secrets.GH_PAT_TOKEN }}

Logs

#9 [builder 1/9] COPY package.json yarn.lock ./
#9 ERROR: failed commit on ref "layer-sha256:0b0af05a4d868593f859eaa5815fc1c3596d77318a4ed756f3865a5fa3f290c6": unexpected commit digest sha256:7097d9f739d4ed17f8875508553264eb5e496d5e07edd35330157cae6d219a2c, expected sha256:0b0af05a4d868593f859eaa5815fc1c3596d77318a4ed756f3865a5fa3f290c6: failed precondition
------
 > [builder 1/9] COPY package.json yarn.lock ./:
------
Dockerfile:9
--------------------
   7 |     FROM base AS builder
   8 |     
   9 | >>> COPY package.json yarn.lock ./
  10 |     
  11 |     # Install production dependencies
--------------------
error: failed to solve: failed to compute cache key: failed commit on ref "layer-sha256:0b0af05a4d868593f859eaa5815fc1c3596d77318a4ed756f3865a5fa3f290c6": unexpected commit digest sha256:7097d9f739d4ed17f8875508553264eb5e496d5e07edd35330157cae6d219a2c, expected sha256:0b0af05a4d868593f859eaa5815fc1c3596d77318a4ed756f3865a5fa3f290c6: failed precondition
Error: buildx failed with: error: failed to solve: failed to compute cache key: failed commit on ref "layer-sha256:0b0af05a4d868593f859eaa5815fc1c3596d77318a4ed756f3865a5fa3f290c6": unexpected commit digest sha256:7097d9f739d4ed17f8875508553264eb5e496d5e07edd35330157cae6d219a2c, expected sha256:0b0af05a4d868593f859eaa5815fc1c3596d77318a4ed756f3865a5fa3f290c6: failed precondition

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions