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

Feature request: Allow specifying subdirectory with default git context #460

Closed
PiDelport opened this issue Sep 6, 2021 · 7 comments · Fixed by #531
Closed

Feature request: Allow specifying subdirectory with default git context #460

PiDelport opened this issue Sep 6, 2021 · 7 comments · Fixed by #531
Labels
kind/enhancement New feature or request

Comments

@PiDelport
Copy link

PiDelport commented Sep 6, 2021

When using git repository contexts, Docker allows specifying a subdirectory using the syntax <repo>#<ref>:<subdir>, as documented here:

BuildKit used to not support this feature, but as of BuildKit 0.9.0, it does:

Can this action add support for this, to avoid the need to use checkouts to build subdirectories?

Workaround

For the time being, specifying a full git context seems to work; for example, to build subdirectory spam:

      - uses: docker/build-push-action@v2
        with:
          context: "https://github.com/${{ github.repository }}.git#${{ github.sha }}:spam"

However, this doesn't use the same logic for determining the default git context as the action does, so it might be fragile.

@crazy-max
Copy link
Member

crazy-max commented Sep 10, 2021

@PiDelport

However, this doesn't use the same logic for determining the default git context as the action does, so it might be fragile.

Indeed. I guess we could provide a magic var for this, then you could do:

      - uses: docker/build-push-action@v2
        with:
          context: "{{defaultContext}}:spam"

@crazy-max crazy-max added the kind/enhancement New feature or request label Sep 10, 2021
BeyondEvil added a commit to BeyondEvil/build-push-action that referenced this issue Dec 28, 2021
Since v0.9.0 of BuildKit (BuildX v0.7.0) you can provide a subdirectory
to the default Git context.

Closes docker#460
Closes docker#528
BeyondEvil added a commit to BeyondEvil/build-push-action that referenced this issue Dec 28, 2021
Since v0.9.0 of BuildKit (BuildX v0.7.0) you can provide a subdirectory
to the default Git context.

Closes docker#460
Closes docker#528

Signed-off-by: Jim Brännlund <jimbrannlund@fastmail.com>
BeyondEvil added a commit to BeyondEvil/build-push-action that referenced this issue Dec 28, 2021
Since v0.9.0 of BuildKit (BuildX v0.7.0) you can provide a subdirectory
to the default Git context.

Closes docker#460
Closes docker#528

Signed-off-by: Jim Brännlund <jimbrannlund@fastmail.com>
BeyondEvil added a commit to BeyondEvil/build-push-action that referenced this issue Jan 6, 2022
Since v0.9.0 of BuildKit (BuildX v0.7.0) you can provide a subdirectory
to the default Git context.

Closes docker#460
Closes docker#528

Signed-off-by: Jim Brännlund <jimbrannlund@fastmail.com>
@dimaqq
Copy link

dimaqq commented Jan 21, 2022

IMO this is still way too hard to get right...

  1. when does specifying context: ... require explicit checkout step? always? sometimes?
  2. when things go wrong, build fails with mysterious failed to fetch remote 😕

Ideally the UX could be something like this:

  • in local checkout you do cd some/sub/dir; docker build .
  • in the GHA, specify e.g. subdir: some/sub/dir

Or maybe:

  • in local I ran docker build -t xx -f subdir/docker/Dockerfile subdir
  • in the GHA, I'd specify file: subdir/docker/Dockerfile and path: subdir

@igorcosta
Copy link

The suggested workaround doesn't work for private repos.

      - uses: docker/build-push-action@v2
        with:
          context: "https://github.com/${{ github.repository }}.git#${{ github.sha }}:spam"

When I tried this, I get the following error.

Error: buildx failed with: error: failed to solve: failed to read dockerfile: failed to fetch remote 

I suspect because it's a private repository, it doesn't work. I guess will work only with public repos.

@PiDelport
Copy link
Author

Yes, for private repositories, you'll probably need to add credentials from an appropriate environment variable to the URL.

@simensol
Copy link

@PiDelport Do you have an example on how to add credentials to the URL?

@karm435
Copy link

karm435 commented Jan 25, 2023

@simensol you can use this for Private repos

with:
  push: true
  tags: user/app:latest
  secrets: |
      GIT_AUTH_TOKEN=${{ secrets.MYTOKEN }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants