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.24k stars 541 forks source link

How to mount `${{ github.workspace }}` so that it can be used by the Docker image? #904

Closed sarthakpati closed 11 months ago

sarthakpati commented 1 year ago

Troubleshooting

N.A.

Behaviour

I am unable to mount ${{ github.workspace }} in a way that is visible within the Docker image. The reasoning behind this is that I would like to build the image from the pull requests' code changes.

Steps to reproduce this issue

Here are the full workflow file and Dockerfile for reference.

Expected behaviour

I would like to make the contents of ${{ github.workspace }} from the host machine running the workflow inside the container as /Front-End.

Actual behaviour

/Front-End seems to be empty.

Configuration

I am using the following (relevant) sections in the workflow file:

jobs:

  build_test_push:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false # So that remaining jobs don't instantly quit if one fails (e.g, CPU/ROCm don't upload if CUDA just fails to push to ghcr...)
      # matrix:
        # include: # Platform locates Dockerfile ("Dockerfile-{PLATFORM}"), docker tag has to be all lowercase alphanumeric for mysterious docker reasons
          # - platform: CPU
          #   dockertag: cpu
          # - platform: ROCm
          #   dockertag: rocm

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

    # Extract metadata (tags, labels) for Docker
    # https://github.com/docker/metadata-action
    - name: Extract Docker metadata
      id: meta
      uses: docker/metadata-action@v4
      with:
        images: ghcr.io/fets-ai/front-end
        flavor: | # Handle prefixing and "latest" generation -- use "tags" property to specify events/tags further
          latest=true
        tags: |
          type=semver,pattern={{version}}
          type=ref,event=branch
          type=ref,event=pr
          type=ref,event=tag

    # Build Docker Image (but don't push yet -- wait for the test step first).
    # https://github.com/docker/build-push-action
    - name: Build Docker images
      id: build
      uses: docker/build-push-action@v4
      with:
        context: .
        # cache-from: type=local,src=${{ github.workspace }}
        ## did not work
        build-args: --mount 'type=volume,src=${{ github.workspace }},dst=/Front-End,volume-driver=local' 
        # build-args: --mount 'type=bind,src=${{ github.workspace }},target=/Front-End'
        # build-args: -v ${{ github.workspace }}:/Front-End
        file: ./Dockerfile
        push: false
        load: true
        tags: ${{ steps.meta.outputs.tags }}
        labels: ${{ steps.meta.outputs.labels }}

Logs

Download the log file of your build and attach it to this issue.

logs_71.zip

Update

20230712: I tried adding VOLUME /Front-End to the Dockerfile as well, but to no avail.

crazy-max commented 11 months ago

When running the action and using context: . you are already in ${{ github.workspace }}. You just need to add COPY . /myproject if you want to copy the content in your image.