docker / build-push-action

GitHub Action to build and push Docker images with Buildx
https://github.com/marketplace/actions/build-and-push-docker-images
Apache License 2.0
4.1k stars 525 forks source link

Error: buildx failed with: ERROR: failed to solve: failed to push can't push tagged ref by digest #1117

Closed cesarcoatl closed 1 month ago

cesarcoatl commented 1 month ago

Contributing guidelines

I've found a bug, and:

Description

After I manually pushed amd64 and arm64 images I followed the Distribute build across multiple runners example to automate that process for me.

Expected behaviour

I was expecting this to work.

Actual behaviour

I got the following error:

ERROR: failed to solve: failed to push coatldev/six:3.8.19: can't push tagged ref docker.io/coatldev/six:3.8.19 by digest
Error: buildx failed with: ERROR: failed to solve: failed to push coatldev/six:3.8.19: can't push tagged ref docker.io/coatldev/six:3.8.19 by digest

Repository URL

https://github.com/coatl-dev/docker-six/tree/83c7e09d18407f9f67cdb75a17cf41a9287b119a

Workflow run URL

https://github.com/coatl-dev/docker-six/actions/runs/9036104550

YAML workflow

name: publish

on:
  release:
    types:
      - published

env:
  REGISTRY_IMAGE: coatldev/six

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        platform:
          - linux/amd64
          - linux/arm64
    steps:
      - name: Prepare
        run: |
          platform=${{ matrix.platform }}
          echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV

      - name: Checkout
        uses: actions/checkout@v4

      - name: Get Dockerfile subdirectory
        id: dockerfile
        run: |
          echo "subdir=$(echo ${{ github.event.release.tag_name }} | cut -d '.' -f 1,2)" >> $GITHUB_OUTPUT

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

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

      - name: Python tags
        id: python
        uses: docker/metadata-action@v5
        with:
          images: |
            ${{ env.REGISTRY_IMAGE }}
          tags: |
            type=pep440,pattern={{version}}
            type=pep440,pattern={{major}}.{{minor}}
          flavor: |
            latest=${{ startsWith(github.ref, 'refs/tags/3.12') }}

      - name: Login to Docker Hub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Build and push Python digest
        id: build-python
        uses: docker/build-push-action@v5
        with:
          cache-from: type=gha
          cache-to: type=gha,mode=max
          context: ./${{ steps.dockerfile.outputs.subdir }}/python
          outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
          platforms: ${{ matrix.platform }}
          tags: ${{ steps.python.outputs.tags }}

      - name: Export digest
        run: |
          mkdir -p /tmp/digests
          digest="${{ steps.build-python.outputs.digest }}"
          touch "/tmp/digests/${digest#sha256:}"

      - name: Jython tags
        id: jython
        uses: docker/metadata-action@v5
        with:
          images: |
            ${{ env.REGISTRY_IMAGE }}
          tags: |
            type=pep440,prefix=jython-,pattern={{version}}
            type=pep440,prefix=jython-,pattern={{major}}.{{minor}}
            type=raw,enable=${{ startsWith(github.ref, 'refs/tags/3.12') }},value=jython

      - name: Build and push Jython digest
        id: build-jython
        uses: docker/build-push-action@v5
        with:
          cache-from: type=gha
          cache-to: type=gha,mode=max
          context: ./${{ steps.dockerfile.outputs.subdir }}/jython
          outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
          platforms: ${{ matrix.platform }}
          tags: ${{ steps.jython.outputs.tags }}

      - name: Export digest
        run: |
          mkdir -p /tmp/digests
          digest="${{ steps.build-jython.outputs.digest }}"
          touch "/tmp/digests/${digest#sha256:}"

      - name: Upload digest
        uses: actions/upload-artifact@v4
        with:
          name: digests-${{ env.PLATFORM_PAIR }}
          path: /tmp/digests/*
          if-no-files-found: error
          retention-days: 1

  merge:
    runs-on: ubuntu-latest
    needs:
      - build
    steps:
      - name: Download digests
        uses: actions/download-artifact@v4
        with:
          path: /tmp/digests
          pattern: digests-*
          merge-multiple: true

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

      - name: Docker meta
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: ${{ env.REGISTRY_IMAGE }}

      - name: Login to Docker Hub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Create manifest list and push
        working-directory: /tmp/digests
        run: |
          docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
            $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)

      - name: Inspect image
        run: |
          docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}

Workflow logs

logs_23660512994.zip

BuildKit logs

No response

Additional info

No response

cesarcoatl commented 1 month ago

After realizing tagging was the issue, and since this is building two images for two platforms, I decided to split it into two workflows.

ckrauterlovescoffee commented 1 week ago

In what way was tagging the issue? I am facing this problem. Not sure why.

ckrauterlovescoffee commented 1 week ago

I figured out my issue... Deleting the GitHub Actions Cache resolved it for me.