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.11k stars 526 forks source link

Error: buildx failed with: ERROR: failed to solve: failed to read dockerfile: open Dockerfile: no such file or directory #1082

Closed okarmusk closed 3 months ago

okarmusk commented 3 months ago

Contributing guidelines

I've found a bug, and:

Description

I've created a github action to build my docker image with buildx. My repository uses monorepo structure and I've decided to create separate workflow based on subpath of project. Workflow runs smoothly to trying build docker image, then it crushes. Dockerfile is visible in subdirectory, even target build maven is, but action still logs:

Run docker/build-push-action@v5
GitHub Actions runtime token ACs
Docker info
Proxy configuration
Buildx version
/usr/bin/docker buildx build --iidfile /home/runner/work/_temp/docker-actions-toolkit-CsABYt/iidfile --provenance mode=min,inline-only=true,builder-id=https://github.com/***/authonium/actions/runs/8333578068 --tag ***/keycloak-authonium:latest --metadata-file /home/runner/work/_temp/docker-actions-toolkit-CsABYt/metadata-file --push .
#0 building with "builder-c256609a-8401-49b2-adbf-73c02af67175" instance using docker-container driver

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 2B done
#1 DONE 0.0s
ERROR: failed to solve: failed to read dockerfile: open Dockerfile: no such file or directory
Error: buildx failed with: ERROR: failed to solve: failed to read dockerfile: open Dockerfile: no such file or directory

Just before I've added DEBUG step to display files located in working directory and Dockerfile is available:

Run ls
Dockerfile
README.md
docker-compose.yml
keycloak.env
mvnw
mvnw.cmd
pom.xml
realms
run.sh
src
target

I tried to remove context: ., but results are the same.

Expected behaviour

Docker image is built and pushed to registry.

Actual behaviour

Github action buildx crushes.

Repository URL

No response

Workflow run URL

No response

YAML workflow

name: Build subdirectoryA

on:
  push:
    branches: [ main ]
    paths: [ 'subdirectoryA/**' ]
  pull_request:
    branches: [ main ]
  workflow_call:

defaults:
  run:
    working-directory: subdirectoryA

jobs:
  build-and-test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Maven build and test
        run: ./mvnw clean install

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

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

      - name: Login to Docker Hub
        uses: docker/login-action@v3
        with:
          registry: my-private-registry.com
          username: ${{ secrets.username }}
          password: ${{ secrets.password }}

      - name: DEBuG
        run: ls

      - name: Build and push
        uses: docker/build-push-action@v5
        with:
          context: .
          push: true
          tags: user/app:latest

Workflow logs

Run docker/build-push-action@v5 GitHub Actions runtime token ACs Docker info Proxy configuration Buildx version /usr/bin/docker buildx build --iidfile /home/runner/work/_temp/docker-actions-toolkit-CsABYt/iidfile --provenance mode=min,inline-only=true,builder-id=https://github.com/***/authonium/actions/runs/8333578068 --tag ***/keycloak-authonium:latest --metadata-file /home/runner/work/_temp/docker-actions-toolkit-CsABYt/metadata-file --push .

0 building with "builder-c256609a-8401-49b2-adbf-73c02af67175" instance using docker-container driver

1 [internal] load build definition from Dockerfile

1 transferring dockerfile: 2B done

1 DONE 0.0s

ERROR: failed to solve: failed to read dockerfile: open Dockerfile: no such file or directory Error: buildx failed with: ERROR: failed to solve: failed to read dockerfile: open Dockerfile: no such file or directory

BuildKit logs

No response

Additional info

No response

tonistiigi commented 3 months ago

defaults: run: working-directory: subdirectoryA

I would guess this only changes the working directory for the inline "run" steps.

From Github docs:

You can use defaults.run to provide default shell and working-directory options for all run steps in a workflow. You can also set default settings for run that are only available to a job. For more information, see jobs..defaults.run. You cannot use contexts or expressions in this keyword.

In that case you would need to set context: subdirectoryA assuming you want to shift the whole context and not just use a custom Dockerfile name. Alternatively you can also use a Git path with : separator.

okarmusk commented 3 months ago

@tonistiigi thank you for your response. After changing the context it works. I was confused, because before there is a maven step what executes properly and ls also shown the Dockerfile.

Thank you once again.