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

Docker build cannot access downloaded artifacts #1131

Closed bfbachmann closed 3 weeks ago

bfbachmann commented 3 weeks ago

Contributing guidelines

I've found a bug, and:

Description

The Docker buildx builder cannot access files downloaded from GHA artifacts. Here's my minimal reproduction:

Dockerfile.test

FROM scratch AS controller
COPY dist/artifacts/test /tmp/test

With this configuration, I have a job called build-test that creates and uploads artifacts. The second job called build-image downloads the artifacts to dist/artifacts and then attempts to build a Docker image using this build-push-action.

Expected behaviour

The copy should work just fine, like any other copy.

Actual behaviour

The Docker build fails with the following error:

#4 [1/1] COPY dist/artifacts/test /tmp/test
#4 ERROR: failed to calculate checksum of ref 714cs4nh3dvawerm1x67d1u8b::jzalluzhqlppqyyofx3nhgrp9: failed to walk /tmp/buildkit-mount2093046158/dist/artifacts: lstat /tmp/buildkit-mount2093046158/dist/artifacts: no such file or directory
------
 > [1/1] COPY dist/artifacts/test /tmp/test:
------
WARNING: No output specified with docker-container driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load
Dockerfile.test:2
--------------------
   1 |     FROM scratch AS controller
   2 | >>> COPY dist/artifacts/test /tmp/test
--------------------
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref 714cs4nh3dvawerm1x67d1u8b::jzalluzhqlppqyyofx3nhgrp9: failed to walk /tmp/buildkit-mount2093046[158](https://github.com/bfbachmann/system-upgrade-controller/actions/runs/9393343783/job/25869234593#step:9:163)/dist/artifacts: lstat /tmp/buildkit-mount2093046158/dist/artifacts: no such file or directory

Repository URL

https://github.com/bfbachmann/system-upgrade-controller

Workflow run URL

https://github.com/bfbachmann/system-upgrade-controller/actions/runs/9393404514

YAML workflow

name: Test

on: 
  push:
    branches:
      - 'gha'

env:
  IMAGE: test/test
  TAG: ${{ github.ref_name }}

jobs:
  build-test:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - name: Generate dummy artifacts
        run: |
          mkdir -p dist/artifacts
          echo "test" > dist/artifacts/dummy.txt

      - name: Upload artifacts
        uses: actions/upload-artifact@v4
        with:
          name: artifacts
          path: dist/artifacts/*
          if-no-files-found: error
          overwrite: true

  build-image:
    runs-on: ubuntu-latest
    needs: 
      - build-test
    permissions:
      contents: read
    strategy:
      matrix:
        os: [linux]
        arch: [amd64]
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Docker meta
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: ${{ env.IMAGE }}
          flavor: latest=false

      - name: Fix the not-a-git-repository issue
        run: git config --global --add safe.directory "$GITHUB_WORKSPACE"

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

      - name: Download artifacts
        uses: actions/download-artifact@v4
        with:
          path: dist/artifacts
          merge-multiple: true

      - name: Debug
        run: ls -lah dist/artifacts

      - name: Build
        uses: docker/build-push-action@v5
        with:
          context: .
          file: Dockerfile.test
          push: false
          tags: "${{ steps.meta.outputs.tags }}"
          platforms: "${{ matrix.os }}/${{ matrix.arch }}"
          labels: "${{ steps.meta.outputs.labels }}"

Workflow logs

logs_24585592087.zip

BuildKit logs

No response

Additional info

No response

PawanMadvIT commented 2 days ago

Why this issue is closed? I am also having same issue. What was the resolution?