Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working directory is not applying to docker/build-push-action@v2 #327

Closed
dszymczuk opened this issue Mar 31, 2021 · 1 comment
Closed

Working directory is not applying to docker/build-push-action@v2 #327

dszymczuk opened this issue Mar 31, 2021 · 1 comment

Comments

@dszymczuk
Copy link

Troubleshooting

I saw that docker/build-push-action@v2 is not applying a working-directory setup.
Here is my GitHub action file:

name: Push docker images

on:
  push:

defaults:
  run:
    working-directory: ./api # here I setup working directory for flow

jobs:
  build:
    runs-on: ubuntu-latest
    timeout-minutes: 15

    steps:
      - uses: actions/checkout@v2

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1

      -
        name: Build Docker Image - API
        uses: docker/build-push-action@v2
        with:
          file: dockerfiles/api/Dockerfile
          context: .
          push: false
          tags: myimage:latest

Expected behaviour

Build image without error

Actual behaviour

/usr/bin/docker buildx build --tag myimage:latest --iidfile /tmp/docker-build-push-ed2Vyp/iidfile --file dockerfiles/api/Dockerfile .

error: could not find dockerfiles/api: stat dockerfiles/api: no such file or directory
Error: buildx call failed with: error: could not find dockerfiles/api: stat dockerfiles/api: no such file or directory

Fix

To fix this I have to pass file and context as path from root. In this case is:

name: Push docker images

on:
  push:

defaults:
  run:
    working-directory: ./api

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Login to Docker Repository
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
          registry: ${{ secrets.DOCKER_REPOSITORY }}

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1

      -
        name: Build Docker Image - API
        uses: docker/build-push-action@v2
        with:
          file: api/dockerfiles/api/Dockerfile
          context: ./api
          push: false
          tags: myimage:latest

With this fix I can build my image.

@crazy-max
Copy link
Member

@dszymczuk

I saw that docker/build-push-action@v2 is not applying a working-directory setup.

defaults.run only applies to jobs.<job_id>.steps[*].run as stipulated in the doc.

arburk added a commit to baloise-incubator/codeql2sonar-maven-plugin that referenced this issue Aug 20, 2021
budak7273 added a commit to AutomatingSciencePipeline/Monorepo that referenced this issue May 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants