diff --git a/bake/bake.go b/bake/bake.go index 5cb6c756..df9c559e 100644 --- a/bake/bake.go +++ b/bake/bake.go @@ -4,6 +4,7 @@ import ( "context" "encoding" "io" + "maps" "os" "path" "path/filepath" @@ -1104,9 +1105,7 @@ func (t *Target) GetEvalContexts(ectx *hcl.EvalContext, block *hcl.Block, loadDe e2 := ectx.NewChild() e2.Variables = make(map[string]cty.Value) if e != ectx { - for k, v := range e.Variables { - e2.Variables[k] = v - } + maps.Copy(e2.Variables, e.Variables) } e2.Variables[k] = v ectxs2 = append(ectxs2, e2) diff --git a/bake/compose.go b/bake/compose.go index 84a6e989..ccf8098c 100644 --- a/bake/compose.go +++ b/bake/compose.go @@ -3,6 +3,7 @@ package bake import ( "context" "fmt" + "maps" "os" "path/filepath" "slices" @@ -91,9 +92,7 @@ func ParseCompose(cfgs []composetypes.ConfigFile, envs map[string]string) (*Conf var additionalContexts map[string]string if s.Build.AdditionalContexts != nil { additionalContexts = map[string]string{} - for k, v := range s.Build.AdditionalContexts { - additionalContexts[k] = v - } + maps.Copy(additionalContexts, s.Build.AdditionalContexts) } var shmSize *string diff --git a/build/build.go b/build/build.go index 96f85069..95d658b3 100644 --- a/build/build.go +++ b/build/build.go @@ -8,6 +8,7 @@ import ( "encoding/json" "fmt" "io" + "maps" "os" "slices" "strconv" @@ -431,9 +432,7 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opts map[ FrontendInputs: frontendInputs, FrontendOpt: make(map[string]string), } - for k, v := range so.FrontendAttrs { - req.FrontendOpt[k] = v - } + maps.Copy(req.FrontendOpt, so.FrontendAttrs) so.Frontend = "" so.FrontendInputs = nil diff --git a/build/git.go b/build/git.go index 0b7aba10..4672860c 100644 --- a/build/git.go +++ b/build/git.go @@ -2,6 +2,7 @@ package build import ( "context" + "maps" "os" "path" "path/filepath" @@ -127,9 +128,7 @@ func getGitAttributes(ctx context.Context, contextPath, dockerfilePath string) ( if so.FrontendAttrs == nil { so.FrontendAttrs = make(map[string]string) } - for k, v := range res { - so.FrontendAttrs[k] = v - } + maps.Copy(so.FrontendAttrs, res) if !setGitInfo || root == "" { return diff --git a/build/provenance.go b/build/provenance.go index 5fd8d08c..b6cca56f 100644 --- a/build/provenance.go +++ b/build/provenance.go @@ -5,6 +5,7 @@ import ( "encoding/base64" "encoding/json" "io" + "maps" "strings" "sync" @@ -40,9 +41,7 @@ func setRecordProvenance(ctx context.Context, c *client.Client, sr *client.Solve if err != nil { return err } - for k, v := range res { - sr.ExporterResponse[k] = v - } + maps.Copy(sr.ExporterResponse, res) return nil }) } diff --git a/commands/ls.go b/commands/ls.go index ffd4c10d..8c247679 100644 --- a/commands/ls.go +++ b/commands/ls.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "maps" "sort" "strings" "time" @@ -409,9 +410,7 @@ func truncPlatforms(pfs []string, max int) truncatedPlatforms { left[ppf] = append(left[ppf], pf) } } - for k, v := range left { - res[k] = v - } + maps.Copy(res, left) return truncatedPlatforms{ res: res, input: pfs, diff --git a/controller/pb/cache.go b/controller/pb/cache.go index 4b7c2b75..f363a419 100644 --- a/controller/pb/cache.go +++ b/controller/pb/cache.go @@ -1,6 +1,10 @@ package pb -import "github.com/moby/buildkit/client" +import ( + "maps" + + "github.com/moby/buildkit/client" +) func CreateCaches(entries []*CacheOptionsEntry) []client.CacheOptionsEntry { var outs []client.CacheOptionsEntry @@ -12,9 +16,7 @@ func CreateCaches(entries []*CacheOptionsEntry) []client.CacheOptionsEntry { Type: entry.Type, Attrs: map[string]string{}, } - for k, v := range entry.Attrs { - out.Attrs[k] = v - } + maps.Copy(out.Attrs, entry.Attrs) outs = append(outs, out) } return outs diff --git a/controller/pb/export.go b/controller/pb/export.go index 8df341b3..c7eef8c9 100644 --- a/controller/pb/export.go +++ b/controller/pb/export.go @@ -2,6 +2,7 @@ package pb import ( "io" + "maps" "os" "strconv" @@ -26,9 +27,7 @@ func CreateExports(entries []*ExportEntry) ([]client.ExportEntry, []string, erro Type: entry.Type, Attrs: map[string]string{}, } - for k, v := range entry.Attrs { - out.Attrs[k] = v - } + maps.Copy(out.Attrs, entry.Attrs) supportFile := false supportDir := false diff --git a/go.mod b/go.mod index aa40920a..3eb47868 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,6 @@ module github.com/docker/buildx -go 1.23 - -toolchain go1.23.7 +go 1.23.0 require ( github.com/Masterminds/semver/v3 v3.2.1 diff --git a/store/nodegroup.go b/store/nodegroup.go index 06ca070e..9d986d17 100644 --- a/store/nodegroup.go +++ b/store/nodegroup.go @@ -2,6 +2,7 @@ package store import ( "fmt" + "maps" "slices" "time" @@ -93,9 +94,7 @@ func (ng *NodeGroup) Update(name, endpoint string, platforms []string, endpoints needsRestart = true } if buildkitdConfigFile != "" { - for k, v := range files { - n.Files[k] = v - } + maps.Copy(n.Files, files) needsRestart = true } if needsRestart { @@ -147,9 +146,7 @@ func (n *Node) Copy() *Node { buildkitdFlags := []string{} copy(buildkitdFlags, n.BuildkitdFlags) driverOpts := map[string]string{} - for k, v := range n.DriverOpts { - driverOpts[k] = v - } + maps.Copy(driverOpts, n.DriverOpts) files := map[string][]byte{} for k, v := range n.Files { vv := []byte{} diff --git a/util/imagetools/create.go b/util/imagetools/create.go index 6fdcac96..9b1ca6b4 100644 --- a/util/imagetools/create.go +++ b/util/imagetools/create.go @@ -107,9 +107,7 @@ func (r *Resolver) Combine(ctx context.Context, srcs []*Source, ann map[exptypes if old.Annotations == nil { old.Annotations = map[string]string{} } - for k, v := range d.Annotations { - old.Annotations[k] = v - } + maps.Copy(old.Annotations, d.Annotations) newDescs[idx] = old } else { m[d.Digest] = len(newDescs) diff --git a/util/imagetools/loader.go b/util/imagetools/loader.go index 457e684e..eaba4d11 100644 --- a/util/imagetools/loader.go +++ b/util/imagetools/loader.go @@ -6,6 +6,7 @@ import ( "context" "encoding/base64" "encoding/json" + "maps" "regexp" "sort" "strings" @@ -126,13 +127,9 @@ func (l *loader) Load(ctx context.Context, ref string) (*result, error) { } var a asset - annotations := make(map[string]string, len(mfst.manifest.Annotations)+len(mfst.desc.Annotations)) - for k, v := range mfst.desc.Annotations { - annotations[k] = v - } - for k, v := range mfst.manifest.Annotations { - annotations[k] = v - } + annotations := map[string]string{} + maps.Copy(annotations, mfst.desc.Annotations) + maps.Copy(annotations, mfst.manifest.Annotations) if err := l.scanConfig(ctx, fetcher, mfst.manifest.Config, &a); err != nil { return nil, err