Skip to content

bake: preserve git subdir in remote bake context paths#3682

Merged
tonistiigi merged 1 commit intodocker:masterfrom
crazy-max:bake-print-subdir
Mar 3, 2026
Merged

bake: preserve git subdir in remote bake context paths#3682
tonistiigi merged 1 commit intodocker:masterfrom
crazy-max:bake-print-subdir

Conversation

@crazy-max
Copy link
Member

@crazy-max crazy-max commented Mar 3, 2026

The repro shown in #3462 was not correct and didn't handle subdir. With this change it supports both fragment and query format with a subdir.

$ docker buildx bake "https://github.com/tonistiigi/xx.git#refs/tags/v1.9.0" xx --print
#0 building with "default" instance using docker driver

#1 [internal] load git source https://github.com/tonistiigi/xx.git#refs/tags/v1.9.0
#1 0.625 a5592eab7a57895e8d385394ff12241bc65ecd50       refs/tags/v1.9.0
#1 0.051 Initialized empty Git repository in /var/lib/desktop-containerd/daemon/io.containerd.snapshotter.v1.overlayfs/snapshots/23414/fs/
#1 0.699 From https://github.com/tonistiigi/xx
#1 0.699  * [new tag]         v1.9.0     -> v1.9.0
#1 0.703 a5592eab7a57895e8d385394ff12241bc65ecd50
#1 DONE 1.4s
{
  "group": {
    "default": {
      "targets": [
        "xx"
      ]
    }
  },
  "target": {
    "xx": {
      "context": "https://github.com/tonistiigi/xx.git#refs/tags/v1.9.0:src",
      "dockerfile": "Dockerfile",
      "tags": [
        "tonistiigi/xx:test"
      ],
      "target": "xx"
    }
  }
}
docker buildx bake "https://github.com/tonistiigi/xx.git?tag=v1.9.0" xx --print
#0 building with "default" instance using docker driver

#1 [internal] load git source https://github.com/tonistiigi/xx.git?tag=v1.9.0
#1 0.493 a5592eab7a57895e8d385394ff12241bc65ecd50       refs/tags/v1.9.0
#1 CACHED
{
  "group": {
    "default": {
      "targets": [
        "xx"
      ]
    }
  },
  "target": {
    "xx": {
      "context": "https://github.com/tonistiigi/xx.git?tag=v1.9.0#:src",
      "dockerfile": "Dockerfile",
      "tags": [
        "tonistiigi/xx:test"
      ],
      "target": "xx"
    }
  }
}
$ docker buildx bake "https://github.com/crazy-max/buildx-buildkit-tests.git#:buildx-3682" --print
#0 building with "default" instance using docker driver

#1 [internal] load git source https://github.com/crazy-max/buildx-buildkit-tests.git#:buildx-3682
#1 0.501 ref: refs/heads/main   HEAD
#1 0.501 848d0e37436a9228dede5abd71f447d63ec380c9       HEAD
#1 0.881 848d0e37436a9228dede5abd71f447d63ec380c9       refs/heads/main
#1 0.051 Initialized empty Git repository in /var/lib/desktop-containerd/daemon/io.containerd.snapshotter.v1.overlayfs/snapshots/23416/fs/
#1 0.389 ref: refs/heads/main   HEAD
#1 0.389 848d0e37436a9228dede5abd71f447d63ec380c9       HEAD
#1 0.940 From https://github.com/crazy-max/buildx-buildkit-tests
#1 0.940  * [new branch]      main       -> main
#1 0.941  * [new branch]      main       -> origin/main
#1 0.944 848d0e37436a9228dede5abd71f447d63ec380c9
#1 DONE 2.0s
{
  "group": {
    "default": {
      "targets": [
        "default"
      ]
    }
  },
  "target": {
    "default": {
      "context": "https://github.com/crazy-max/buildx-buildkit-tests.git#:buildx-3682/src",
      "dockerfile": "Dockerfile"
    }
  }
}
$ docker buildx bake "https://github.com/crazy-max/buildx-buildkit-tests.git?subdir=buildx-3682" --print
#0 building with "default" instance using docker driver

#1 [internal] load git source https://github.com/crazy-max/buildx-buildkit-tests.git?subdir=buildx-3682
#1 0.391 ref: refs/heads/main   HEAD
#1 0.391 848d0e37436a9228dede5abd71f447d63ec380c9       HEAD
#1 0.768 848d0e37436a9228dede5abd71f447d63ec380c9       refs/heads/main
#1 CACHED
{
  "group": {
    "default": {
      "targets": [
        "default"
      ]
    }
  },
  "target": {
    "default": {
      "context": "https://github.com/crazy-max/buildx-buildkit-tests.git?subdir=buildx-3682%2Fsrc",
      "dockerfile": "Dockerfile"
    }
  }
}

@crazy-max crazy-max requested a review from tonistiigi March 3, 2026 09:09
@crazy-max crazy-max added this to the v0.32.0 milestone Mar 3, 2026
@crazy-max crazy-max marked this pull request as ready for review March 3, 2026 09:09
bake/bake.go Outdated

// keep query string and transport style untouched nad only append/adjust
// fragment subdir
if !strings.Contains(remoteURL, "#") && parsed.SubDir != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be subdir != "" ?

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
@crazy-max crazy-max force-pushed the bake-print-subdir branch from ba9b598 to 50fa13d Compare March 3, 2026 16:47
@crazy-max crazy-max requested a review from tonistiigi March 3, 2026 16:48
@tonistiigi tonistiigi merged commit 75c53e3 into docker:master Mar 3, 2026
159 checks passed
@crazy-max crazy-max deleted the bake-print-subdir branch March 3, 2026 17:34
@tonistiigi tonistiigi mentioned this pull request Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants