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

No examples of path or dockerfile options #51

Closed
bobvanderlinden opened this issue May 28, 2020 · 25 comments
Closed

No examples of path or dockerfile options #51

bobvanderlinden opened this issue May 28, 2020 · 25 comments
Milestone

Comments

@bobvanderlinden
Copy link

bobvanderlinden commented May 28, 2020

I'm working on a project that has multiple Dockerfiles, each of them in a separate directory. One of those is named api, so the dockerfile is in api/Dockerfile. I have the following in my workflow:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: docker/build-push-action@v1
      with:
        path: api
        username: companyusername
        password: companypassword
        repository: company/myproject/api
        registry: companyregistry
        tags: latest

I get the following error:

unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /github/workspace/api/Dockerfile: no such file or directory

However, I see the checkout action logging the following:

Initializing the repository
  /usr/bin/git init /home/runner/work/myproject/myproject

From the documentation it is unclear that I should be using some variable to determine /home/runner/work/myproject/myproject instead of /github/workspace/. What am I doing wrong?

I also tried using dockerfile:, but also with the same results: always relative to /github/workspace.

@yordis
Copy link

yordis commented May 28, 2020

@bobvanderlinden use uses: actions/checkout@v1 for now since it seems that the action is broken with v2

@bobvanderlinden
Copy link
Author

I now have the following:

    steps:
    - uses: actions/checkout@v1
    - uses: docker/build-push-action@v1
      with:
        path: api
        username: ${{ secrets.DOCKER_USERNAME }}
        password: ${{ secrets.DOCKER_PASSWORD }}
        repository: mycompany/myproject/api
        registry: ${{ secrets.DOCKER_REGISTRY }}
        tags: latest

and I'm still seeing:

unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /github/workspace/api/Dockerfile: no such file or directory

@yordis
Copy link

yordis commented May 28, 2020

I have the following

name: "Release"

on:
  push:
    branches:
      - "production"

jobs:
  publish_docker_image:
    runs-on: ubuntu-latest
    name: Publish docker image
    steps:
      - name: Checkout
        uses: actions/checkout@v1
      - name: Publish image
        uses: docker/build-push-action@v1
        with:
          registry: docker.pkg.github.com
          username: $GITHUB_ACTOR
          password: ${{ secrets.GITHUB_TOKEN }}
          repository: org/repo/name
          tag_with_ref: true
          tag_with_sha: true

And it works.

Make sure you have a Dockerfile in the root of the project, double-check that.

@bobvanderlinden
Copy link
Author

Your example doesn't have a path nor a dockerfile option. My project doesn't have a Dockerfile on the root of the repository, which is why I was forced to use the path option.

@sau00
Copy link

sau00 commented May 31, 2020

Got the same issue as @bobvanderlinden, looks like path option doesn't work at all.

@sau00
Copy link

sau00 commented Jun 1, 2020

Alright, I get it now.
If you want to use path and dockerfile options at the same time, you should make sure that your dockerfile option matches the pattern {path}/%Dockerfile%. Cause by default parttern is {path}/Dockerfile.

Examples
I have my dockerfile named Dockerfile.txt in ./backend/ folder, then my options should look like this:

path: backend
dockerfile: backend/Dockerfile.txt

Dockerfile is default name for dockerfiles. So if I have file named Dockerfile in ./frontend/ folder, then I just set path option like this:

path: frontend

@jonkight
Copy link

jonkight commented Jun 2, 2020

I'm seeing a similar issue with the following:

    steps:
      - uses: docker/build-push-action@v1
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
          repository: my/repo
          tags: latest
          path: src/go/server

My Dockerfile is located at ./src/go/server/Dockerfile. Seeing the following:

unable to prepare context: path "src/go/server" not found

Any ideas what I'm missing?

@bobvanderlinden
Copy link
Author

@sau00 that is quite useful to know. Such examples could be useful to have in the readme.

@jonkight did you do a checkout step?

@jonkight
Copy link

jonkight commented Jun 3, 2020

@bobvanderlinden
Great point! That was exactly my problem and everything works as expected now with the config I mentioned above. Not sure why I thought it would work without it, but at some point I removed the checkout I guess. Thanks for responding so quickly.

@jonkight
Copy link

jonkight commented Jun 3, 2020

@sau00 Thanks for your comment as well. It helped me validate what I was testing.

@bobvanderlinden
Copy link
Author

If that works for you I have to revisit my example again, something must be wrong on my side of things.

@jonkight
Copy link

jonkight commented Jun 3, 2020

Here's what I got working as a test. Hopefully it helps. Repo is obviously fake, but everything else is real.

name: Build, test, and push Docker image

on: pull_request

jobs:
  vm-job:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
        with:
          ref: ${{ github.event.pull_request.head.ref }}
          fetch-depth: 0
      - uses: docker/build-push-action@v1
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
          repository: my/repo
          tags: latest
          path: src/go/server

@joebone
Copy link

joebone commented Jun 19, 2020

Similar issue, but not sure how to resolve it...

Directory structure is:
/root/src/

The build context needs to be set to /root/src/,
and the Dockerfiles would be in [ /src/projecta/dockerfile, /src/projectb/dockerfile ] etc... but the context has to be the parent in order for the internal compilation step to be able to pull in inter-project dependencies.

running from a command line would be something along the lines of:
docker build -f Dockerfile ".."

or from the root:

docker build -f "./src/projecta/Dockerfile" "./src".

How can I represent this structure, as it seems the path is completely ignored..

@crazy-max
Copy link
Member

crazy-max commented Sep 2, 2020

Hi,

This will be solved through build-push-action v2 (#92) as it's written as a typescript-action to be as closed as possible of the GitHub Runner during its execution. You can already try it with:

@crazy-max crazy-max added this to the v2 milestone Sep 2, 2020
@crazy-max
Copy link
Member

Version 2 has been merged to the main branch and is therefore available via uses: docker/build-push-action@v2 (mutable tag).

As a reminder, this new version changes drastically and works with 3 new actions (login, setup-buildx and setup-qemu) that we have created. Many usage examples have been added to handle most use cases.

And it should fix this current issue. Don't hesitate if you have any questions.

@bobvanderlinden
Copy link
Author

That looks good! Thanks a lot 👍

@dinvlad
Copy link

dinvlad commented Oct 2, 2020

We're still seeing the same error, even with @v2. I wonder what that could be?

- uses: docker/setup-buildx-action@v1
- uses: docker/build-push-action@v2
  with:
    context: ./path/to/context
    tags: docker/image/name:latest

Result:

Run docker/build-push-action@v2
  with:
    context: ./path/to/context
    push: true
    tags: docker/image/name:latest
    file: ./Dockerfile
    pull: false
    no-cache: false
    load: false
    github-token: ***
📣 Buildx version: 0.4.2
🏃 Starting build...
/usr/bin/docker buildx build --tag docker/image/name:latest --iidfile /tmp/docker-build-push-XMCDtE/iidfile --file ./Dockerfile --push ./path/to/context
time="2020-10-02T03:11:16Z" level=warning msg="invalid non-bool value for BUILDX_NO_DEFAULT_LOAD: "
#2 [internal] load .dockerignore
#2 transferring context: 77B 0.0s done
#2 DONE 0.0s

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 2B 0.0s done
#1 DONE 0.0s
failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /tmp/buildkit-mount934169700/Dockerfile: no such file or directory
Error: The process '/usr/bin/docker' failed with exit code 1

I have verified that our ./path/to/context does contain Dockerfile - not sure where else to look.
Thanks!

@dinvlad
Copy link

dinvlad commented Oct 2, 2020

OK, so our mistake was that file: is not relative to context:! We have to specify it like this:

- uses: docker/build-push-action@v2
  with:
    context: ./path/to/context
    file: ./path/to/context/Dockerfile
    tags: docker/image/name:latest

It would be nice to document it more explicitly :)

@guumaster
Copy link

We have this same issue in our workflow. And I think the documentation is not entirely clear. If you have to specify a context path, be sure to add a step with the check out action.

# This Checkout is necessary when using a context in docker/build-push-action
- name: Checkout
  uses: actions/checkout@v2
....
- uses: docker/build-push-action@v2
  with:
    context: ./path/to/context
    file: ./path/to/context/Dockerfile
    tags: docker/image/name:latest

@crazy-max
Copy link
Member

@guumaster See #189

@guumaster
Copy link

@crazy-max thanks. but I think is not the same issue.

No matter what you put on file: (the default works ok), if you add a context: path, you need to also add the code checkout action explicitly too. Otherwise, it will complain with the error unable to prepare context: ... folder not found error.

@crazy-max
Copy link
Member

@guumaster

thanks. but I think is not the same issue.

Sorry that's this one: #120 (comment). See also Git context and Path context.

@guumaster
Copy link

@crazy-max that's the one. And you are rigth that it is in the docs, but it seems clear once you already had the issue.

Is it a good idea to add this info in the TROUBLESHOOTING.md section? I can make a PR with it.

@crazy-max
Copy link
Member

@guumaster Sure feel free to open a PR.

@vot4anto
Copy link

@crazy-max thanks. but I think is not the same issue.

No matter what you put on file: (the default works ok), if you add a context: path, you need to also add the code checkout action explicitly too. Otherwise, it will complain with the error unable to prepare context: ... folder not found error.

@guumaster thanks to your suggestion I finally go out from a nightmare buildx on github action

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

9 participants