From 7b9ea84c692e1dc83a64a8ab9834f1e0a8898327 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Fri, 13 Mar 2026 14:57:05 -0700 Subject: [PATCH] Update `github.com/go-git/go-git/v5` Also: - update Go to 1.24 - update `actions.checkout` to `v6` - apply `go fix` changes - update `pault.ag/go/debian` to `v0.19.0` --- .github/workflows/ci.yml | 8 ++--- Dockerfile | 4 +-- Dockerfile.release | 4 +-- Dockerfile.test | 2 +- cmd/bashbrew/cmd-cat.go | 2 +- cmd/bashbrew/cmd-children.go | 3 +- cmd/bashbrew/cmd-put-shared.go | 25 ++++++++-------- cmd/bashbrew/config.go | 6 ++-- cmd/bashbrew/dedupe-slice.go | 11 ++----- cmd/bashbrew/oci-builder.go | 6 ++-- go.mod | 22 +++++++------- go.sum | 45 +++++++++++++---------------- manifest/rfc2822.go | 41 +++++++++----------------- pkg/dockerfile/parse_test.go | 1 - pkg/gitfs/fs.go | 2 +- pkg/templatelib/lib.go | 28 +++++++++--------- pkg/templatelib/lib_example_test.go | 6 ++-- registry/registry.go | 2 +- 18 files changed, 96 insertions(+), 122 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3a3ae5ac..99d8797c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: name: Build ${{ matrix.os }} runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - uses: ./ # test our "action.yml" 👀 - name: Smoke Test run: | @@ -41,7 +41,7 @@ jobs: name: Go Test runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Go Test run: | docker build --pull --file Dockerfile.test --tag test . @@ -65,7 +65,7 @@ jobs: name: Test Dockerfile runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Build Dockerfile run: | docker build --pull . @@ -73,7 +73,7 @@ jobs: name: Test Dockerfile.release runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Build Dockerfile.release run: | docker build --pull --file Dockerfile.release . diff --git a/Dockerfile b/Dockerfile index 06ede09b..6e9de476 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.23-bookworm AS build +FROM golang:1.24-trixie AS build SHELL ["bash", "-Eeuo", "pipefail", "-xc"] @@ -20,7 +20,7 @@ RUN apt-get update; \ apt-get install -y --no-install-recommends \ git \ ; \ - rm -rf /var/lib/apt/lists/* + apt-get dist-clean COPY --from=build /bashbrew /usr/local/bin/ RUN bashbrew --version diff --git a/Dockerfile.release b/Dockerfile.release index 7eb9faaf..e0fb0942 100644 --- a/Dockerfile.release +++ b/Dockerfile.release @@ -1,4 +1,4 @@ -FROM golang:1.23-bookworm +FROM golang:1.24-trixie SHELL ["bash", "-Eeuo", "pipefail", "-xc"] @@ -8,7 +8,7 @@ RUN apt-get update; \ gnupg \ wget \ ; \ - rm -rf /var/lib/apt/lists/* + apt-get dist-clean WORKDIR /usr/src/bashbrew ENV CGO_ENABLED 0 diff --git a/Dockerfile.test b/Dockerfile.test index 8c40927a..2823659d 100644 --- a/Dockerfile.test +++ b/Dockerfile.test @@ -1,4 +1,4 @@ -FROM golang:1.23-bookworm +FROM golang:1.24-trixie SHELL ["bash", "-Eeuo", "pipefail", "-xc"] diff --git a/cmd/bashbrew/cmd-cat.go b/cmd/bashbrew/cmd-cat.go index 48ee130f..3cc1f929 100644 --- a/cmd/bashbrew/cmd-cat.go +++ b/cmd/bashbrew/cmd-cat.go @@ -83,7 +83,7 @@ func cmdCat(c *cli.Context) error { "archNamespace": func(arch string) string { return archNamespaces[arch] }, - "archFilter": func(arch string, entriesArg ...interface{}) []manifest.Manifest2822Entry { + "archFilter": func(arch string, entriesArg ...any) []manifest.Manifest2822Entry { if len(entriesArg) < 1 { panic(`"archFilter" requires at least one argument`) } diff --git a/cmd/bashbrew/cmd-children.go b/cmd/bashbrew/cmd-children.go index 937e6548..2da21492 100644 --- a/cmd/bashbrew/cmd-children.go +++ b/cmd/bashbrew/cmd-children.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path" + "slices" "strings" "github.com/urfave/cli" @@ -152,7 +153,7 @@ func cmdChildren(c *cli.Context) error { for _, kid := range kids { supported := false for _, arch := range arches.slice(kid) { - if sliceHas[string](supportedArches, arch) { + if slices.Contains(supportedArches, arch) { supported = true break } diff --git a/cmd/bashbrew/cmd-put-shared.go b/cmd/bashbrew/cmd-put-shared.go index f231650f..190e2cdf 100644 --- a/cmd/bashbrew/cmd-put-shared.go +++ b/cmd/bashbrew/cmd-put-shared.go @@ -16,7 +16,7 @@ import ( var errPutShared404 = fmt.Errorf("nothing to push") func entriesToManifestToolYaml(singleArch bool, r Repo, entries ...*manifest.Manifest2822Entry) (string, []string, error) { - yaml := "" + var yaml strings.Builder remoteDigests := []string{} entryIdentifiers := []string{} for _, entry := range entries { @@ -52,33 +52,34 @@ func entriesToManifestToolYaml(singleArch bool, r Repo, entries ...*manifest.Man } remoteDigests = append(remoteDigests, archImageDigests...) - yaml += fmt.Sprintf(" - image: %s\n", archImage) - yaml += fmt.Sprintf(" platform:\n") - yaml += fmt.Sprintf(" os: %s\n", ociArch.OS) - yaml += fmt.Sprintf(" architecture: %s\n", ociArch.Architecture) + fmt.Fprintf(&yaml, " - image: %s\n", archImage) + fmt.Fprintf(&yaml, " platform:\n") + fmt.Fprintf(&yaml, " os: %s\n", ociArch.OS) + fmt.Fprintf(&yaml, " architecture: %s\n", ociArch.Architecture) if ociArch.Variant != "" { - yaml += fmt.Sprintf(" variant: %s\n", ociArch.Variant) + fmt.Fprintf(&yaml, " variant: %s\n", ociArch.Variant) } } } - if yaml == "" { + if yaml.Len() == 0 { // we're not even going to try pushing something, so let's inform the caller of that to skip the unnecessary call to "manifest-tool" return "", nil, errPutShared404 } - return "manifests:\n" + yaml, remoteDigests, nil + return "manifests:\n" + yaml.String(), remoteDigests, nil } func tagsToManifestToolYaml(repo string, tags ...string) string { - yaml := fmt.Sprintf("image: %s:%s\n", repo, tags[0]) + var yaml strings.Builder + fmt.Fprintf(&yaml, "image: %s:%s\n", repo, tags[0]) if len(tags) > 1 { - yaml += "tags:\n" + yaml.WriteString("tags:\n") for _, tag := range tags[1:] { - yaml += fmt.Sprintf(" - %s\n", tag) + fmt.Fprintf(&yaml, " - %s\n", tag) } } - return yaml + return yaml.String() } func cmdPutShared(c *cli.Context) error { diff --git a/cmd/bashbrew/config.go b/cmd/bashbrew/config.go index d35895fc..37ac5330 100644 --- a/cmd/bashbrew/config.go +++ b/cmd/bashbrew/config.go @@ -76,8 +76,8 @@ func (dst *FlagsConfigEntry) Apply(src FlagsConfigEntry) { } } -func (config FlagsConfigEntry) Vars() map[string]map[string]interface{} { - return map[string]map[string]interface{}{ +func (config FlagsConfigEntry) Vars() map[string]map[string]any { + return map[string]map[string]any{ "global": { "library": config.Library, "cache": config.Cache, @@ -160,7 +160,7 @@ func (config FlagsConfig) ApplyTo(cmd string, c *cli.Context) error { // https://github.com/urfave/cli/blob/73aa67b7a20db7514b1c086866469c49bc93a569/altsrc/flag.go#L237-L251 func isEnvVarSet(envVars string) bool { - for _, envVar := range strings.Split(envVars, ",") { + for envVar := range strings.SplitSeq(envVars, ",") { envVar = strings.TrimSpace(envVar) if envVal := os.Getenv(envVar); envVal != "" { // TODO: Can't use this for bools as diff --git a/cmd/bashbrew/dedupe-slice.go b/cmd/bashbrew/dedupe-slice.go index 63e55795..5b3c4cb7 100644 --- a/cmd/bashbrew/dedupe-slice.go +++ b/cmd/bashbrew/dedupe-slice.go @@ -1,20 +1,13 @@ package main -func sliceHas[T comparable](s []T, t T) bool { - for _, i := range s { - if i == t { - return true - } - } - return false -} +import "slices" type dedupeSlice[T comparable] struct { s []T } func (s *dedupeSlice[T]) add(i T) bool { - if sliceHas[T](s.s, i) { + if slices.Contains(s.s, i) { return false } s.s = append(s.s, i) diff --git a/cmd/bashbrew/oci-builder.go b/cmd/bashbrew/oci-builder.go index ea8d35ad..bf845472 100644 --- a/cmd/bashbrew/oci-builder.go +++ b/cmd/bashbrew/oci-builder.go @@ -28,7 +28,7 @@ import ( ) // given a reader and an interface to read it into, do the JSON decoder dance -func readJSON(r io.Reader, v interface{}) error { +func readJSON(r io.Reader, v any) error { decoder := json.NewDecoder(r) decoder.DisallowUnknownFields() if err := decoder.Decode(&v); err != nil { @@ -42,7 +42,7 @@ func readJSON(r io.Reader, v interface{}) error { } // given an io/fs, a file reference, and an interface to read it into, read a JSON blob from the io/fs -func readJSONFile(fs iofs.FS, file string, v interface{}) error { +func readJSONFile(fs iofs.FS, file string, v any) error { f, err := fs.Open(file) if err != nil { return err @@ -53,7 +53,7 @@ func readJSONFile(fs iofs.FS, file string, v interface{}) error { } // given a containerd content store and an OCI descriptor, parse the JSON blob -func readContentJSON(ctx context.Context, cs content.Provider, desc imagespec.Descriptor, v interface{}) error { +func readContentJSON(ctx context.Context, cs content.Provider, desc imagespec.Descriptor, v any) error { ra, err := cs.ReaderAt(ctx, desc) if err != nil { return err diff --git a/go.mod b/go.mod index e01cc83f..9387dc6c 100644 --- a/go.mod +++ b/go.mod @@ -1,16 +1,16 @@ module github.com/docker-library/bashbrew -go 1.23.0 +go 1.24.0 require ( github.com/containerd/containerd v1.6.19 - github.com/go-git/go-git/v5 v5.16.2 + github.com/go-git/go-git/v5 v5.17.0 github.com/opencontainers/image-spec v1.1.0-rc2.0.20221013174636-8159c8264e2e github.com/sirupsen/logrus v1.9.3 github.com/urfave/cli v1.22.10 go.etcd.io/bbolt v1.3.7 - golang.org/x/term v0.31.0 - pault.ag/go/debian v0.12.0 + golang.org/x/term v0.37.0 + pault.ag/go/debian v0.19.0 pault.ag/go/topsort v0.1.1 ) @@ -30,7 +30,7 @@ require ( github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect github.com/emirpasic/gods v1.18.1 // indirect github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect - github.com/go-git/go-billy/v5 v5.6.2 // indirect + github.com/go-git/go-billy/v5 v5.8.0 // indirect github.com/gogo/googleapis v1.4.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect @@ -38,7 +38,7 @@ require ( github.com/google/uuid v1.3.0 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/kevinburke/ssh_config v1.2.0 // indirect - github.com/klauspost/compress v1.15.13 // indirect + github.com/klauspost/compress v1.18.0 // indirect github.com/moby/locker v1.0.1 // indirect github.com/moby/sys/mountinfo v0.6.2 // indirect github.com/moby/sys/signal v0.7.0 // indirect @@ -53,11 +53,11 @@ require ( github.com/skeema/knownhosts v1.3.1 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect go.opencensus.io v0.24.0 // indirect - golang.org/x/crypto v0.37.0 // indirect - golang.org/x/net v0.39.0 // indirect - golang.org/x/sync v0.13.0 // indirect - golang.org/x/sys v0.32.0 // indirect - golang.org/x/text v0.24.0 // indirect + golang.org/x/crypto v0.45.0 // indirect + golang.org/x/net v0.47.0 // indirect + golang.org/x/sync v0.18.0 // indirect + golang.org/x/sys v0.38.0 // indirect + golang.org/x/text v0.31.0 // indirect google.golang.org/genproto v0.0.0-20221207170731-23e4bf6bdc37 // indirect google.golang.org/grpc v1.51.0 // indirect google.golang.org/protobuf v1.33.0 // indirect diff --git a/go.sum b/go.sum index cef8bc6d..9f19fd2b 100644 --- a/go.sum +++ b/go.sum @@ -39,7 +39,6 @@ github.com/Azure/go-autorest/logger v0.2.0/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZ github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/DataDog/zstd v1.4.8/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= github.com/Microsoft/go-winio v0.4.11/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA= github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5/go.mod h1:tTuCMEN+UleMWgg9dVx4Hu52b1bJo+59jBh3ajtinzw= @@ -299,12 +298,12 @@ github.com/gliderlabs/ssh v0.3.8 h1:a4YXD1V7xMF9g5nTkdfnja3Sxy1PVDCj1Zg4Wb8vY6c= github.com/gliderlabs/ssh v0.3.8/go.mod h1:xYoytBv1sV0aL3CavoDuJIQNURXkkfPA/wxQ1pL1fAU= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= -github.com/go-git/go-billy/v5 v5.6.2 h1:6Q86EsPXMa7c3YZ3aLAQsMA0VlWmy43r6FHqa/UNbRM= -github.com/go-git/go-billy/v5 v5.6.2/go.mod h1:rcFC2rAsp/erv7CMz9GczHcuD0D32fWzH+MJAU+jaUU= +github.com/go-git/go-billy/v5 v5.8.0 h1:I8hjc3LbBlXTtVuFNJuwYuMiHvQJDq1AT6u4DwDzZG0= +github.com/go-git/go-billy/v5 v5.8.0/go.mod h1:RpvI/rw4Vr5QA+Z60c6d6LXH0rYJo0uD5SqfmrrheCY= github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4= github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII= -github.com/go-git/go-git/v5 v5.16.2 h1:fT6ZIOjE5iEnkzKyxTHK1W4HGAsPhqEqiSAssSO77hM= -github.com/go-git/go-git/v5 v5.16.2/go.mod h1:4Ge4alE/5gPs30F2H1esi2gPd69R0C39lolkucHBOp8= +github.com/go-git/go-git/v5 v5.17.0 h1:AbyI4xf+7DsjINHMu35quAh4wJygKBKBuXVjV/pxesM= +github.com/go-git/go-git/v5 v5.17.0/go.mod h1:f82C4YiLx+Lhi8eHxltLeGC5uBTXSFa6PC5WW9o4SjI= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= @@ -460,11 +459,10 @@ github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvW github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/kjk/lzma v0.0.0-20161016003348-3fd93898850d/go.mod h1:phT/jsRPBAEqjAibu1BurrabCBNTYiVI+zbmyCZJY6Q= github.com/klauspost/compress v1.11.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.11.13/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= -github.com/klauspost/compress v1.15.13 h1:NFn1Wr8cfnenSJSA46lLq4wHCcBzKTSjnBIexDMMOV0= -github.com/klauspost/compress v1.15.13/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM= +github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo= +github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -709,7 +707,6 @@ github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xeipuuv/gojsonschema v0.0.0-20180618132009-1d523034197f/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs= -github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -749,11 +746,10 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE= -golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc= +golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q= +golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -827,8 +823,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210825183410-e898025ed96a/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY= -golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E= +golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY= +golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -845,8 +841,8 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610= -golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= +golang.org/x/sync v0.18.0 h1:kr88TuHDroi+UVf+0hZnirlk8o8T+4MrK6mr60WkH/I= +golang.org/x/sync v0.18.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -920,11 +916,11 @@ golang.org/x/sys v0.0.0-20211116061358-0a5406a5449c/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20= -golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc= +golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.31.0 h1:erwDkOK1Msy6offm1mOgvspSkslFnIGsFnxOKoufg3o= -golang.org/x/term v0.31.0/go.mod h1:R4BeIy7D95HzImkxGkTW1UQTtP54tio2RyHz7PwK0aw= +golang.org/x/term v0.37.0 h1:8EGAD0qCmHYZg6J17DvsMy9/wJ7/D/4pV/wfnld5lTU= +golang.org/x/term v0.37.0/go.mod h1:5pB4lxRNYYVZuTLmy8oR2BH8dflOR+IbTYFD8fi3254= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -932,8 +928,8 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0= -golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU= +golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM= +golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -1144,9 +1140,8 @@ k8s.io/kube-openapi v0.0.0-20200805222855-6aeccd4b50c6/go.mod h1:UuqjUnNftUyPE5H k8s.io/kube-openapi v0.0.0-20201113171705-d219536bb9fd/go.mod h1:WOJ3KddDSol4tAGcJo0Tvi+dK12EcqSLqcWsryKMpfM= k8s.io/kubernetes v1.13.0/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk= k8s.io/utils v0.0.0-20201110183641-67b214c5f920/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= -pault.ag/go/debian v0.12.0 h1:b8ctSdBSGJ98NE1VLn06aSx70EUpczlP2qqSHEiYYJA= -pault.ag/go/debian v0.12.0/go.mod h1:UbnMr3z/KZepjq7VzbYgBEfz8j4+Pyrm2L5X1fzhy/k= -pault.ag/go/topsort v0.0.0-20160530003732-f98d2ad46e1a/go.mod h1:INqx0ClF7kmPAMk2zVTX8DRnhZ/yaA/Mg52g8KFKE7k= +pault.ag/go/debian v0.19.0 h1:RUxCjScMbnlqFH5I+qsmyjZH8fXXtQ05rlkMJop3tjo= +pault.ag/go/debian v0.19.0/go.mod h1:1LMojDAazlJ7cA5Ne6H2ZHD4hh3o8NRiW+MpvQRji2o= pault.ag/go/topsort v0.1.1 h1:L0QnhUly6LmTv0e3DEzbN2q6/FGgAcQvaEw65S53Bg4= pault.ag/go/topsort v0.1.1/go.mod h1:r1kc/L0/FZ3HhjezBIPaNVhkqv8L0UJ9bxRuHRVZ0q4= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= diff --git a/manifest/rfc2822.go b/manifest/rfc2822.go index e415f83d..cda73f1d 100644 --- a/manifest/rfc2822.go +++ b/manifest/rfc2822.go @@ -4,8 +4,10 @@ import ( "bufio" "fmt" "io" + "maps" "path" "regexp" + "slices" "sort" "strings" @@ -72,14 +74,6 @@ var ( } ) -func deepCopyStringsMap(a map[string]string) map[string]string { - b := map[string]string{} - for k, v := range a { - b[k] = v - } - return b -} - func (entry Manifest2822Entry) Clone() Manifest2822Entry { // SLICES! grr entry.Maintainers = append([]Manifest2822Maintainer{}, entry.Maintainers...) @@ -88,11 +82,14 @@ func (entry Manifest2822Entry) Clone() Manifest2822Entry { entry.Architectures = append([]string{}, entry.Architectures...) entry.Constraints = append([]string{}, entry.Constraints...) // and MAPS, oh my - entry.ArchValues = deepCopyStringsMap(entry.ArchValues) + entry.ArchValues = maps.Clone(entry.ArchValues) return entry } func (entry *Manifest2822Entry) SeedArchValues() { + if entry.ArchValues == nil { + entry.ArchValues = map[string]string{} + } for field, val := range entry.Paragraph.Values { if strings.HasSuffix(field, "-GitRepo") || strings.HasSuffix(field, "-GitFetch") || strings.HasSuffix(field, "-GitCommit") || strings.HasSuffix(field, "-Directory") || strings.HasSuffix(field, "-File") || strings.HasSuffix(field, "-Builder") { entry.ArchValues[field] = val @@ -101,6 +98,9 @@ func (entry *Manifest2822Entry) SeedArchValues() { } func (entry *Manifest2822Entry) CleanDirectoryValues() { entry.Directory = path.Clean(entry.Directory) + if entry.ArchValues == nil { + entry.ArchValues = map[string]string{} + } for field, val := range entry.ArchValues { if strings.HasSuffix(field, "-Directory") && val != "" { entry.ArchValues[field] = path.Clean(val) @@ -315,32 +315,17 @@ func (entry Manifest2822Entry) ArchBuilder(arch string) string { } func (entry Manifest2822Entry) HasTag(tag string) bool { - for _, existingTag := range entry.Tags { - if tag == existingTag { - return true - } - } - return false + return slices.Contains(entry.Tags, tag) } // HasSharedTag returns true if the given tag exists in entry.SharedTags. func (entry Manifest2822Entry) HasSharedTag(tag string) bool { - for _, existingTag := range entry.SharedTags { - if tag == existingTag { - return true - } - } - return false + return slices.Contains(entry.SharedTags, tag) } // HasArchitecture returns true if the given architecture exists in entry.Architectures func (entry Manifest2822Entry) HasArchitecture(arch string) bool { - for _, existingArch := range entry.Architectures { - if arch == existingArch { - return true - } - } - return false + return slices.Contains(entry.Architectures, arch) } func (manifest Manifest2822) GetTag(tag string) *Manifest2822Entry { @@ -400,7 +385,7 @@ func (manifest Manifest2822) GetSharedTagGroups() []SharedTagGroup { SharedTags: inter[tags], Entries: []*Manifest2822Entry{}, } - for _, tag := range strings.Split(tags, interKeySep) { + for tag := range strings.SplitSeq(tags, interKeySep) { group.Entries = append(group.Entries, manifest.GetTag(tag)) } ret = append(ret, group) diff --git a/pkg/dockerfile/parse_test.go b/pkg/dockerfile/parse_test.go index e4cd31c9..ddda9711 100644 --- a/pkg/dockerfile/parse_test.go +++ b/pkg/dockerfile/parse_test.go @@ -159,7 +159,6 @@ func TestParse(t *testing.T) { }, }, } { - td := td // some light normalization if td.name == "" { td.name = td.dockerfile diff --git a/pkg/gitfs/fs.go b/pkg/gitfs/fs.go index cf48f80c..c0625d2a 100644 --- a/pkg/gitfs/fs.go +++ b/pkg/gitfs/fs.go @@ -391,7 +391,7 @@ func (f gitFS) IsDir() bool { } // https://pkg.go.dev/io/fs#FileInfo: underlying data source (can return nil) -func (f gitFS) Sys() interface{} { +func (f gitFS) Sys() any { return nil } diff --git a/pkg/templatelib/lib.go b/pkg/templatelib/lib.go index 1ebedcd3..357380ae 100644 --- a/pkg/templatelib/lib.go +++ b/pkg/templatelib/lib.go @@ -17,13 +17,13 @@ func swapStringsFuncBoolArgsOrder(a func(string, string) bool) func(string, stri } } -func thingsActionFactory(name string, actOnFirst bool, action func([]interface{}, interface{}) interface{}) func(args ...interface{}) interface{} { - return func(args ...interface{}) interface{} { +func thingsActionFactory(name string, actOnFirst bool, action func([]any, any) any) func(args ...any) any { + return func(args ...any) any { if len(args) < 1 { panic(fmt.Sprintf(`%q requires at least one argument`, name)) } - actArgs := []interface{}{} + actArgs := []any{} for _, val := range args { v := reflect.ValueOf(val) @@ -37,7 +37,7 @@ func thingsActionFactory(name string, actOnFirst bool, action func([]interface{} } } - var arg interface{} + var arg any if actOnFirst { arg = actArgs[0] actArgs = actArgs[1:] @@ -50,8 +50,8 @@ func thingsActionFactory(name string, actOnFirst bool, action func([]interface{} } } -func stringsActionFactory(name string, actOnFirst bool, action func([]string, string) string) func(args ...interface{}) interface{} { - return thingsActionFactory(name, actOnFirst, func(args []interface{}, arg interface{}) interface{} { +func stringsActionFactory(name string, actOnFirst bool, action func([]string, string) string) func(args ...any) any { + return thingsActionFactory(name, actOnFirst, func(args []any, arg any) any { str := arg.(string) strs := []string{} for _, val := range args { @@ -79,7 +79,7 @@ var FuncMap = template.FuncMap{ // {{- $hugeIfTrue := .SomeValue | ternary "HUGE" "not so huge" -}} // if .SomeValue is truthy, $hugeIfTrue will be "HUGE" // (otherwise, "not so huge") - "ternary": func(truthy interface{}, falsey interface{}, val interface{}) interface{} { + "ternary": func(truthy any, falsey any, val any) any { if t, ok := template.IsTrue(val); !ok { panic(fmt.Sprintf(`template.IsTrue(%+v) says things are NOT OK`, val)) } else if t { @@ -91,13 +91,13 @@ var FuncMap = template.FuncMap{ // First Tag: {{- .Tags | first -}} // Last Tag: {{- .Tags | last -}} - "first": thingsActionFactory("first", true, func(args []interface{}, arg interface{}) interface{} { return arg }), - "last": thingsActionFactory("last", false, func(args []interface{}, arg interface{}) interface{} { return arg }), + "first": thingsActionFactory("first", true, func(args []any, arg any) any { return arg }), + "last": thingsActionFactory("last", false, func(args []any, arg any) any { return arg }), // JSON data dump: {{ json . }} // (especially nice for taking data and piping it to "jq") // (ie "some-tool inspect --format '{{ json . }}' some-things | jq .") - "json": func(v interface{}) (string, error) { + "json": func(v any) (string, error) { j, err := json.Marshal(v) return string(j), err }, @@ -118,11 +118,11 @@ var FuncMap = template.FuncMap{ // {{- getenv "PATH" -}} // {{- getenv "HOME" "no HOME set" -}} // {{- getenv "HOME" "is set" "is NOT set (or is empty)" -}} - "getenv": thingsActionFactory("getenv", true, func(args []interface{}, arg interface{}) interface{} { + "getenv": thingsActionFactory("getenv", true, func(args []any, arg any) any { var ( - val = os.Getenv(arg.(string)) - setVal interface{} = val - unsetVal interface{} = "" + val = os.Getenv(arg.(string)) + setVal any = val + unsetVal any = "" ) if len(args) == 2 { setVal, unsetVal = args[0], args[1] diff --git a/pkg/templatelib/lib_example_test.go b/pkg/templatelib/lib_example_test.go index 2fd7b861..e2caa5af 100644 --- a/pkg/templatelib/lib_example_test.go +++ b/pkg/templatelib/lib_example_test.go @@ -59,7 +59,7 @@ func Example_ternary() { {{- end -}} `) - err = tmpl.Execute(os.Stdout, []interface{}{ + err = tmpl.Execute(os.Stdout, []any{ true, false, "true", @@ -93,7 +93,7 @@ func Example_ternary() { func Example_firstLast() { tmpl, err := template.New("first-and-last").Funcs(templatelib.FuncMap).Parse(`First: {{ . | first }}, Last: {{ . | last }}`) - err = tmpl.Execute(os.Stdout, []interface{}{ + err = tmpl.Execute(os.Stdout, []any{ "a", "b", "c", @@ -111,7 +111,7 @@ func Example_json() { {{- json . -}} `) - err = tmpl.Execute(os.Stdout, map[string]interface{}{ + err = tmpl.Execute(os.Stdout, map[string]any{ "a": []string{"1", "2", "3"}, "b": map[string]bool{"1": true, "2": false, "3": true}, "c": nil, diff --git a/registry/registry.go b/registry/registry.go index d9c459ef..426b9867 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -27,7 +27,7 @@ type ResolvedObject struct { fetcher remotes.Fetcher } -func (obj ResolvedObject) fetchJSON(ctx context.Context, v interface{}) error { +func (obj ResolvedObject) fetchJSON(ctx context.Context, v any) error { // prevent go-digest panics later if err := obj.Desc.Digest.Validate(); err != nil { return err