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

Setting path context does not work when using workflow_dispatch #1165

Closed mmllc-jsilverman closed 4 days ago

mmllc-jsilverman commented 4 days ago

Contributing guidelines

I've found a bug, and:

Description

I'm trying to manually trigger a workflow that builds off of a specific branch or tag

For example, tag v24.6.28.1 exists; I want to use that tag to run this action against. However, I want to trigger it manually, via workflow_dispatch.

No matter what combination of checkout action, moving the codebase into a different dir, specifying that dir with this action's PATH context -- it always uses the master branch to build images.

fwiw, the checkout action seems to suffer from this problem as well. To fix that, I had to check out to a subdir, and manually run git checkout -b branchname tagname to switch to the branch or tag i want here.

For example, I check out the codebase with the checkout action, then switch branch as stated.

The final path is ${GITHUB_WORKSPACE}/fix-refs/

When I run the action in this example, I get the error ERROR: unable to prepare context: path "$***GITHUB_WORKSPACE***/fix-refs/" not found

If I try to use a relative path, it just uses the master branch and not the tag I want to use.

Is there no way to do this with workflow_dispatch?

Expected behaviour

context should use any arbitrary directory; and/or should not use the github push event context

Actual behaviour

this action always uses the branch (master) in the push context

Repository URL

No response

Workflow run URL

No response

YAML workflow

This is just the step causing the issue; in this case, the build-push action builds master:

      - name: Build and push docker
        uses: docker/build-push-action@v6
        with:
          context:  fix-refs/
          push: true
          tags: |
            us-docker.pkg.dev/${{ matrix.project }}/my-proj/my-proj:${{ env.RELEASE_TAG }}
          file: fix-refs/Dockerfile
          target: prod

Or this; in this case, I get the error `ERROR: unable to prepare context: path "$***GITHUB_WORKSPACE***/fix-refs/" not found`

      - name: Build and push docker
        uses: docker/build-push-action@v6
        with:
          context: ${GITHUB_WORKSPACE}/fix-refs/
          push: true
          tags: |
            us-docker.pkg.dev/${{ matrix.project }}/my-proj/my-proj:${{ env.RELEASE_TAG }}
          file: fix-refs/Dockerfile
          target: prod

Workflow logs

No response

BuildKit logs

No response

Additional info

No response

mmllc-jsilverman commented 4 days ago

I have a feeling this is gonna end up getting closed as "won't fix" or "intended behavior"; so lemme document my workaround/solution.

I figured out a solution which is

crazy-max commented 4 days ago

run via workflow_dispatch and select that branch under "from which branch" dropdown

Yes you need to select the right branch for workflow_dispatch

cherry pick my workflow into the branch or tag

Yes this might be necessary as well if workflow is not aligned with default branch

More info on this event: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch

          context: ${GITHUB_WORKSPACE}/fix-refs/

Syntax is not correct and should be ${{ env.GITHUB_WORKSPACE }}: https://docs.github.com/en/actions/learn-github-actions/variables#using-the-env-context-to-access-environment-variable-values


Closing as this doesn't seem an issue with the action but your workflow imo. But feel free to leave a reply if you still think something needs to be considered. Thanks.