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

Path context error when copying file from nested Dockerfile #1113

Closed moy2010 closed 1 month ago

moy2010 commented 1 month ago

Contributing guidelines

I've found a bug, and:

Description

Copying a file from a Dockerfile fails despite providing a path context.

Expected behaviour

The behaviour observed when building the docker image locally.

Actual behaviour

The file can't be located, resulting in an error

Repository URL

No response

Workflow run URL

No response

YAML workflow

name: Publish Docker Image

on:
  pull_request:
    paths:
      - web-apps/apps/demo-app/**
      - web-apps/packages/**
    branches:
      - main

jobs:
  build-and-push-docker-image:
    runs-on: ubuntu-latest

    steps:
      - name: Check out the repo
        uses: actions/checkout@v3

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

      - name: Extract metadata (tags, labels) for Docker
        id: meta
        uses: docker/metadata-action@v4
        with:
          images: demo-app
          flavor: latest=true
          tags: |
            type=ref,event=branch
            type=ref,event=pr
            type=semver,pattern={{version}}

      - name: Build and push Docker image
        uses: docker/build-push-action@v5
        with:
          context: web-apps
          file: web-apps/apps/demo-app/Dockerfile
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}

Workflow logs

11 [builder 5/7] COPY /apps/demo-app/tsconfig.production.json ./tsconfig.production.json

11 ERROR: failed to calculate checksum of ref 584d62f5-11d9-4074-87e4-acacf60905a6::lk5e1y6f6z47pufppid6zsnff: "/apps/demo-app/tsconfig.production.json": not found

BuildKit logs

No response

Additional info

Building the docker image locally from the aforementioned build context works (docker build -f ./apps/demo-app/Dockerfile .). My gut feeling is that somehow build-push-action is reading the path provided to the COPY command as absolute rather than relative to the path context.

moy2010 commented 1 month ago

Update: Somehow, the file sytem on the Github action went nuts, and couldn't see the file. This is why it worked locally. I renamed it and the Github action is working now.