@@ -698,30 +698,30 @@ type Target struct {
698698 // Inherits is the only field that cannot be overridden with --set
699699 Inherits []string `json:"inherits,omitempty" hcl:"inherits,optional" cty:"inherits"`
700700
701- Annotations []string `json:"annotations,omitempty" hcl:"annotations,optional" cty:"annotations"`
702- Attest []string `json:"attest,omitempty" hcl:"attest,optional" cty:"attest"`
703- Context * string `json:"context,omitempty" hcl:"context,optional" cty:"context"`
704- Contexts map [string ]string `json:"contexts,omitempty" hcl:"contexts,optional" cty:"contexts"`
705- Dockerfile * string `json:"dockerfile,omitempty" hcl:"dockerfile,optional" cty:"dockerfile"`
706- DockerfileInline * string `json:"dockerfile-inline,omitempty" hcl:"dockerfile-inline,optional" cty:"dockerfile-inline"`
707- Args map [string ]* string `json:"args,omitempty" hcl:"args,optional" cty:"args"`
708- Labels map [string ]* string `json:"labels,omitempty" hcl:"labels,optional" cty:"labels"`
709- Tags []string `json:"tags,omitempty" hcl:"tags,optional" cty:"tags"`
710- CacheFrom [] * buildflags.CacheOptionsEntry `json:"cache-from,omitempty" hcl:"cache-from,optional" cty:"cache-from"`
711- CacheTo [] * buildflags.CacheOptionsEntry `json:"cache-to,omitempty" hcl:"cache-to,optional" cty:"cache-to"`
712- Target * string `json:"target,omitempty" hcl:"target,optional" cty:"target"`
713- Secrets []* buildflags.Secret `json:"secret,omitempty" hcl:"secret,optional" cty:"secret"`
714- SSH []* buildflags.SSH `json:"ssh,omitempty" hcl:"ssh,optional" cty:"ssh"`
715- Platforms []string `json:"platforms,omitempty" hcl:"platforms,optional" cty:"platforms"`
716- Outputs []* buildflags.ExportEntry `json:"output,omitempty" hcl:"output,optional" cty:"output"`
717- Pull * bool `json:"pull,omitempty" hcl:"pull,optional" cty:"pull"`
718- NoCache * bool `json:"no-cache,omitempty" hcl:"no-cache,optional" cty:"no-cache"`
719- NetworkMode * string `json:"network,omitempty" hcl:"network,optional" cty:"network"`
720- NoCacheFilter []string `json:"no-cache-filter,omitempty" hcl:"no-cache-filter,optional" cty:"no-cache-filter"`
721- ShmSize * string `json:"shm-size,omitempty" hcl:"shm-size,optional"`
722- Ulimits []string `json:"ulimits,omitempty" hcl:"ulimits,optional"`
723- Call * string `json:"call,omitempty" hcl:"call,optional" cty:"call"`
724- Entitlements []string `json:"entitlements,omitempty" hcl:"entitlements,optional" cty:"entitlements"`
701+ Annotations []string `json:"annotations,omitempty" hcl:"annotations,optional" cty:"annotations"`
702+ Attest []string `json:"attest,omitempty" hcl:"attest,optional" cty:"attest"`
703+ Context * string `json:"context,omitempty" hcl:"context,optional" cty:"context"`
704+ Contexts map [string ]string `json:"contexts,omitempty" hcl:"contexts,optional" cty:"contexts"`
705+ Dockerfile * string `json:"dockerfile,omitempty" hcl:"dockerfile,optional" cty:"dockerfile"`
706+ DockerfileInline * string `json:"dockerfile-inline,omitempty" hcl:"dockerfile-inline,optional" cty:"dockerfile-inline"`
707+ Args map [string ]* string `json:"args,omitempty" hcl:"args,optional" cty:"args"`
708+ Labels map [string ]* string `json:"labels,omitempty" hcl:"labels,optional" cty:"labels"`
709+ Tags []string `json:"tags,omitempty" hcl:"tags,optional" cty:"tags"`
710+ CacheFrom * buildflags.CacheOptions `json:"cache-from,omitempty" hcl:"cache-from,optional" cty:"cache-from"`
711+ CacheTo * buildflags.CacheOptions `json:"cache-to,omitempty" hcl:"cache-to,optional" cty:"cache-to"`
712+ Target * string `json:"target,omitempty" hcl:"target,optional" cty:"target"`
713+ Secrets []* buildflags.Secret `json:"secret,omitempty" hcl:"secret,optional" cty:"secret"`
714+ SSH []* buildflags.SSH `json:"ssh,omitempty" hcl:"ssh,optional" cty:"ssh"`
715+ Platforms []string `json:"platforms,omitempty" hcl:"platforms,optional" cty:"platforms"`
716+ Outputs []* buildflags.ExportEntry `json:"output,omitempty" hcl:"output,optional" cty:"output"`
717+ Pull * bool `json:"pull,omitempty" hcl:"pull,optional" cty:"pull"`
718+ NoCache * bool `json:"no-cache,omitempty" hcl:"no-cache,optional" cty:"no-cache"`
719+ NetworkMode * string `json:"network,omitempty" hcl:"network,optional" cty:"network"`
720+ NoCacheFilter []string `json:"no-cache-filter,omitempty" hcl:"no-cache-filter,optional" cty:"no-cache-filter"`
721+ ShmSize * string `json:"shm-size,omitempty" hcl:"shm-size,optional"`
722+ Ulimits []string `json:"ulimits,omitempty" hcl:"ulimits,optional"`
723+ Call * string `json:"call,omitempty" hcl:"call,optional" cty:"call"`
724+ Entitlements []string `json:"entitlements,omitempty" hcl:"entitlements,optional" cty:"entitlements"`
725725 // IMPORTANT: if you add more fields here, do not forget to update newOverrides/AddOverrides and docs/bake-reference.md.
726726
727727 // linked is a private field to mark a target used as a linked one
@@ -742,8 +742,12 @@ func (t *Target) normalize() {
742742 t .Secrets = removeDupes (t .Secrets )
743743 t .SSH = removeDupes (t .SSH )
744744 t .Platforms = removeDupesStr (t .Platforms )
745- t .CacheFrom = removeDupes (t .CacheFrom )
746- t .CacheTo = removeDupes (t .CacheTo )
745+ if t .CacheFrom != nil {
746+ t .CacheFrom .Normalize ()
747+ }
748+ if t .CacheTo != nil {
749+ t .CacheTo .Normalize ()
750+ }
747751 t .Outputs = removeDupes (t .Outputs )
748752 t .NoCacheFilter = removeDupesStr (t .NoCacheFilter )
749753 t .Ulimits = removeDupesStr (t .Ulimits )
@@ -824,7 +828,7 @@ func (t *Target) Merge(t2 *Target) {
824828 t .Platforms = t2 .Platforms
825829 }
826830 if t2 .CacheFrom != nil { // merge
827- t .CacheFrom = append ( t .CacheFrom , t2 .CacheFrom ... )
831+ t .CacheFrom = t .CacheFrom . Merge ( t2 .CacheFrom )
828832 }
829833 if t2 .CacheTo != nil { // no merge
830834 t .CacheTo = t2 .CacheTo
@@ -1338,17 +1342,12 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
13381342 }
13391343 }
13401344
1341- cacheImports := make ([]* controllerapi.CacheOptionsEntry , len (t .CacheFrom ))
1342- for i , ci := range t .CacheFrom {
1343- cacheImports [i ] = ci .ToPB ()
1345+ if t .CacheFrom != nil {
1346+ bo .CacheFrom = controllerapi .CreateCaches (t .CacheFrom .ToPB ())
13441347 }
1345- bo .CacheFrom = controllerapi .CreateCaches (cacheImports )
1346-
1347- cacheExports := make ([]* controllerapi.CacheOptionsEntry , len (t .CacheTo ))
1348- for i , ce := range t .CacheTo {
1349- cacheExports [i ] = ce .ToPB ()
1348+ if t .CacheTo != nil {
1349+ bo .CacheTo = controllerapi .CreateCaches (t .CacheTo .ToPB ())
13501350 }
1351- bo .CacheTo = controllerapi .CreateCaches (cacheExports )
13521351
13531352 outputs := make ([]* controllerapi.ExportEntry , len (t .Outputs ))
13541353 for i , output := range t .Outputs {
@@ -1591,9 +1590,13 @@ func parseArrValue[T any, PT arrValue[T]](s []string) ([]*T, error) {
15911590 return outputs , nil
15921591}
15931592
1594- func parseCacheArrValues (s []string ) ([] * buildflags.CacheOptionsEntry , error ) {
1593+ func parseCacheArrValues (s []string ) (* buildflags.CacheOptions , error ) {
15951594 outs := make ([]* buildflags.CacheOptionsEntry , 0 , len (s ))
15961595 for _ , in := range s {
1596+ if in == "" {
1597+ continue
1598+ }
1599+
15971600 if ! strings .Contains (in , "=" ) {
15981601 // This is ref only format. Each field in the CSV is its own entry.
15991602 fields , err := csvvalue .Fields (in , nil )
@@ -1618,5 +1621,9 @@ func parseCacheArrValues(s []string) ([]*buildflags.CacheOptionsEntry, error) {
16181621 }
16191622 outs = append (outs , & out )
16201623 }
1621- return outs , nil
1624+
1625+ if len (outs ) == 0 {
1626+ return nil , nil
1627+ }
1628+ return & buildflags.CacheOptions {Entries : outs }, nil
16221629}
0 commit comments