From f67d118414b998f645480c12e22f2fac422e3c83 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 30 Nov 2023 01:39:42 +0000 Subject: [PATCH] Bump github.com/google/go-containerregistry from 0.16.1 to 0.17.0 Bumps [github.com/google/go-containerregistry](https://github.com/google/go-containerregistry) from 0.16.1 to 0.17.0. - [Release notes](https://github.com/google/go-containerregistry/releases) - [Changelog](https://github.com/google/go-containerregistry/blob/main/.goreleaser.yml) - [Commits](https://github.com/google/go-containerregistry/compare/v0.16.1...v0.17.0) --- updated-dependencies: - dependency-name: github.com/google/go-containerregistry dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 +- .../go-containerregistry/cmd/crane/cmd/gc.go | 66 +++++++++ .../cmd/crane/cmd/root.go | 3 +- .../cmd/crane/cmd/serve.go | 44 ++++-- .../go-containerregistry/cmd/crane/cmd/tag.go | 4 +- .../cmd/crane/cmd/validate.go | 57 +++++--- .../pkg/authn/keychain.go | 2 +- .../pkg/registry/blobs_disk.go | 16 +- .../go-containerregistry/pkg/v1/layout/gc.go | 137 ++++++++++++++++++ .../pkg/v1/remote/write.go | 5 + .../pkg/v1/validate/index.go | 54 +++++++ vendor/modules.txt | 2 +- 13 files changed, 356 insertions(+), 40 deletions(-) create mode 100644 vendor/github.com/google/go-containerregistry/cmd/crane/cmd/gc.go create mode 100644 vendor/github.com/google/go-containerregistry/pkg/v1/layout/gc.go diff --git a/go.mod b/go.mod index 77b6909bf3..3ba70349c7 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 github.com/go-training/helloworld v0.0.0-20200225145412-ba5f4379d78b github.com/google/go-cmp v0.6.0 - github.com/google/go-containerregistry v0.16.1 + github.com/google/go-containerregistry v0.17.0 github.com/opencontainers/image-spec v1.1.0-rc5 github.com/sigstore/cosign/v2 v2.2.1 github.com/spf13/cobra v1.8.0 diff --git a/go.sum b/go.sum index dec8b3bce8..03c1a37546 100644 --- a/go.sum +++ b/go.sum @@ -292,8 +292,8 @@ github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/go-containerregistry v0.16.1 h1:rUEt426sR6nyrL3gt+18ibRcvYpKYdpsa5ZW7MA08dQ= -github.com/google/go-containerregistry v0.16.1/go.mod h1:u0qB2l7mvtWVR5kNcbFIhFY1hLbf8eeGapA+vbFDCtQ= +github.com/google/go-containerregistry v0.17.0 h1:5p+zYs/R4VGHkhyvgWurWrpJ2hW4Vv9fQI+GzdcwXLk= +github.com/google/go-containerregistry v0.17.0/go.mod h1:u0qB2l7mvtWVR5kNcbFIhFY1hLbf8eeGapA+vbFDCtQ= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= diff --git a/vendor/github.com/google/go-containerregistry/cmd/crane/cmd/gc.go b/vendor/github.com/google/go-containerregistry/cmd/crane/cmd/gc.go new file mode 100644 index 0000000000..a80f148437 --- /dev/null +++ b/vendor/github.com/google/go-containerregistry/cmd/crane/cmd/gc.go @@ -0,0 +1,66 @@ +// Copyright 2018 Google LLC All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cmd + +import ( + "fmt" + "os" + + "github.com/google/go-containerregistry/pkg/v1/layout" + "github.com/spf13/cobra" +) + +func NewCmdLayout() *cobra.Command { + cmd := &cobra.Command{ + Use: "layout", + } + cmd.AddCommand(newCmdGc()) + return cmd +} + +// NewCmdGc creates a new cobra.Command for the pull subcommand. +func newCmdGc() *cobra.Command { + cmd := &cobra.Command{ + Use: "gc OCI-LAYOUT", + Short: "Garbage collect unreferenced blobs in a local oci-layout", + Args: cobra.ExactArgs(1), + Hidden: true, // TODO: promote to public once theres some milage + RunE: func(_ *cobra.Command, args []string) error { + path := args[0] + + p, err := layout.FromPath(path) + + if err != nil { + return err + } + + blobs, err := p.GarbageCollect() + if err != nil { + return err + } + + for _, blob := range blobs { + if err := p.RemoveBlob(blob); err != nil { + return err + } + fmt.Fprintf(os.Stderr, "garbage collecting: %s\n", blob.String()) + } + + return nil + }, + } + + return cmd +} diff --git a/vendor/github.com/google/go-containerregistry/cmd/crane/cmd/root.go b/vendor/github.com/google/go-containerregistry/cmd/crane/cmd/root.go index 3faa85f5f9..8fc8ccefa9 100644 --- a/vendor/github.com/google/go-containerregistry/cmd/crane/cmd/root.go +++ b/vendor/github.com/google/go-containerregistry/cmd/crane/cmd/root.go @@ -129,7 +129,8 @@ func New(use, short string, options []crane.Option) *cobra.Command { NewCmdTag(&options), NewCmdValidate(&options), NewCmdVersion(), - newCmdRegistry(), + NewCmdRegistry(), + NewCmdLayout(), ) root.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable debug logs") diff --git a/vendor/github.com/google/go-containerregistry/cmd/crane/cmd/serve.go b/vendor/github.com/google/go-containerregistry/cmd/crane/cmd/serve.go index 61d031b393..c375d648ef 100644 --- a/vendor/github.com/google/go-containerregistry/cmd/crane/cmd/serve.go +++ b/vendor/github.com/google/go-containerregistry/cmd/crane/cmd/serve.go @@ -28,7 +28,7 @@ import ( "github.com/google/go-containerregistry/pkg/registry" ) -func newCmdRegistry() *cobra.Command { +func NewCmdRegistry() *cobra.Command { cmd := &cobra.Command{ Use: "registry", } @@ -37,15 +37,16 @@ func newCmdRegistry() *cobra.Command { } func newCmdServe() *cobra.Command { - var disk bool + var address, disk string + var blobsToDisk bool cmd := &cobra.Command{ Use: "serve", - Short: "Serve an in-memory registry implementation", - Long: `This sub-command serves an in-memory registry implementation on an automatically chosen port (or $PORT) + Short: "Serve a registry implementation", + Long: `This sub-command serves a registry implementation on an automatically chosen port (:0), $PORT or --address The command blocks while the server accepts pushes and pulls. -Contents are only stored in memory, and when the process exits, pushed data is lost.`, +Contents are can be stored in memory (when the process exits, pushed data is lost.), and disk (--disk).`, Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, _ []string) error { ctx := cmd.Context() @@ -54,7 +55,12 @@ Contents are only stored in memory, and when the process exits, pushed data is l if port == "" { port = "0" } - listener, err := net.Listen("tcp", ":"+port) + listenOn := ":" + port + if address != "" { + listenOn = address + } + + listener, err := net.Listen("tcp", listenOn) if err != nil { log.Fatalln(err) } @@ -62,10 +68,21 @@ Contents are only stored in memory, and when the process exits, pushed data is l port = fmt.Sprintf("%d", porti) bh := registry.NewInMemoryBlobHandler() - if disk { - tmp := os.TempDir() - log.Printf("storing blobs in %s", tmp) - bh = registry.NewDiskBlobHandler(tmp) + + diskp := disk + if cmd.Flags().Changed("blobs-to-disk") { + if disk != "" { + return fmt.Errorf("--disk and --blobs-to-disk can't be used together") + } + diskp, err = os.MkdirTemp(os.TempDir(), "craneregistry*") + if err != nil { + return err + } + } + + if diskp != "" { + log.Printf("storing blobs in %s", diskp) + bh = registry.NewDiskBlobHandler(diskp) } s := &http.Server{ @@ -89,7 +106,12 @@ Contents are only stored in memory, and when the process exits, pushed data is l return nil }, } - cmd.Flags().BoolVar(&disk, "blobs-to-disk", false, "Store blobs on disk") + // TODO: remove --blobs-to-disk in a future release. + cmd.Flags().BoolVarP(&blobsToDisk, "blobs-to-disk", "", false, "Store blobs on disk on tmpdir") cmd.Flags().MarkHidden("blobs-to-disk") + cmd.Flags().MarkDeprecated("blobs-to-disk", "and will stop working in a future release. use --disk=$(mktemp -d) instead.") + cmd.Flags().StringVarP(&disk, "disk", "", "", "Path to a directory where blobs will be stored") + cmd.Flags().StringVar(&address, "address", "", "Address to listen on") + return cmd } diff --git a/vendor/github.com/google/go-containerregistry/cmd/crane/cmd/tag.go b/vendor/github.com/google/go-containerregistry/cmd/crane/cmd/tag.go index 9af803a659..eb2ba2f838 100644 --- a/vendor/github.com/google/go-containerregistry/cmd/crane/cmd/tag.go +++ b/vendor/github.com/google/go-containerregistry/cmd/crane/cmd/tag.go @@ -24,7 +24,9 @@ func NewCmdTag(options *[]crane.Option) *cobra.Command { return &cobra.Command{ Use: "tag IMG TAG", Short: "Efficiently tag a remote image", - Long: `This differs slightly from the "copy" command in a couple subtle ways: + Long: `Tag remote image without downloading it. + +This differs slightly from the "copy" command in a couple subtle ways: 1. You don't have to specify the entire repository for the tag you're adding. For example, these two commands are functionally equivalent: ` + "```" + ` diff --git a/vendor/github.com/google/go-containerregistry/cmd/crane/cmd/validate.go b/vendor/github.com/google/go-containerregistry/cmd/crane/cmd/validate.go index d5736bd253..411772f524 100644 --- a/vendor/github.com/google/go-containerregistry/cmd/crane/cmd/validate.go +++ b/vendor/github.com/google/go-containerregistry/cmd/crane/cmd/validate.go @@ -18,7 +18,6 @@ import ( "fmt" "github.com/google/go-containerregistry/pkg/crane" - v1 "github.com/google/go-containerregistry/pkg/v1" "github.com/google/go-containerregistry/pkg/v1/tarball" "github.com/google/go-containerregistry/pkg/v1/validate" "github.com/spf13/cobra" @@ -36,28 +35,56 @@ func NewCmdValidate(options *[]crane.Option) *cobra.Command { Short: "Validate that an image is well-formed", Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) error { - for flag, maker := range map[string]func(string, ...crane.Option) (v1.Image, error){ - tarballPath: makeTarball, - remoteRef: crane.Pull, - } { - if flag == "" { - continue - } - img, err := maker(flag, *options...) + if tarballPath != "" { + img, err := tarball.ImageFromPath(tarballPath, nil) if err != nil { - return fmt.Errorf("failed to read image %s: %w", flag, err) + return fmt.Errorf("failed to read image %s: %w", tarballPath, err) } - opt := []validate.Option{} if fast { opt = append(opt, validate.Fast) } if err := validate.Image(img, opt...); err != nil { - fmt.Fprintf(cmd.OutOrStdout(), "FAIL: %s: %v\n", flag, err) + fmt.Fprintf(cmd.OutOrStdout(), "FAIL: %s: %v\n", tarballPath, err) return err } - fmt.Fprintf(cmd.OutOrStdout(), "PASS: %s\n", flag) + fmt.Fprintf(cmd.OutOrStdout(), "PASS: %s\n", tarballPath) + } + + if remoteRef != "" { + rmt, err := crane.Get(remoteRef, *options...) + if err != nil { + return fmt.Errorf("failed to read image %s: %w", remoteRef, err) + } + + o := crane.GetOptions(*options...) + + opt := []validate.Option{} + if fast { + opt = append(opt, validate.Fast) + } + if rmt.MediaType.IsIndex() && o.Platform == nil { + idx, err := rmt.ImageIndex() + if err != nil { + return fmt.Errorf("reading index: %w", err) + } + if err := validate.Index(idx, opt...); err != nil { + fmt.Fprintf(cmd.OutOrStdout(), "FAIL: %s: %v\n", remoteRef, err) + return err + } + } else { + img, err := rmt.Image() + if err != nil { + return fmt.Errorf("reading image: %w", err) + } + if err := validate.Image(img, opt...); err != nil { + fmt.Fprintf(cmd.OutOrStdout(), "FAIL: %s: %v\n", remoteRef, err) + return err + } + } + fmt.Fprintf(cmd.OutOrStdout(), "PASS: %s\n", remoteRef) } + return nil }, } @@ -67,7 +94,3 @@ func NewCmdValidate(options *[]crane.Option) *cobra.Command { return validateCmd } - -func makeTarball(path string, _ ...crane.Option) (v1.Image, error) { - return tarball.ImageFromPath(path, nil) -} diff --git a/vendor/github.com/google/go-containerregistry/pkg/authn/keychain.go b/vendor/github.com/google/go-containerregistry/pkg/authn/keychain.go index 4e32500cda..99e0b81c8d 100644 --- a/vendor/github.com/google/go-containerregistry/pkg/authn/keychain.go +++ b/vendor/github.com/google/go-containerregistry/pkg/authn/keychain.go @@ -53,7 +53,7 @@ type defaultKeychain struct { var ( // DefaultKeychain implements Keychain by interpreting the docker config file. - DefaultKeychain = RefreshingKeychain(&defaultKeychain{}, 5*time.Minute) + DefaultKeychain = &defaultKeychain{} ) const ( diff --git a/vendor/github.com/google/go-containerregistry/pkg/registry/blobs_disk.go b/vendor/github.com/google/go-containerregistry/pkg/registry/blobs_disk.go index dc86bec351..361390f049 100644 --- a/vendor/github.com/google/go-containerregistry/pkg/registry/blobs_disk.go +++ b/vendor/github.com/google/go-containerregistry/pkg/registry/blobs_disk.go @@ -30,8 +30,12 @@ type diskHandler struct { func NewDiskBlobHandler(dir string) BlobHandler { return &diskHandler{dir: dir} } +func (m *diskHandler) blobHashPath(h v1.Hash) string { + return filepath.Join(m.dir, h.Algorithm, h.Hex) +} + func (m *diskHandler) Stat(_ context.Context, _ string, h v1.Hash) (int64, error) { - fi, err := os.Stat(filepath.Join(m.dir, h.String())) + fi, err := os.Stat(m.blobHashPath(h)) if errors.Is(err, os.ErrNotExist) { return 0, errNotFound } else if err != nil { @@ -40,7 +44,7 @@ func (m *diskHandler) Stat(_ context.Context, _ string, h v1.Hash) (int64, error return fi.Size(), nil } func (m *diskHandler) Get(_ context.Context, _ string, h v1.Hash) (io.ReadCloser, error) { - return os.Open(filepath.Join(m.dir, h.String())) + return os.Open(m.blobHashPath(h)) } func (m *diskHandler) Put(_ context.Context, _ string, h v1.Hash, rc io.ReadCloser) error { // Put the temp file in the same directory to avoid cross-device problems @@ -57,9 +61,11 @@ func (m *diskHandler) Put(_ context.Context, _ string, h v1.Hash, rc io.ReadClos }(); err != nil { return err } - - return os.Rename(f.Name(), filepath.Join(m.dir, h.String())) + if err := os.MkdirAll(filepath.Join(m.dir, h.Algorithm), os.ModePerm); err != nil { + return err + } + return os.Rename(f.Name(), m.blobHashPath(h)) } func (m *diskHandler) Delete(_ context.Context, _ string, h v1.Hash) error { - return os.Remove(filepath.Join(m.dir, h.String())) + return os.Remove(m.blobHashPath(h)) } diff --git a/vendor/github.com/google/go-containerregistry/pkg/v1/layout/gc.go b/vendor/github.com/google/go-containerregistry/pkg/v1/layout/gc.go new file mode 100644 index 0000000000..5fdb2c05d2 --- /dev/null +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/layout/gc.go @@ -0,0 +1,137 @@ +// Copyright 2018 Google LLC All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This is an EXPERIMENTAL package, and may change in arbitrary ways without notice. +package layout + +import ( + "fmt" + "io/fs" + "path/filepath" + "strings" + + v1 "github.com/google/go-containerregistry/pkg/v1" +) + +// GarbageCollect removes unreferenced blobs from the oci-layout +// +// This is an experimental api, and not subject to any stability guarantees +// We may abandon it at any time, without prior notice. +// Deprecated: Use it at your own risk! +func (l Path) GarbageCollect() ([]v1.Hash, error) { + idx, err := l.ImageIndex() + if err != nil { + return nil, err + } + blobsToKeep := map[string]bool{} + if err := l.garbageCollectImageIndex(idx, blobsToKeep); err != nil { + return nil, err + } + blobsDir := l.path("blobs") + removedBlobs := []v1.Hash{} + + err = filepath.WalkDir(blobsDir, func(path string, d fs.DirEntry, err error) error { + if err != nil { + return err + } + + if d.IsDir() { + return nil + } + + rel, err := filepath.Rel(blobsDir, path) + if err != nil { + return err + } + hashString := strings.Replace(rel, "/", ":", 1) + if present := blobsToKeep[hashString]; !present { + h, err := v1.NewHash(hashString) + if err != nil { + return err + } + removedBlobs = append(removedBlobs, h) + } + return nil + }) + + if err != nil { + return nil, err + } + + return removedBlobs, nil +} + +func (l Path) garbageCollectImageIndex(index v1.ImageIndex, blobsToKeep map[string]bool) error { + idxm, err := index.IndexManifest() + if err != nil { + return err + } + + h, err := index.Digest() + if err != nil { + return err + } + + blobsToKeep[h.String()] = true + + for _, descriptor := range idxm.Manifests { + if descriptor.MediaType.IsImage() { + img, err := index.Image(descriptor.Digest) + if err != nil { + return err + } + if err := l.garbageCollectImage(img, blobsToKeep); err != nil { + return err + } + } else if descriptor.MediaType.IsIndex() { + idx, err := index.ImageIndex(descriptor.Digest) + if err != nil { + return err + } + if err := l.garbageCollectImageIndex(idx, blobsToKeep); err != nil { + return err + } + } else { + return fmt.Errorf("gc: unknown media type: %s", descriptor.MediaType) + } + } + return nil +} + +func (l Path) garbageCollectImage(image v1.Image, blobsToKeep map[string]bool) error { + h, err := image.Digest() + if err != nil { + return err + } + blobsToKeep[h.String()] = true + + h, err = image.ConfigName() + if err != nil { + return err + } + blobsToKeep[h.String()] = true + + ls, err := image.Layers() + if err != nil { + return err + } + for _, l := range ls { + h, err := l.Digest() + if err != nil { + return err + } + blobsToKeep[h.String()] = true + } + return nil +} diff --git a/vendor/github.com/google/go-containerregistry/pkg/v1/remote/write.go b/vendor/github.com/google/go-containerregistry/pkg/v1/remote/write.go index 6bfce75e72..04a3989a6e 100644 --- a/vendor/github.com/google/go-containerregistry/pkg/v1/remote/write.go +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/remote/write.go @@ -280,6 +280,11 @@ func (w *writer) streamBlob(ctx context.Context, layer v1.Layer, streamLocation if _, ok := layer.(*stream.Layer); !ok { // We can't retry streaming layers. req.GetBody = getBody + + // If we know the size, set it. + if size, err := layer.Size(); err == nil { + req.ContentLength = size + } } req.Header.Set("Content-Type", "application/octet-stream") diff --git a/vendor/github.com/google/go-containerregistry/pkg/v1/validate/index.go b/vendor/github.com/google/go-containerregistry/pkg/v1/validate/index.go index 7514dc48a0..4d833ae672 100644 --- a/vendor/github.com/google/go-containerregistry/pkg/v1/validate/index.go +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/validate/index.go @@ -79,6 +79,9 @@ func validateChildren(idx v1.ImageIndex, opt ...Option) error { if err := validateMediaType(img, desc.MediaType); err != nil { errs = append(errs, fmt.Sprintf("failed to validate image MediaType[%d](%s): %v", i, desc.Digest, err)) } + if err := validatePlatform(img, desc.Platform); err != nil { + errs = append(errs, fmt.Sprintf("failed to validate image platform[%d](%s): %v", i, desc.Digest, err)) + } default: // Workaround for #819. if wl, ok := idx.(withLayer); ok { @@ -173,3 +176,54 @@ func validateIndexManifest(idx v1.ImageIndex) error { return nil } + +func validatePlatform(img v1.Image, want *v1.Platform) error { + if want == nil { + return nil + } + + cf, err := img.ConfigFile() + if err != nil { + return err + } + + got := cf.Platform() + + if got == nil { + return fmt.Errorf("config file missing platform fields") + } + + if got.Equals(*want) { + return nil + } + + errs := []string{} + + if got.OS != want.OS { + errs = append(errs, fmt.Sprintf("mismatched OS: %s != %s", got.OS, want.OS)) + } + + if got.Architecture != want.Architecture { + errs = append(errs, fmt.Sprintf("mismatched Architecture: %s != %s", got.Architecture, want.Architecture)) + } + + if got.OSVersion != want.OSVersion { + errs = append(errs, fmt.Sprintf("mismatched OSVersion: %s != %s", got.OSVersion, want.OSVersion)) + } + + if got.OSVersion != want.OSVersion { + errs = append(errs, fmt.Sprintf("mismatched OSVersion: %s != %s", got.OSVersion, want.OSVersion)) + } + + if len(errs) == 0 { + // If we got here, some features might be mismatched. Just add those... + if len(got.Features) != 0 || len(want.Features) != 0 { + errs = append(errs, fmt.Sprintf("mismatched Features: %v, %v", got.Features, want.Features)) + } + if len(got.OSFeatures) != 0 || len(want.OSFeatures) != 0 { + errs = append(errs, fmt.Sprintf("mismatched OSFeatures: %v, %v", got.OSFeatures, want.OSFeatures)) + } + } + + return errors.New(strings.Join(errs, "\n")) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index c15275ab46..79321d8b7d 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -284,7 +284,7 @@ github.com/google/go-cmp/cmp/internal/diff github.com/google/go-cmp/cmp/internal/flags github.com/google/go-cmp/cmp/internal/function github.com/google/go-cmp/cmp/internal/value -# github.com/google/go-containerregistry v0.16.1 +# github.com/google/go-containerregistry v0.17.0 ## explicit; go 1.18 github.com/google/go-containerregistry/cmd/crane/cmd github.com/google/go-containerregistry/internal/and