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

Build-push action requires actions/checkout #1146

Closed Ethycs closed 1 week ago

Ethycs commented 1 week ago

Contributing guidelines

I've found a bug, and:

Description

Despite the documentation claiming the opposite, you do need to check out the repository

Expected behaviour

By default, this action uses the Git context, so you don't need to use the actions/checkout action to check out the repository as this will be done directly by BuildKit.

(This is a quote of the documentation from the repo)

Actual behaviour

Build fails because the repository is not checked out. action is fixed by adding a actions/checkout This was also tried with the following added: name: Set up Docker Buildx uses: docker/setup-buildx-action@v3

Repository URL

No response

Workflow run URL

No response

YAML workflow

name: <REDACTED>
on:
  push:
    branches:
      - main

env:
  REGISTRY: ghcr.io
  IMAGE_NAME: ${{ github.repository }}

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

    permissions:
      contents: read
      packages: write
      attestations: write
      id-token: write

    steps:
    - name: Check working directory
      run: pwd

    - name: Login to GitHub Container Registry
      uses: docker/login-action@v3
      with:
        registry: ${{ env.REGISTRY }}
        username: ${{ github.actor }}
        password: ${{ secrets.GITHUB_TOKEN }}
    - name: Build and push Docker image
      uses: docker/build-push-action@v6
      with:
        context: .
        file: ./dockerfile
        push: true
        tags: <REDACTED>
        # tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest.REGISTRY }}/${{ env.IMAGE_NAME }}:latest

Workflow logs

No response

BuildKit logs

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

Additional info

No response

crazy-max commented 1 week ago

If you want to use Git context, then don't specify context: .:

    - name: Build and push Docker image
      uses: docker/build-push-action@v6
      with:
        file: ./dockerfile
        push: true
        tags: <REDACTED>
        # tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest.REGISTRY }}/${{ env.IMAGE_NAME }}:latest