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.28k stars 548 forks source link

Force to use action/checkout with specific context #888

Closed headyj closed 10 months ago

headyj commented 1 year ago

Hello,

in the documentation, it's written the following:

By default, this action uses the [Git context](https://docs.docker.com/engine/reference/commandline/build/#git-repositories), so you don't need to use the [actions/checkout](https://github.com/actions/checkout/) action to check out the repository as this will be done directly by [BuildKit](https://github.com/moby/buildkit).

This seems not true, as I if I don't do an action/checkout before my docker build, sources are not even found:

buildx failed with: ERROR: could not find docker: stat docker: no such file or directory

my Dockerfile is in fact in a subfolder named "docker" on my git repo. The dockerfile will only be found if I do an action/checkout before my build-push-action:

      - name: Checkout
        uses: actions/checkout@v2
[...]
     - name: Build and push
        uses: docker/build-push-action@v4
        with:
          push: true
          tags: registry/image:latest
          file: docker/Dockerfile
          context: "/home/runner/work/git-repo/git-repo"

moreover, if I don't setup the context, git sources are not found at all

crazy-max commented 1 year ago

If you look at the bottom of the Git context section, we explain how to provide a subdir for the default Git context:

Default Git context can also be provided using the Handlebars template expression {{defaultContext}}. Here we can use it to provide a subdirectory to the default Git context:

      -
        # Setting up Docker Buildx with docker-container driver is required
        # at the moment to be able to use a subdirectory with Git context
        name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2
      -
        name: Build and push
        uses: docker/build-push-action@v4
        with:
          context: "{{defaultContext}}:mysubdir"
          push: true
          tags: user/app:latest

In your case:

     - name: Build and push
        uses: docker/build-push-action@v4
        with:
          context: "{{defaultContext}}:docker"
          push: true
          tags: registry/image:latest
          file: docker/Dockerfile