@@ -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
0 commit comments