@@ -588,7 +588,7 @@ func (c Config) newOverrides(v []string) (map[string]map[string]Override, error)
588588 // IMPORTANT: if you add more fields here, do not forget to update
589589 // docs/reference/buildx_bake.md (--set) and https://docs.docker.com/build/bake/overrides/
590590 switch keys [1 ] {
591- case "output" , "cache-to" , "cache-from" , "tags" , "platform" , "secrets" , "ssh" , "attest" , "entitlements" , "network" , "annotations" :
591+ case "output" , "cache-to" , "cache-from" , "tags" , "platform" , "secrets" , "ssh" , "attest" , "entitlements" , "network" , "annotations" , "policy" :
592592 if len (parts ) == 2 {
593593 override .Append = appendTo
594594 override .ArrValue = append (override .ArrValue , parts [1 ])
@@ -732,31 +732,32 @@ type Target struct {
732732 // Inherits is the only field that cannot be overridden with --set
733733 Inherits []string `json:"inherits,omitempty" hcl:"inherits,optional" cty:"inherits"`
734734
735- Annotations []string `json:"annotations,omitempty" hcl:"annotations,optional" cty:"annotations"`
736- Attest buildflags.Attests `json:"attest,omitempty" hcl:"attest,optional" cty:"attest"`
737- Context * string `json:"context,omitempty" hcl:"context,optional" cty:"context"`
738- Contexts map [string ]string `json:"contexts,omitempty" hcl:"contexts,optional" cty:"contexts"`
739- Dockerfile * string `json:"dockerfile,omitempty" hcl:"dockerfile,optional" cty:"dockerfile"`
740- DockerfileInline * string `json:"dockerfile-inline,omitempty" hcl:"dockerfile-inline,optional" cty:"dockerfile-inline"`
741- Args map [string ]* string `json:"args,omitempty" hcl:"args,optional" cty:"args"`
742- Labels map [string ]* string `json:"labels,omitempty" hcl:"labels,optional" cty:"labels"`
743- Tags []string `json:"tags,omitempty" hcl:"tags,optional" cty:"tags"`
744- CacheFrom buildflags.CacheOptions `json:"cache-from,omitempty" hcl:"cache-from,optional" cty:"cache-from"`
745- CacheTo buildflags.CacheOptions `json:"cache-to,omitempty" hcl:"cache-to,optional" cty:"cache-to"`
746- Target * string `json:"target,omitempty" hcl:"target,optional" cty:"target"`
747- Secrets buildflags.Secrets `json:"secret,omitempty" hcl:"secret,optional" cty:"secret"`
748- SSH buildflags.SSHKeys `json:"ssh,omitempty" hcl:"ssh,optional" cty:"ssh"`
749- Platforms []string `json:"platforms,omitempty" hcl:"platforms,optional" cty:"platforms"`
750- Outputs buildflags.Exports `json:"output,omitempty" hcl:"output,optional" cty:"output"`
751- Pull * bool `json:"pull,omitempty" hcl:"pull,optional" cty:"pull"`
752- NoCache * bool `json:"no-cache,omitempty" hcl:"no-cache,optional" cty:"no-cache"`
753- NetworkMode * string `json:"network,omitempty" hcl:"network,optional" cty:"network"`
754- NoCacheFilter []string `json:"no-cache-filter,omitempty" hcl:"no-cache-filter,optional" cty:"no-cache-filter"`
755- ShmSize * string `json:"shm-size,omitempty" hcl:"shm-size,optional" cty:"shm-size"`
756- Ulimits []string `json:"ulimits,omitempty" hcl:"ulimits,optional" cty:"ulimits"`
757- Call * string `json:"call,omitempty" hcl:"call,optional" cty:"call"`
758- Entitlements []string `json:"entitlements,omitempty" hcl:"entitlements,optional" cty:"entitlements"`
759- ExtraHosts map [string ]* string `json:"extra-hosts,omitempty" hcl:"extra-hosts,optional" cty:"extra-hosts"`
735+ Annotations []string `json:"annotations,omitempty" hcl:"annotations,optional" cty:"annotations"`
736+ Attest buildflags.Attests `json:"attest,omitempty" hcl:"attest,optional" cty:"attest"`
737+ Context * string `json:"context,omitempty" hcl:"context,optional" cty:"context"`
738+ Contexts map [string ]string `json:"contexts,omitempty" hcl:"contexts,optional" cty:"contexts"`
739+ Dockerfile * string `json:"dockerfile,omitempty" hcl:"dockerfile,optional" cty:"dockerfile"`
740+ DockerfileInline * string `json:"dockerfile-inline,omitempty" hcl:"dockerfile-inline,optional" cty:"dockerfile-inline"`
741+ Args map [string ]* string `json:"args,omitempty" hcl:"args,optional" cty:"args"`
742+ Labels map [string ]* string `json:"labels,omitempty" hcl:"labels,optional" cty:"labels"`
743+ Tags []string `json:"tags,omitempty" hcl:"tags,optional" cty:"tags"`
744+ CacheFrom buildflags.CacheOptions `json:"cache-from,omitempty" hcl:"cache-from,optional" cty:"cache-from"`
745+ CacheTo buildflags.CacheOptions `json:"cache-to,omitempty" hcl:"cache-to,optional" cty:"cache-to"`
746+ Target * string `json:"target,omitempty" hcl:"target,optional" cty:"target"`
747+ Secrets buildflags.Secrets `json:"secret,omitempty" hcl:"secret,optional" cty:"secret"`
748+ SSH buildflags.SSHKeys `json:"ssh,omitempty" hcl:"ssh,optional" cty:"ssh"`
749+ Platforms []string `json:"platforms,omitempty" hcl:"platforms,optional" cty:"platforms"`
750+ Outputs buildflags.Exports `json:"output,omitempty" hcl:"output,optional" cty:"output"`
751+ Pull * bool `json:"pull,omitempty" hcl:"pull,optional" cty:"pull"`
752+ NoCache * bool `json:"no-cache,omitempty" hcl:"no-cache,optional" cty:"no-cache"`
753+ NetworkMode * string `json:"network,omitempty" hcl:"network,optional" cty:"network"`
754+ NoCacheFilter []string `json:"no-cache-filter,omitempty" hcl:"no-cache-filter,optional" cty:"no-cache-filter"`
755+ ShmSize * string `json:"shm-size,omitempty" hcl:"shm-size,optional" cty:"shm-size"`
756+ Ulimits []string `json:"ulimits,omitempty" hcl:"ulimits,optional" cty:"ulimits"`
757+ Call * string `json:"call,omitempty" hcl:"call,optional" cty:"call"`
758+ Entitlements []string `json:"entitlements,omitempty" hcl:"entitlements,optional" cty:"entitlements"`
759+ ExtraHosts map [string ]* string `json:"extra-hosts,omitempty" hcl:"extra-hosts,optional" cty:"extra-hosts"`
760+ Policy buildflags.PolicyConfigs `json:"policy,omitempty" hcl:"policy,optional" cty:"policy"`
760761 // IMPORTANT: if you add more fields here, do not forget to update newOverrides/AddOverrides and docs/bake-reference.md.
761762
762763 // linked is a private field to mark a target used as a linked one
@@ -891,6 +892,9 @@ func (t *Target) Merge(t2 *Target) {
891892 if t2 .Attest != nil { // merge
892893 t .Attest = t .Attest .Merge (t2 .Attest )
893894 }
895+ if t2 .Policy != nil { // merge
896+ t .Policy = append (t .Policy , t2 .Policy ... )
897+ }
894898 if t2 .Secrets != nil { // merge
895899 t .Secrets = t .Secrets .Merge (t2 .Secrets )
896900 }
@@ -986,6 +990,17 @@ func (t *Target) AddOverrides(overrides map[string]Override, ent *EntitlementCon
986990 } else {
987991 t .Tags = o .ArrValue
988992 }
993+ case "policy" :
994+ if ! o .Append {
995+ t .Policy = nil
996+ }
997+ for _ , v := range o .ArrValue {
998+ cfg , err := buildflags .ParsePolicyConfig (v )
999+ if err != nil {
1000+ return err
1001+ }
1002+ t .Policy = append (t .Policy , cfg )
1003+ }
9891004 case "cache-from" :
9901005 cacheFrom , err := buildflags .ParseCacheEntry (o .ArrValue )
9911006 if err != nil {
@@ -1548,6 +1563,8 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
15481563
15491564 bo .Attests = t .Attest .ToMap ()
15501565
1566+ bo .Policy = []buildflags.PolicyConfig (t .Policy )
1567+
15511568 bo .SourcePolicy , err = build .ReadSourcePolicy ()
15521569 if err != nil {
15531570 return nil , err
0 commit comments