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

subdir not supported yet while it should be supported #676

Closed
jkulak opened this issue Aug 23, 2022 · 9 comments
Closed

subdir not supported yet while it should be supported #676

jkulak opened this issue Aug 23, 2022 · 9 comments

Comments

@jkulak
Copy link

jkulak commented Aug 23, 2022

Behaviour

It is a simple repository with a Dockerfile (in a subdirectory). I want to build the image and push it to Docker Hub. It fails.

Steps to reproduce this issue

  1. Fork https://github.com/jkulak/gh-actions-test
  2. Commit any new file/change
  3. Actions will run, and there will be an ERROR

Expected behaviour

It seems like a simple/basic use case for build-push-action. I would expect it build the Docker image and push it to Docker Hub.

Actual behaviour

Build fails. Seems like the action can not find the Dockerfile, which is located in the ./app directory of the repository.

#1 [internal] load git source https://github.com/***/gh-actions-test.git#7915aa22036b623876c4e04eeda5754b72aafaeb:app
#1 ERROR: subdir not supported yet

Configuration

name: Docker Image CI

on:
    push:
        branches: ["*"]

jobs:
    docker:
        runs-on: ubuntu-latest
        steps:
            - name: Login to DockerHub
              uses: docker/login-action@v2
              with:
                  username: ${{ secrets.DOCKERHUB_USERNAME }}
                  password: ${{ secrets.DOCKERHUB_TOKEN }}
            - name: Build and push
              uses: docker/build-push-action@v3
              with:
                  context: "{{defaultContext}}:app"
                  push: true
                  tags: grabtrack/app:latest

Logs

logs_4.zip

Also:

1s
Run docker/build-push-action@v3
  with:
    context: {{defaultContext}}:app
    push: true
    tags: grabtrack/app:latest
    load: false
    no-cache: false
    pull: false
    github-token: ***
Docker info
Buildx version
  /usr/bin/docker buildx version
  github.com/docker/buildx 0.9.0+azure-[1](https://github.com/jkulak/gh-actions-test/runs/7976332899?check_suite_focus=true#step:3:1) 6113[2](https://github.com/jkulak/gh-actions-test/runs/7976332899?check_suite_focus=true#step:3:2)9fc7f1[3](https://github.com/jkulak/gh-actions-test/runs/7976332899?check_suite_focus=true#step:3:3)65556789bff[4](https://github.com/jkulak/gh-actions-test/runs/7976332899?check_suite_focus=true#step:3:4)747f608d40cdc8a9
/usr/bin/docker buildx build --iidfile /tmp/docker-build-push-0pxVKg/iidfile --secret id=GIT_AUTH_TOKEN,src=/tmp/docker-build-push-0pxVKg/tmp-1[5](https://github.com/jkulak/gh-actions-test/runs/7976332899?check_suite_focus=true#step:3:5)35-gtFtbXRZZaTx --tag grabtrack/app:latest --metadata-file /tmp/docker-build-push-0pxVKg/metadata-file --push https://github.com/***/gh-actions-test.git#7915aa2203[6](https://github.com/jkulak/gh-actions-test/runs/7976332899?check_suite_focus=true#step:3:6)b6238[7](https://github.com/jkulak/gh-actions-test/runs/7976332899?check_suite_focus=true#step:3:7)6c4e04eeda5754b72aafaeb:app
#1 [internal] load git source https://github.com/***/gh-actions-test.git#7915aa22036b623[8](https://github.com/jkulak/gh-actions-test/runs/7976332899?check_suite_focus=true#step:3:8)76c4e04eeda5754b72aafaeb:app
#1 ERROR: subdir not supported yet
------
 > [internal] load git source https://github.com/***/gh-actions-test.git#7[9](https://github.com/jkulak/gh-actions-test/runs/7976332899?check_suite_focus=true#step:3:9)15aa22036b623876c4e04eeda5754b72aafaeb:app:
------
ERROR: failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: failed to read dockerfile: failed to load cache key: subdir not supported yet
Error: buildx failed with: ERROR: failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: failed to read dockerfile: failed to load cache key: subdir not supported yet
@polarathene
Copy link

From docker build docs:

Note

You cannot specify the build-context directory (myfolder in the examples above) when using BuildKit as builder (DOCKER_BUILDKIT=1). Support for this feature is tracked in buildkit#1684.

Although the issue closed as resolved over a year ago, so maybe those docs are outdated. Might be related to the issue you're having though 🤷‍♂️

Can you make it work locally with the same versions used by the action?

@jcnils
Copy link

jcnils commented Aug 31, 2022

I have the same problem with v3.1.1

context: .
file: ./docker/Dockerfile
/usr/bin/docker buildx build --file ./docker/Dockerfile --iidfile /tmp/docker-build-push-D7L3OP/iidfile --tag [repo]/[img]:[tag] --metadata-file /tmp/docker-build-push-D7L3OP/metadata-file --push .
ERROR: could not find docker: stat docker: no such file or directory
Error: buildx failed with: ERROR: could not find docker: stat docker: no such file or directory

I tried different paths as well:

  • /docker/Dockerfile
  • docker/Dockerfile
  • repo/docker/Dockerfile

=====

@polarathene

I can make it work local with buildx v0.8.2-docker,
docker buildx build --platform=linux/arm64 --push -t aidantai/tcpgeneric:hello_scratch -f ./docker/Dockerfile .

the GitHub actions is using github.com/docker/buildx 0.9.1+azure-1

@polarathene
Copy link

I have the same problem with v3.1.1

context: .
file: ./docker/Dockerfile

That is not the same problem.

You used context: . which is "PATH" context, not "GIT" context (default of this action).

This issue is about using subdir with the git build context (eg: context: {{defaultContext}}:app for app/).


Your issue states from the error that docker could not be found. So your workflow is not configured properly.

@jcnils
Copy link

jcnils commented Aug 31, 2022

I see, sorry, my mistake. I will open another one. Thanks.

I saw this one, but it was closed #169
I mistakenly thought it was related.

btw, the docker it is missing is the name of the directory. if I run with another name it shows.
buildx failed with: ERROR: could not find repo/docker: stat repo/docker: no such file or directory

@crazy-max
Copy link
Member

See for more info #673 (comment)

Closing this issue since that should answer your question, but feel free to re-open if it doesn't. Thanks.

@jkulak
Copy link
Author

jkulak commented Sep 1, 2022

It does not.

@crazy-max
Copy link
Member

@jkulak Will copy/paste for good measure:

If you're using the docker builder (default if setup-buildx-action not used, then BuildKit in Docker Engine will be used. Current Docker Engine version 20.10.17 embeds Buildkit 0.8.2 and therefore does not support subdir with git context. That's why you have this warning message.

And yes it's recommended to use the setup-buildx-action because will create a docker-container builder using the latest stable version of BuildKit (0.10.4 atm).

What is missing from my comment?

@polarathene
Copy link

polarathene commented Sep 2, 2022

It does not.

The docs update is very good at explaining it. But if you need extra clarification:

  • buildx uses BuildKit, and docker (Docker Engine which provides docker migrated to the moby project since 2022. The moby README doesn't mention it, but if you view their releases page, you can see that's the case).
  • docker releases provide their own buildx by default, but it's version is too old to have the subdir support.
  • buildx can be installed separately (which setup-buildx-action will do for you, and you have skipped this in your shared config, you need it as a step before build-push-action), doing so you can get a new enough version that has BuildKit version with the subdir feature support available.

Basically, docker does not yet have the compatibility. You'll need to wait for a future release to be available.

However if you use setup-buildx-action prior to your build-push-action step, you'll get a newer version of buildx that docker can use (via this actions docker-container builder, instead of the plain docker builder).

You don't have to do anything else, just add the setup-buildx-action step, like this projects README shows.

@jkulak
Copy link
Author

jkulak commented Sep 4, 2022

Thank you, it solves the issue.

The docs update makes it clear. 👍🏽

Zweihander-Main added a commit to Zweihander-Main/docker that referenced this issue Dec 11, 2022
Allows using subdirectories by forcing a more recent version of buildx.
See docker/build-push-action#676
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

4 participants