Skip to content

Commit c963931

Browse files
tonistiigicrazy-max
authored andcommitted
git querystring frontend capability detection
Signed-off-by: Tonis Tiigi <[email protected]>
1 parent 99320bf commit c963931

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

build/opt.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"github.com/moby/buildkit/solver/pb"
3939
"github.com/moby/buildkit/util/apicaps"
4040
"github.com/moby/buildkit/util/entitlements"
41+
"github.com/moby/buildkit/util/gitutil"
4142
"github.com/opencontainers/go-digest"
4243
"github.com/pkg/errors"
4344
"github.com/tonistiigi/fsutil"
@@ -404,6 +405,7 @@ func loadInputs(ctx context.Context, d *driver.DriverHandle, inp *Inputs, pw pro
404405
dockerfileName = inp.DockerfilePath
405406
dockerfileSrcName = inp.DockerfilePath
406407
toRemove []string
408+
caps = map[string]struct{}{}
407409
)
408410

409411
switch {
@@ -469,6 +471,12 @@ func loadInputs(ctx context.Context, d *driver.DriverHandle, inp *Inputs, pw pro
469471
target.FrontendAttrs["dockerfilekey"] = "dockerfile"
470472
}
471473
target.FrontendAttrs["context"] = inp.ContextPath
474+
475+
gitRef, err := gitutil.ParseURL(inp.ContextPath)
476+
if err == nil && len(gitRef.Query) > 0 {
477+
caps["moby.buildkit.frontend.gitquerystring"] = struct{}{}
478+
}
479+
472480
default:
473481
return nil, errors.Errorf("unable to prepare context: path %q not found", inp.ContextPath)
474482
}
@@ -516,7 +524,7 @@ func loadInputs(ctx context.Context, d *driver.DriverHandle, inp *Inputs, pw pro
516524
target.FrontendAttrs["filename"] = dockerfileName
517525

518526
for k, v := range inp.NamedContexts {
519-
target.FrontendAttrs["frontend.caps"] = "moby.buildkit.frontend.contexts+forward"
527+
caps["moby.buildkit.frontend.contexts+forward"] = struct{}{}
520528
if v.State != nil {
521529
target.FrontendAttrs["context:"+k] = "input:" + k
522530
if target.FrontendInputs == nil {
@@ -528,6 +536,12 @@ func loadInputs(ctx context.Context, d *driver.DriverHandle, inp *Inputs, pw pro
528536

529537
if IsRemoteURL(v.Path) || strings.HasPrefix(v.Path, "docker-image://") || strings.HasPrefix(v.Path, "target:") {
530538
target.FrontendAttrs["context:"+k] = v.Path
539+
gitRef, err := gitutil.ParseURL(v.Path)
540+
if err == nil && len(gitRef.Query) > 0 {
541+
if _, ok := caps["moby.buildkit.frontend.gitquerystring"]; !ok {
542+
caps["moby.buildkit.frontend.gitquerystring+forward"] = struct{}{}
543+
}
544+
}
531545
continue
532546
}
533547

@@ -557,6 +571,7 @@ func loadInputs(ctx context.Context, d *driver.DriverHandle, inp *Inputs, pw pro
557571
target.FrontendAttrs["context:"+k] = "oci-layout://" + storeName + ":" + tag + "@" + dig
558572
continue
559573
}
574+
560575
st, err := os.Stat(v.Path)
561576
if err != nil {
562577
return nil, errors.Wrapf(err, "failed to get build context %v", k)
@@ -580,6 +595,12 @@ func loadInputs(ctx context.Context, d *driver.DriverHandle, inp *Inputs, pw pro
580595
}
581596
}
582597

598+
if len(caps) > 0 {
599+
keys := slices.Collect(maps.Keys(caps))
600+
slices.Sort(keys)
601+
target.FrontendAttrs["frontend.caps"] = strings.Join(keys, ",")
602+
}
603+
583604
inp.DockerfileMappingSrc = dockerfileSrcName
584605
inp.DockerfileMappingDst = dockerfileName
585606
return release, nil

commands/build.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,11 @@ func wrapBuildError(err error, bake bool) error {
692692
msg += " Named contexts are supported since Dockerfile v1.4. Use #syntax directive in Dockerfile or update to latest BuildKit."
693693
return &wrapped{err, msg}
694694
}
695+
if st.Code() == codes.Unimplemented && strings.Contains(st.Message(), "unsupported frontend capability moby.buildkit.frontend.gitquerystring") {
696+
msg := "current frontend does not support Git URLs with query string components."
697+
msg += " Git URLs with query string are supported since Dockerfile v1.18 and BuildKit v0.24. Use BUILDKIT_SYNTAX build-arg, #syntax directive in Dockerfile or update to latest BuildKit."
698+
return &wrapped{err, msg}
699+
}
695700
}
696701
return err
697702
}

0 commit comments

Comments
 (0)