From a42a5099cc66fdc9743062697ffb97f74c13c8e1 Mon Sep 17 00:00:00 2001 From: dlorenc Date: Wed, 22 Aug 2018 08:50:19 -0700 Subject: [PATCH 1/2] Update go-containerregistry library --- Godeps/Godeps.json | 102 +++--- .../go-containerregistry/authn/BUILD.bazel | 31 -- .../go-containerregistry/name/BUILD.bazel | 28 -- .../{ => pkg}/authn/anon.go | 0 .../{ => pkg}/authn/auth.go | 0 .../{ => pkg}/authn/authn.go | 0 .../{ => pkg}/authn/basic.go | 0 .../{ => pkg}/authn/bearer.go | 0 .../{ => pkg}/authn/doc.go | 0 .../{ => pkg}/authn/helper.go | 12 +- .../{ => pkg}/authn/keychain.go | 36 +- .../pkg/authn/multikeychain.go | 45 +++ .../{ => pkg}/name/check.go | 0 .../{ => pkg}/name/digest.go | 0 .../{ => pkg}/name/errors.go | 0 .../{ => pkg}/name/ref.go | 1 + .../{ => pkg}/name/registry.go | 59 +++- .../{ => pkg}/name/repository.go | 2 +- .../{ => pkg}/name/tag.go | 4 +- .../{ => pkg}/v1/config.go | 53 ++- .../go-containerregistry/{ => pkg}/v1/doc.go | 3 + .../go-containerregistry/{ => pkg}/v1/hash.go | 5 +- .../{ => pkg}/v1/image.go | 4 +- .../transport/scheme.go => pkg/v1/index.go} | 33 +- .../{ => pkg}/v1/layer.go | 0 .../{ => pkg}/v1/manifest.go | 25 +- .../{ => pkg}/v1/partial/compressed.go | 10 +- .../{ => pkg}/v1/partial/doc.go | 0 .../{ => pkg}/v1/partial/image.go | 2 +- .../{ => pkg}/v1/partial/uncompressed.go | 19 +- .../{ => pkg}/v1/partial/with.go | 26 +- .../go-containerregistry/pkg/v1/platform.go | 24 ++ .../{ => pkg}/v1/remote/delete.go | 11 +- .../{ => pkg}/v1/remote/doc.go | 0 .../{ => pkg}/v1/remote/error.go | 2 +- .../{ => pkg}/v1/remote/image.go | 82 +++-- .../pkg/v1/remote/list.go | 64 ++++ .../pkg/v1/remote/mount.go | 77 +++++ .../pkg/v1/remote/options.go | 56 ++++ .../{ => pkg}/v1/remote/transport/basic.go | 2 +- .../{ => pkg}/v1/remote/transport/bearer.go | 34 +- .../{ => pkg}/v1/remote/transport/doc.go | 0 .../{ => pkg}/v1/remote/transport/ping.go | 18 +- .../{ => pkg}/v1/remote/transport/scope.go | 13 +- .../v1/remote/transport/transport.go | 22 +- .../{ => pkg}/v1/remote/write.go | 111 +++++-- .../{ => pkg}/v1/tarball/doc.go | 0 .../{ => pkg}/v1/tarball/image.go | 63 ++-- .../pkg/v1/tarball/layer.go | 144 ++++++++ .../{ => pkg}/v1/tarball/write.go | 61 ++-- .../{ => pkg}/v1/types/types.go | 0 .../{ => pkg}/v1/v1util/and_closer.go | 0 .../{ => pkg}/v1/v1util/nop.go | 0 .../{ => pkg}/v1/v1util/verify.go | 2 +- .../{ => pkg}/v1/v1util/zip.go | 33 +- .../pkg/v1/zz_deepcopy_generated.go | 314 ++++++++++++++++++ .../go-containerregistry/v1/BUILD.bazel | 26 -- .../v1/partial/BUILD.bazel | 19 -- .../v1/remote/BUILD.bazel | 44 --- .../v1/remote/transport/BUILD.bazel | 37 --- .../v1/tarball/BUILD.bazel | 68 ---- .../go-containerregistry/v1/types/BUILD.bazel | 8 - .../v1/v1util/BUILD.bazel | 25 -- 63 files changed, 1298 insertions(+), 562 deletions(-) delete mode 100644 vendor/github.com/google/go-containerregistry/authn/BUILD.bazel delete mode 100644 vendor/github.com/google/go-containerregistry/name/BUILD.bazel rename vendor/github.com/google/go-containerregistry/{ => pkg}/authn/anon.go (100%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/authn/auth.go (100%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/authn/authn.go (100%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/authn/basic.go (100%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/authn/bearer.go (100%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/authn/doc.go (100%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/authn/helper.go (95%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/authn/keychain.go (81%) create mode 100644 vendor/github.com/google/go-containerregistry/pkg/authn/multikeychain.go rename vendor/github.com/google/go-containerregistry/{ => pkg}/name/check.go (100%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/name/digest.go (100%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/name/errors.go (100%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/name/ref.go (96%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/name/registry.go (59%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/name/repository.go (98%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/name/tag.go (91%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/config.go (59%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/doc.go (84%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/hash.go (95%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/image.go (93%) rename vendor/github.com/google/go-containerregistry/{v1/remote/transport/scheme.go => pkg/v1/index.go} (50%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/layer.go (100%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/manifest.go (64%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/partial/compressed.go (93%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/partial/doc.go (100%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/partial/image.go (94%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/partial/uncompressed.go (94%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/partial/with.go (92%) create mode 100644 vendor/github.com/google/go-containerregistry/pkg/v1/platform.go rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/remote/delete.go (83%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/remote/doc.go (100%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/remote/error.go (98%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/remote/image.go (68%) create mode 100644 vendor/github.com/google/go-containerregistry/pkg/v1/remote/list.go create mode 100644 vendor/github.com/google/go-containerregistry/pkg/v1/remote/mount.go create mode 100644 vendor/github.com/google/go-containerregistry/pkg/v1/remote/options.go rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/remote/transport/basic.go (96%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/remote/transport/bearer.go (76%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/remote/transport/doc.go (100%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/remote/transport/ping.go (85%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/remote/transport/scope.go (73%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/remote/transport/transport.go (78%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/remote/write.go (70%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/tarball/doc.go (100%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/tarball/image.go (82%) create mode 100644 vendor/github.com/google/go-containerregistry/pkg/v1/tarball/layer.go rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/tarball/write.go (50%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/types/types.go (100%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/v1util/and_closer.go (100%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/v1util/nop.go (100%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/v1util/verify.go (97%) rename vendor/github.com/google/go-containerregistry/{ => pkg}/v1/v1util/zip.go (81%) create mode 100644 vendor/github.com/google/go-containerregistry/pkg/v1/zz_deepcopy_generated.go delete mode 100644 vendor/github.com/google/go-containerregistry/v1/BUILD.bazel delete mode 100644 vendor/github.com/google/go-containerregistry/v1/partial/BUILD.bazel delete mode 100644 vendor/github.com/google/go-containerregistry/v1/remote/BUILD.bazel delete mode 100644 vendor/github.com/google/go-containerregistry/v1/remote/transport/BUILD.bazel delete mode 100644 vendor/github.com/google/go-containerregistry/v1/tarball/BUILD.bazel delete mode 100644 vendor/github.com/google/go-containerregistry/v1/types/BUILD.bazel delete mode 100644 vendor/github.com/google/go-containerregistry/v1/v1util/BUILD.bazel diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 3992b557cce9..5227a9a2faec 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -1,7 +1,7 @@ { "ImportPath": "k8s.io/minikube", "GoVersion": "go1.10", - "GodepVersion": "v80", + "GodepVersion": "v79", "Packages": [ "./..." ], @@ -50,162 +50,162 @@ }, { "ImportPath": "github.com/docker/machine/commands/mcndirs", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/drivers/errdriver", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/drivers/hyperv", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/drivers/none", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/drivers/virtualbox", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/drivers/vmwarefusion", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/libmachine", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/libmachine/auth", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/libmachine/cert", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/libmachine/check", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/libmachine/drivers", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/libmachine/drivers/plugin", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/libmachine/drivers/plugin/localbinary", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/libmachine/drivers/rpc", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/libmachine/engine", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/libmachine/host", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/libmachine/log", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/libmachine/mcndockerclient", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/libmachine/mcnerror", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/libmachine/mcnflag", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/libmachine/mcnutils", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/libmachine/persist", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/libmachine/provision", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/libmachine/provision/pkgaction", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/libmachine/provision/serviceaction", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/libmachine/shell", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/libmachine/ssh", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/libmachine/state", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/libmachine/swarm", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/libmachine/version", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/libmachine/versioncmp", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { "ImportPath": "github.com/docker/machine/version", - "Comment": "docs-v0.8.2-2016-09-26-391-g1903531", + "Comment": "docs-v0.8.2-2016-09-26-391-g19035310", "Rev": "19035310d4ba1b58056aae427ea669d1db5fc618" }, { @@ -256,40 +256,40 @@ "Rev": "1643683e1b54a9e88ad26d98f81400c8c9d9f4f9" }, { - "ImportPath": "github.com/google/go-containerregistry/authn", - "Rev": "ee5c47f79bbaa9faac0ffd681b86427383b79213" + "ImportPath": "github.com/google/go-containerregistry/pkg/authn", + "Rev": "3165313d6d3f973ec0b0ed3ec5a63b520e065d40" }, { - "ImportPath": "github.com/google/go-containerregistry/name", - "Rev": "ee5c47f79bbaa9faac0ffd681b86427383b79213" + "ImportPath": "github.com/google/go-containerregistry/pkg/name", + "Rev": "3165313d6d3f973ec0b0ed3ec5a63b520e065d40" }, { - "ImportPath": "github.com/google/go-containerregistry/v1", - "Rev": "ee5c47f79bbaa9faac0ffd681b86427383b79213" + "ImportPath": "github.com/google/go-containerregistry/pkg/v1", + "Rev": "3165313d6d3f973ec0b0ed3ec5a63b520e065d40" }, { - "ImportPath": "github.com/google/go-containerregistry/v1/partial", - "Rev": "ee5c47f79bbaa9faac0ffd681b86427383b79213" + "ImportPath": "github.com/google/go-containerregistry/pkg/v1/partial", + "Rev": "3165313d6d3f973ec0b0ed3ec5a63b520e065d40" }, { - "ImportPath": "github.com/google/go-containerregistry/v1/remote", - "Rev": "ee5c47f79bbaa9faac0ffd681b86427383b79213" + "ImportPath": "github.com/google/go-containerregistry/pkg/v1/remote", + "Rev": "3165313d6d3f973ec0b0ed3ec5a63b520e065d40" }, { - "ImportPath": "github.com/google/go-containerregistry/v1/remote/transport", - "Rev": "ee5c47f79bbaa9faac0ffd681b86427383b79213" + "ImportPath": "github.com/google/go-containerregistry/pkg/v1/remote/transport", + "Rev": "3165313d6d3f973ec0b0ed3ec5a63b520e065d40" }, { - "ImportPath": "github.com/google/go-containerregistry/v1/tarball", - "Rev": "ee5c47f79bbaa9faac0ffd681b86427383b79213" + "ImportPath": "github.com/google/go-containerregistry/pkg/v1/tarball", + "Rev": "3165313d6d3f973ec0b0ed3ec5a63b520e065d40" }, { - "ImportPath": "github.com/google/go-containerregistry/v1/types", - "Rev": "ee5c47f79bbaa9faac0ffd681b86427383b79213" + "ImportPath": "github.com/google/go-containerregistry/pkg/v1/types", + "Rev": "3165313d6d3f973ec0b0ed3ec5a63b520e065d40" }, { - "ImportPath": "github.com/google/go-containerregistry/v1/v1util", - "Rev": "ee5c47f79bbaa9faac0ffd681b86427383b79213" + "ImportPath": "github.com/google/go-containerregistry/pkg/v1/v1util", + "Rev": "3165313d6d3f973ec0b0ed3ec5a63b520e065d40" }, { "ImportPath": "github.com/google/gofuzz", diff --git a/vendor/github.com/google/go-containerregistry/authn/BUILD.bazel b/vendor/github.com/google/go-containerregistry/authn/BUILD.bazel deleted file mode 100644 index a2271da965d1..000000000000 --- a/vendor/github.com/google/go-containerregistry/authn/BUILD.bazel +++ /dev/null @@ -1,31 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") - -go_library( - name = "go_default_library", - srcs = [ - "anon.go", - "auth.go", - "authn.go", - "basic.go", - "bearer.go", - "doc.go", - "helper.go", - "keychain.go", - ], - importpath = "github.com/google/go-containerregistry/authn", - visibility = ["//visibility:public"], - deps = ["//name:go_default_library"], -) - -go_test( - name = "go_default_test", - srcs = [ - "anon_test.go", - "basic_test.go", - "bearer_test.go", - "helper_test.go", - "keychain_test.go", - ], - embed = [":go_default_library"], - deps = ["//name:go_default_library"], -) diff --git a/vendor/github.com/google/go-containerregistry/name/BUILD.bazel b/vendor/github.com/google/go-containerregistry/name/BUILD.bazel deleted file mode 100644 index d9d54aa3cbe8..000000000000 --- a/vendor/github.com/google/go-containerregistry/name/BUILD.bazel +++ /dev/null @@ -1,28 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") - -go_library( - name = "go_default_library", - srcs = [ - "check.go", - "digest.go", - "errors.go", - "ref.go", - "registry.go", - "repository.go", - "tag.go", - ], - importpath = "github.com/google/go-containerregistry/name", - visibility = ["//visibility:public"], -) - -go_test( - name = "go_default_test", - srcs = [ - "digest_test.go", - "ref_test.go", - "registry_test.go", - "repository_test.go", - "tag_test.go", - ], - embed = [":go_default_library"], -) diff --git a/vendor/github.com/google/go-containerregistry/authn/anon.go b/vendor/github.com/google/go-containerregistry/pkg/authn/anon.go similarity index 100% rename from vendor/github.com/google/go-containerregistry/authn/anon.go rename to vendor/github.com/google/go-containerregistry/pkg/authn/anon.go diff --git a/vendor/github.com/google/go-containerregistry/authn/auth.go b/vendor/github.com/google/go-containerregistry/pkg/authn/auth.go similarity index 100% rename from vendor/github.com/google/go-containerregistry/authn/auth.go rename to vendor/github.com/google/go-containerregistry/pkg/authn/auth.go diff --git a/vendor/github.com/google/go-containerregistry/authn/authn.go b/vendor/github.com/google/go-containerregistry/pkg/authn/authn.go similarity index 100% rename from vendor/github.com/google/go-containerregistry/authn/authn.go rename to vendor/github.com/google/go-containerregistry/pkg/authn/authn.go diff --git a/vendor/github.com/google/go-containerregistry/authn/basic.go b/vendor/github.com/google/go-containerregistry/pkg/authn/basic.go similarity index 100% rename from vendor/github.com/google/go-containerregistry/authn/basic.go rename to vendor/github.com/google/go-containerregistry/pkg/authn/basic.go diff --git a/vendor/github.com/google/go-containerregistry/authn/bearer.go b/vendor/github.com/google/go-containerregistry/pkg/authn/bearer.go similarity index 100% rename from vendor/github.com/google/go-containerregistry/authn/bearer.go rename to vendor/github.com/google/go-containerregistry/pkg/authn/bearer.go diff --git a/vendor/github.com/google/go-containerregistry/authn/doc.go b/vendor/github.com/google/go-containerregistry/pkg/authn/doc.go similarity index 100% rename from vendor/github.com/google/go-containerregistry/authn/doc.go rename to vendor/github.com/google/go-containerregistry/pkg/authn/doc.go diff --git a/vendor/github.com/google/go-containerregistry/authn/helper.go b/vendor/github.com/google/go-containerregistry/pkg/authn/helper.go similarity index 95% rename from vendor/github.com/google/go-containerregistry/authn/helper.go rename to vendor/github.com/google/go-containerregistry/pkg/authn/helper.go index 5b2467ae83cb..4a8ec24042d3 100644 --- a/vendor/github.com/google/go-containerregistry/authn/helper.go +++ b/vendor/github.com/google/go-containerregistry/pkg/authn/helper.go @@ -21,7 +21,7 @@ import ( "os/exec" "strings" - "github.com/google/go-containerregistry/name" + "github.com/google/go-containerregistry/pkg/name" ) // magicNotFoundMessage is the string that the CLI special cases to mean @@ -72,17 +72,19 @@ func (h *helper) Authorization() (string, error) { var out bytes.Buffer cmd.Stdout = &out - if err := h.r.Run(cmd); err != nil { - return "", err - } - output := out.String() + err := h.r.Run(cmd) // If we see this specific message, it means the domain wasn't found // and we should fall back on anonymous auth. + output := strings.TrimSpace(out.String()) if output == magicNotFoundMessage { return Anonymous.Authorization() } + if err != nil { + return "", err + } + // Any other output should be parsed as JSON and the Username / Secret // fields used for Basic authentication. ho := helperOutput{} diff --git a/vendor/github.com/google/go-containerregistry/authn/keychain.go b/vendor/github.com/google/go-containerregistry/pkg/authn/keychain.go similarity index 81% rename from vendor/github.com/google/go-containerregistry/authn/keychain.go rename to vendor/github.com/google/go-containerregistry/pkg/authn/keychain.go index c7c6a15074b8..aee1fedb9944 100644 --- a/vendor/github.com/google/go-containerregistry/authn/keychain.go +++ b/vendor/github.com/google/go-containerregistry/pkg/authn/keychain.go @@ -16,14 +16,15 @@ package authn import ( "encoding/json" + "errors" "fmt" "io/ioutil" "log" "os" - "os/user" - "path" + "path/filepath" + "runtime" - "github.com/google/go-containerregistry/name" + "github.com/google/go-containerregistry/pkg/name" ) // Keychain is an interface for resolving an image reference to a credential. @@ -41,11 +42,22 @@ func configDir() (string, error) { if dc := os.Getenv("DOCKER_CONFIG"); dc != "" { return dc, nil } - usr, err := user.Current() - if err != nil { - return "", err + if h := dockerUserHomeDir(); h != "" { + return filepath.Join(dockerUserHomeDir(), ".docker"), nil + } + return "", errNoHomeDir +} + +var errNoHomeDir = errors.New("could not determine home directory") + +// dockerUserHomeDir returns the current user's home directory, as interpreted by Docker. +func dockerUserHomeDir() string { + if runtime.GOOS == "windows" { + // Docker specifically expands "%USERPROFILE%" on Windows, + return os.Getenv("USERPROFILE") } - return path.Join(usr.HomeDir, ".docker"), nil + // Docker defaults to "$HOME" Linux and OSX. + return os.Getenv("HOME") } // authEntry is a helper for JSON parsing an "auth" entry of config.json @@ -88,19 +100,19 @@ var ( func (dk *defaultKeychain) Resolve(reg name.Registry) (Authenticator, error) { dir, err := configDir() if err != nil { - log.Printf("Unable to determine config dir, falling back on anonymous: %v", err) + log.Printf("Unable to determine config dir: %v", err) return Anonymous, nil } - file := path.Join(dir, "config.json") + file := filepath.Join(dir, "config.json") content, err := ioutil.ReadFile(file) if err != nil { - log.Printf("Unable to read %q, falling back on anonymous: %v", file, err) + log.Printf("Unable to read %q: %v", file, err) return Anonymous, nil } var cf cfg if err := json.Unmarshal(content, &cf); err != nil { - log.Printf("Unable to parse %q, falling back on anonymous: %v", file, err) + log.Printf("Unable to parse %q: %v", file, err) return Anonymous, nil } @@ -135,6 +147,6 @@ func (dk *defaultKeychain) Resolve(reg name.Registry) (Authenticator, error) { } } - log.Printf("No matching credentials found for %v, falling back on anoynmous", reg) + // Fallback on anonymous. return Anonymous, nil } diff --git a/vendor/github.com/google/go-containerregistry/pkg/authn/multikeychain.go b/vendor/github.com/google/go-containerregistry/pkg/authn/multikeychain.go new file mode 100644 index 000000000000..9d7fb3145cf3 --- /dev/null +++ b/vendor/github.com/google/go-containerregistry/pkg/authn/multikeychain.go @@ -0,0 +1,45 @@ +// 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 authn + +import ( + "github.com/google/go-containerregistry/pkg/name" +) + +type multiKeychain struct { + keychains []Keychain +} + +// Assert that our multi-keychain implements Keychain. +var _ (Keychain) = (*multiKeychain)(nil) + +// NewMultiKeychain composes a list of keychains into one new keychain. +func NewMultiKeychain(kcs ...Keychain) Keychain { + return &multiKeychain{keychains: kcs} +} + +// Resolve implements Keychain. +func (mk *multiKeychain) Resolve(reg name.Registry) (Authenticator, error) { + for _, kc := range mk.keychains { + auth, err := kc.Resolve(reg) + if err != nil { + return nil, err + } + if auth != Anonymous { + return auth, nil + } + } + return Anonymous, nil +} diff --git a/vendor/github.com/google/go-containerregistry/name/check.go b/vendor/github.com/google/go-containerregistry/pkg/name/check.go similarity index 100% rename from vendor/github.com/google/go-containerregistry/name/check.go rename to vendor/github.com/google/go-containerregistry/pkg/name/check.go diff --git a/vendor/github.com/google/go-containerregistry/name/digest.go b/vendor/github.com/google/go-containerregistry/pkg/name/digest.go similarity index 100% rename from vendor/github.com/google/go-containerregistry/name/digest.go rename to vendor/github.com/google/go-containerregistry/pkg/name/digest.go diff --git a/vendor/github.com/google/go-containerregistry/name/errors.go b/vendor/github.com/google/go-containerregistry/pkg/name/errors.go similarity index 100% rename from vendor/github.com/google/go-containerregistry/name/errors.go rename to vendor/github.com/google/go-containerregistry/pkg/name/errors.go diff --git a/vendor/github.com/google/go-containerregistry/name/ref.go b/vendor/github.com/google/go-containerregistry/pkg/name/ref.go similarity index 96% rename from vendor/github.com/google/go-containerregistry/name/ref.go rename to vendor/github.com/google/go-containerregistry/pkg/name/ref.go index 356d79eb69ea..58775daa300c 100644 --- a/vendor/github.com/google/go-containerregistry/name/ref.go +++ b/vendor/github.com/google/go-containerregistry/pkg/name/ref.go @@ -45,5 +45,6 @@ func ParseReference(s string, strict Strictness) (Reference, error) { if d, err := NewDigest(s, strict); err == nil { return d, nil } + // TODO: Combine above errors into something more useful? return nil, errors.New("could not parse reference") } diff --git a/vendor/github.com/google/go-containerregistry/name/registry.go b/vendor/github.com/google/go-containerregistry/pkg/name/registry.go similarity index 59% rename from vendor/github.com/google/go-containerregistry/name/registry.go rename to vendor/github.com/google/go-containerregistry/pkg/name/registry.go index 7618b3f27e6e..c2bf5758a616 100644 --- a/vendor/github.com/google/go-containerregistry/name/registry.go +++ b/vendor/github.com/google/go-containerregistry/pkg/name/registry.go @@ -14,12 +14,29 @@ package name -import "net/url" +import ( + "net/url" + "regexp" + "strings" +) -const DefaultRegistry = "index.docker.io" +const ( + DefaultRegistry = "index.docker.io" + defaultRegistryAlias = "docker.io" +) + +// Detect more complex forms of local references. +var reLocal = regexp.MustCompile(`.*\.local(?:host)?(?::\d{1,5})?$`) + +// Detect the loopback IP (127.0.0.1) +var reLoopback = regexp.MustCompile(regexp.QuoteMeta("127.0.0.1")) + +// Detect the loopback IPV6 (::1) +var reipv6Loopback = regexp.MustCompile(regexp.QuoteMeta("::1")) // Registry stores a docker registry name in a structured form. type Registry struct { + insecure bool registry string } @@ -46,6 +63,26 @@ func (r Registry) Scope(string) string { return "registry:catalog:*" } +// Scheme returns https scheme for all the endpoints except localhost or when explicitly defined. +func (r Registry) Scheme() string { + if r.insecure { + return "http" + } + if strings.HasPrefix(r.Name(), "localhost:") { + return "http" + } + if reLocal.MatchString(r.Name()) { + return "http" + } + if reLoopback.MatchString(r.Name()) { + return "http" + } + if reipv6Loopback.MatchString(r.Name()) { + return "http" + } + return "https" +} + func checkRegistry(name string) error { // Per RFC 3986, registries (authorities) are required to be prefixed with "//" // url.Host == hostname[:port] == authority @@ -65,5 +102,23 @@ func NewRegistry(name string, strict Strictness) (Registry, error) { if err := checkRegistry(name); err != nil { return Registry{}, err } + + // Rewrite "docker.io" to "index.docker.io". + // See: https://github.com/google/go-containerregistry/issues/68 + if name == defaultRegistryAlias { + name = DefaultRegistry + } + return Registry{registry: name}, nil } + +// NewInsecureRegistry returns an Insecure Registry based on the given name. +// Strict validation requires explicit, valid RFC 3986 URI authorities to be given. +func NewInsecureRegistry(name string, strict Strictness) (Registry, error) { + reg, err := NewRegistry(name, strict) + if err != nil { + return Registry{}, err + } + reg.insecure = true + return reg, nil +} diff --git a/vendor/github.com/google/go-containerregistry/name/repository.go b/vendor/github.com/google/go-containerregistry/pkg/name/repository.go similarity index 98% rename from vendor/github.com/google/go-containerregistry/name/repository.go rename to vendor/github.com/google/go-containerregistry/pkg/name/repository.go index 7c296e394a75..43cc5b82b3fb 100644 --- a/vendor/github.com/google/go-containerregistry/name/repository.go +++ b/vendor/github.com/google/go-containerregistry/pkg/name/repository.go @@ -79,7 +79,7 @@ func NewRepository(name string, strict Strictness) (Repository, error) { if len(parts) == 2 && (strings.ContainsRune(parts[0], '.') || strings.ContainsRune(parts[0], ':')) { // The first part of the repository is treated as the registry domain // iff it contains a '.' or ':' character, otherwise it is all repository - // and the domain defaults to DockerHub. + // and the domain defaults to Docker Hub. registry = parts[0] repo = parts[1] } diff --git a/vendor/github.com/google/go-containerregistry/name/tag.go b/vendor/github.com/google/go-containerregistry/pkg/name/tag.go similarity index 91% rename from vendor/github.com/google/go-containerregistry/name/tag.go rename to vendor/github.com/google/go-containerregistry/pkg/name/tag.go index cb0e70b177ce..b8375e1f9bde 100644 --- a/vendor/github.com/google/go-containerregistry/name/tag.go +++ b/vendor/github.com/google/go-containerregistry/pkg/name/tag.go @@ -76,7 +76,9 @@ func NewTag(name string, strict Strictness) (Tag, error) { tag := "" // Split on ":" - if parts := strings.Split(name, tagDelim); len(parts) >= 2 { + parts := strings.Split(name, tagDelim) + // Verify that we aren't confusing a tag for a hostname w/ port for the purposes of weak validation. + if len(parts) > 1 && !strings.Contains(parts[len(parts)-1], regRepoDelimiter) { base = strings.Join(parts[:len(parts)-1], tagDelim) tag = parts[len(parts)-1] } diff --git a/vendor/github.com/google/go-containerregistry/v1/config.go b/vendor/github.com/google/go-containerregistry/pkg/v1/config.go similarity index 59% rename from vendor/github.com/google/go-containerregistry/v1/config.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/config.go index 4fa65155ec03..d1d809d911ce 100644 --- a/vendor/github.com/google/go-containerregistry/v1/config.go +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/config.go @@ -26,7 +26,7 @@ import ( type ConfigFile struct { Architecture string `json:"architecture"` Container string `json:"container"` - Created time.Time `json:"created"` + Created Time `json:"created"` DockerVersion string `json:"docker_version"` History []History `json:"history"` OS string `json:"os"` @@ -38,11 +38,23 @@ type ConfigFile struct { // History is one entry of a list recording how this container image was built. type History struct { - Author string `json:"author"` - Created time.Time `json:"created"` - CreatedBy string `json:"created_by"` - Comment string `json:"comment"` - EmptyLayer bool `json:"empty_layer,omitempty"` + Author string `json:"author"` + Created Time `json:"created"` + CreatedBy string `json:"created_by"` + Comment string `json:"comment"` + EmptyLayer bool `json:"empty_layer,omitempty"` +} + +// Time is a wrapper around time.Time to help with deep copying +type Time struct { + time.Time +} + +// DeepCopyInto creates a deep-copy of the Time value. The underlying time.Time +// type is effectively immutable in the time API, so it is safe to +// copy-by-assign, despite the presence of (unexported) Pointer fields. +func (t *Time) DeepCopyInto(out *Time) { + *out = *t } // RootFS holds the ordered list of file system deltas that comprise the @@ -52,6 +64,27 @@ type RootFS struct { DiffIDs []Hash `json:"diff_ids"` } +// HealthConfig holds configuration settings for the HEALTHCHECK feature. +type HealthConfig struct { + // Test is the test to perform to check that the container is healthy. + // An empty slice means to inherit the default. + // The options are: + // {} : inherit healthcheck + // {"NONE"} : disable healthcheck + // {"CMD", args...} : exec arguments directly + // {"CMD-SHELL", command} : run command with system's default shell + Test []string `json:",omitempty"` + + // Zero means to inherit. Durations are expressed as integer nanoseconds. + Interval time.Duration `json:",omitempty"` // Interval is the time to wait between checks. + Timeout time.Duration `json:",omitempty"` // Timeout is the time to wait before considering the check to have hung. + StartPeriod time.Duration `json:",omitempty"` // The start period for the container to initialize before the retries starts to count down. + + // Retries is the number of consecutive failures needed to consider a container as unhealthy. + // Zero means inherit. + Retries int `json:",omitempty"` +} + // Config is a submessage of the config file described as: // The execution parameters which SHOULD be used as a base when running // a container using the image. @@ -65,9 +98,10 @@ type Config struct { AttachStdin bool AttachStdout bool Cmd []string + Healthcheck *HealthConfig Domainname string Entrypoint []string - End []string + Env []string Hostname string Image string Labels map[string]string @@ -86,9 +120,8 @@ type Config struct { Shell []string } -// ParseConfigFile parses the io.ReadCloser's contents into a ConfigFile. -func ParseConfigFile(r io.ReadCloser) (*ConfigFile, error) { - defer r.Close() +// ParseConfigFile parses the io.Reader's contents into a ConfigFile. +func ParseConfigFile(r io.Reader) (*ConfigFile, error) { cf := ConfigFile{} if err := json.NewDecoder(r).Decode(&cf); err != nil { return nil, err diff --git a/vendor/github.com/google/go-containerregistry/v1/doc.go b/vendor/github.com/google/go-containerregistry/pkg/v1/doc.go similarity index 84% rename from vendor/github.com/google/go-containerregistry/v1/doc.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/doc.go index 2aa71c57d28d..c9b203173e09 100644 --- a/vendor/github.com/google/go-containerregistry/v1/doc.go +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/doc.go @@ -13,4 +13,7 @@ // limitations under the License. // Package v1 defines structured types for OCI v1 images +// +k8s:deepcopy-gen=package + +//go:generate deepcopy-gen -O zz_deepcopy_generated --go-header-file $BOILER_PLATE_FILE -i . package v1 diff --git a/vendor/github.com/google/go-containerregistry/v1/hash.go b/vendor/github.com/google/go-containerregistry/pkg/v1/hash.go similarity index 95% rename from vendor/github.com/google/go-containerregistry/v1/hash.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/hash.go index 71f57bec058a..f0db0d51cfa0 100644 --- a/vendor/github.com/google/go-containerregistry/v1/hash.go +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/hash.go @@ -97,9 +97,8 @@ func (h *Hash) parse(unquoted string) error { return nil } -// SHA256 computes the Hash of the provided io.ReadCloser's content. -func SHA256(r io.ReadCloser) (Hash, int64, error) { - defer r.Close() +// SHA256 computes the Hash of the provided io.Reader's content. +func SHA256(r io.Reader) (Hash, int64, error) { hasher := sha256.New() n, err := io.Copy(hasher, r) if err != nil { diff --git a/vendor/github.com/google/go-containerregistry/v1/image.go b/vendor/github.com/google/go-containerregistry/pkg/v1/image.go similarity index 93% rename from vendor/github.com/google/go-containerregistry/v1/image.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/image.go index 9f7381cc30d4..05568aae0cc1 100644 --- a/vendor/github.com/google/go-containerregistry/v1/image.go +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/image.go @@ -15,13 +15,13 @@ package v1 import ( - "github.com/google/go-containerregistry/v1/types" + "github.com/google/go-containerregistry/pkg/v1/types" ) // Image defines the interface for interacting with an OCI v1 image. type Image interface { // Layers returns the ordered collection of filesystem layers that comprise this image. - // The order of the list is most-recent first, and oldest base layer last. + // The order of the list is oldest/base layer first, and most-recent/top layer last. Layers() ([]Layer, error) // BlobSet returns an unordered collection of all the blobs in the image. diff --git a/vendor/github.com/google/go-containerregistry/v1/remote/transport/scheme.go b/vendor/github.com/google/go-containerregistry/pkg/v1/index.go similarity index 50% rename from vendor/github.com/google/go-containerregistry/v1/remote/transport/scheme.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/index.go index b9d1dd3bf0f0..25ba29ed70e3 100644 --- a/vendor/github.com/google/go-containerregistry/v1/remote/transport/scheme.go +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/index.go @@ -12,31 +12,22 @@ // See the License for the specific language governing permissions and // limitations under the License. -package transport +package v1 import ( - "regexp" - "strings" - - "github.com/google/go-containerregistry/name" + "github.com/google/go-containerregistry/pkg/v1/types" ) -// Detect more complex forms of local references. -var reLocal = regexp.MustCompile(`.*\.local(?:host)?(?::\d{1,5})?$`) +type ImageIndex interface { + // MediaType of this image's manifest. + MediaType() (types.MediaType, error) + + // Digest returns the sha256 of this index's manifest. + Digest() (Hash, error) -// Detect the loopback IP (127.0.0.1) -var reLoopback = regexp.MustCompile(regexp.QuoteMeta("127.0.0.1")) + // IndexManifest returns this image index's manifest object. + IndexManifest() (*IndexManifest, error) -// Scheme returns https scheme for all the endpoints except localhost. -func Scheme(reg name.Registry) string { - if strings.HasPrefix(reg.Name(), "localhost:") { - return "http" - } - if reLocal.MatchString(reg.Name()) { - return "http" - } - if reLoopback.MatchString(reg.Name()) { - return "http" - } - return "https" + // RawIndexManifest returns the serialized bytes of IndexManifest(). + RawIndexManifest() ([]byte, error) } diff --git a/vendor/github.com/google/go-containerregistry/v1/layer.go b/vendor/github.com/google/go-containerregistry/pkg/v1/layer.go similarity index 100% rename from vendor/github.com/google/go-containerregistry/v1/layer.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/layer.go diff --git a/vendor/github.com/google/go-containerregistry/v1/manifest.go b/vendor/github.com/google/go-containerregistry/pkg/v1/manifest.go similarity index 64% rename from vendor/github.com/google/go-containerregistry/v1/manifest.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/manifest.go index 0cb6070a2ce9..932ae056a15d 100644 --- a/vendor/github.com/google/go-containerregistry/v1/manifest.go +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/manifest.go @@ -18,7 +18,7 @@ import ( "encoding/json" "io" - "github.com/google/go-containerregistry/v1/types" + "github.com/google/go-containerregistry/pkg/v1/types" ) // Manifest represents the OCI image manifest in a structured way. @@ -30,6 +30,14 @@ type Manifest struct { Annotations map[string]string `json:"annotations,omitempty"` } +// IndexManifest represents an OCI image index in a structured way. +type IndexManifest struct { + SchemaVersion int64 `json:"schemaVersion"` + MediaType types.MediaType `json:"mediaType,omitempty"` + Manifests []Descriptor `json:"manifests"` + Annotations map[string]string `json:"annotations,omitempty"` +} + // Descriptor holds a reference from the manifest to one of its constituent elements. type Descriptor struct { MediaType types.MediaType `json:"mediaType"` @@ -37,14 +45,23 @@ type Descriptor struct { Digest Hash `json:"digest"` URLs []string `json:"urls,omitempty"` Annotations map[string]string `json:"annotations,omitempty"` + Platform *Platform `json:"platform,omitempty"` } -// ParseManifest parses the io.ReadCloser's contents into a Manifest. -func ParseManifest(r io.ReadCloser) (*Manifest, error) { - defer r.Close() +// ParseManifest parses the io.Reader's contents into a Manifest. +func ParseManifest(r io.Reader) (*Manifest, error) { m := Manifest{} if err := json.NewDecoder(r).Decode(&m); err != nil { return nil, err } return &m, nil } + +// ParseIndexManifest parses the io.Reader's contents into an IndexManifest. +func ParseIndexManifest(r io.Reader) (*IndexManifest, error) { + im := IndexManifest{} + if err := json.NewDecoder(r).Decode(&im); err != nil { + return nil, err + } + return &im, nil +} diff --git a/vendor/github.com/google/go-containerregistry/v1/partial/compressed.go b/vendor/github.com/google/go-containerregistry/pkg/v1/partial/compressed.go similarity index 93% rename from vendor/github.com/google/go-containerregistry/v1/partial/compressed.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/partial/compressed.go index 6ee5ce85e60c..e6e4f4d42f6a 100644 --- a/vendor/github.com/google/go-containerregistry/v1/partial/compressed.go +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/partial/compressed.go @@ -17,8 +17,8 @@ package partial import ( "io" - "github.com/google/go-containerregistry/v1" - "github.com/google/go-containerregistry/v1/v1util" + "github.com/google/go-containerregistry/pkg/v1" + "github.com/google/go-containerregistry/pkg/v1/v1util" ) // CompressedLayer represents the bare minimum interface a natively @@ -50,10 +50,16 @@ func (ule *compressedLayerExtender) Uncompressed() (io.ReadCloser, error) { // DiffID implements v1.Layer func (ule *compressedLayerExtender) DiffID() (v1.Hash, error) { + // If our nested CompressedLayer implements DiffID, + // then delegate to it instead. + if wdi, ok := ule.CompressedLayer.(WithDiffID); ok { + return wdi.DiffID() + } r, err := ule.Uncompressed() if err != nil { return v1.Hash{}, err } + defer r.Close() h, _, err := v1.SHA256(r) return h, err } diff --git a/vendor/github.com/google/go-containerregistry/v1/partial/doc.go b/vendor/github.com/google/go-containerregistry/pkg/v1/partial/doc.go similarity index 100% rename from vendor/github.com/google/go-containerregistry/v1/partial/doc.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/partial/doc.go diff --git a/vendor/github.com/google/go-containerregistry/v1/partial/image.go b/vendor/github.com/google/go-containerregistry/pkg/v1/partial/image.go similarity index 94% rename from vendor/github.com/google/go-containerregistry/v1/partial/image.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/partial/image.go index b82ea36b69b4..5d6da39d24ce 100644 --- a/vendor/github.com/google/go-containerregistry/v1/partial/image.go +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/partial/image.go @@ -15,7 +15,7 @@ package partial import ( - "github.com/google/go-containerregistry/v1/types" + "github.com/google/go-containerregistry/pkg/v1/types" ) // imageCore is the core set of properties without which we cannot build a v1.Image diff --git a/vendor/github.com/google/go-containerregistry/v1/partial/uncompressed.go b/vendor/github.com/google/go-containerregistry/pkg/v1/partial/uncompressed.go similarity index 94% rename from vendor/github.com/google/go-containerregistry/v1/partial/uncompressed.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/partial/uncompressed.go index 444dc93a5c2e..7afa187b872d 100644 --- a/vendor/github.com/google/go-containerregistry/v1/partial/uncompressed.go +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/partial/uncompressed.go @@ -19,9 +19,9 @@ import ( "io" "sync" - "github.com/google/go-containerregistry/v1" - "github.com/google/go-containerregistry/v1/types" - "github.com/google/go-containerregistry/v1/v1util" + "github.com/google/go-containerregistry/pkg/v1" + "github.com/google/go-containerregistry/pkg/v1/types" + "github.com/google/go-containerregistry/pkg/v1/v1util" ) // UncompressedLayer represents the bare minimum interface a natively @@ -56,6 +56,7 @@ func (ule *uncompressedLayerExtender) Digest() (v1.Hash, error) { if err != nil { return v1.Hash{}, err } + defer r.Close() h, _, err := v1.SHA256(r) return h, err } @@ -66,6 +67,7 @@ func (ule *uncompressedLayerExtender) Size() (int64, error) { if err != nil { return -1, err } + defer r.Close() _, i, err := v1.SHA256(r) return i, err } @@ -126,7 +128,8 @@ func (i *uncompressedImageExtender) Manifest() (*v1.Manifest, error) { if err != nil { return nil, err } - cfgHash, cfgSize, err := v1.SHA256(v1util.NopReadCloser(bytes.NewBuffer(b))) + + cfgHash, cfgSize, err := v1.SHA256(bytes.NewReader(b)) if err != nil { return nil, err } @@ -146,7 +149,8 @@ func (i *uncompressedImageExtender) Manifest() (*v1.Manifest, error) { return nil, err } - for _, l := range ls { + m.Layers = make([]v1.Descriptor, len(ls)) + for i, l := range ls { sz, err := l.Size() if err != nil { return nil, err @@ -155,11 +159,12 @@ func (i *uncompressedImageExtender) Manifest() (*v1.Manifest, error) { if err != nil { return nil, err } - m.Layers = append(m.Layers, v1.Descriptor{ + + m.Layers[i] = v1.Descriptor{ MediaType: types.DockerLayer, Size: sz, Digest: h, - }) + } } i.manifest = m diff --git a/vendor/github.com/google/go-containerregistry/v1/partial/with.go b/vendor/github.com/google/go-containerregistry/pkg/v1/partial/with.go similarity index 92% rename from vendor/github.com/google/go-containerregistry/v1/partial/with.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/partial/with.go index 4c0a90097cf0..bc6fd8e9f56e 100644 --- a/vendor/github.com/google/go-containerregistry/v1/partial/with.go +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/partial/with.go @@ -19,10 +19,9 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" - "github.com/google/go-containerregistry/v1" - "github.com/google/go-containerregistry/v1/v1util" + "github.com/google/go-containerregistry/pkg/v1" + "github.com/google/go-containerregistry/pkg/v1/v1util" ) // WithRawConfigFile defines the subset of v1.Image used by these helper methods @@ -37,7 +36,7 @@ func ConfigFile(i WithRawConfigFile) (*v1.ConfigFile, error) { if err != nil { return nil, err } - return v1.ParseConfigFile(v1util.NopReadCloser(bytes.NewBuffer(b))) + return v1.ParseConfigFile(bytes.NewReader(b)) } // ConfigName is a helper for implementing v1.Image @@ -46,7 +45,7 @@ func ConfigName(i WithRawConfigFile) (v1.Hash, error) { if err != nil { return v1.Hash{}, err } - h, _, err := v1.SHA256(v1util.NopReadCloser(bytes.NewBuffer(b))) + h, _, err := v1.SHA256(bytes.NewReader(b)) return h, err } @@ -111,11 +110,7 @@ func DiffIDs(i WithConfigFile) ([]v1.Hash, error) { if err != nil { return nil, err } - dids := make([]v1.Hash, len(cfg.RootFS.DiffIDs)) - for i, did := range cfg.RootFS.DiffIDs { - dids[len(dids)-i-1] = did - } - return dids, nil + return cfg.RootFS.DiffIDs, nil } // RawConfigFile is a helper for implementing v1.Image @@ -154,7 +149,7 @@ func Digest(i WithRawManifest) (v1.Hash, error) { if err != nil { return v1.Hash{}, err } - digest, _, err := v1.SHA256(ioutil.NopCloser(bytes.NewReader(mb))) + digest, _, err := v1.SHA256(bytes.NewReader(mb)) return digest, err } @@ -164,7 +159,7 @@ func Manifest(i WithRawManifest) (*v1.Manifest, error) { if err != nil { return nil, err } - return v1.ParseManifest(v1util.NopReadCloser(bytes.NewBuffer(b))) + return v1.ParseManifest(bytes.NewReader(b)) } // WithManifest defines the subset of v1.Image used by these helper methods @@ -190,7 +185,7 @@ func FSLayers(i WithManifest) ([]v1.Hash, error) { } fsl := make([]v1.Hash, len(m.Layers)) for i, l := range m.Layers { - fsl[len(fsl)-i-1] = l.Digest + fsl[i] = l.Digest } return fsl, nil } @@ -290,3 +285,8 @@ func UncompressedBlob(b WithBlob, h v1.Hash) (io.ReadCloser, error) { } return v1util.GunzipReadCloser(rc) } + +// WithDiffID defines the subset of v1.Layer for exposing the DiffID method. +type WithDiffID interface { + DiffID() (v1.Hash, error) +} diff --git a/vendor/github.com/google/go-containerregistry/pkg/v1/platform.go b/vendor/github.com/google/go-containerregistry/pkg/v1/platform.go new file mode 100644 index 000000000000..df9b2959e396 --- /dev/null +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/platform.go @@ -0,0 +1,24 @@ +// 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 v1 + +// Platform represents the target os/arch for an image. +type Platform struct { + Architecture string `json:"architecture"` + OS string `json:"os"` + OSVersion string `json:"os.version,omitempty"` + OSFeatures []string `json:"os.features,omitempty"` + Variant string `json:"variant,omitempty"` +} diff --git a/vendor/github.com/google/go-containerregistry/v1/remote/delete.go b/vendor/github.com/google/go-containerregistry/pkg/v1/remote/delete.go similarity index 83% rename from vendor/github.com/google/go-containerregistry/v1/remote/delete.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/remote/delete.go index 48f2c44a8f3b..5108a05dea97 100644 --- a/vendor/github.com/google/go-containerregistry/v1/remote/delete.go +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/remote/delete.go @@ -20,9 +20,9 @@ import ( "net/http" "net/url" - "github.com/google/go-containerregistry/authn" - "github.com/google/go-containerregistry/name" - "github.com/google/go-containerregistry/v1/remote/transport" + "github.com/google/go-containerregistry/pkg/authn" + "github.com/google/go-containerregistry/pkg/name" + "github.com/google/go-containerregistry/pkg/v1/remote/transport" ) // DeleteOptions are used to expose optional information to guide or @@ -34,14 +34,15 @@ type DeleteOptions struct { // Delete removes the specified image reference from the remote registry. func Delete(ref name.Reference, auth authn.Authenticator, t http.RoundTripper, do DeleteOptions) error { - tr, err := transport.New(ref, auth, t, transport.DeleteScope) + scopes := []string{ref.Scope(transport.DeleteScope)} + tr, err := transport.New(ref.Context().Registry, auth, t, scopes) if err != nil { return err } c := &http.Client{Transport: tr} u := url.URL{ - Scheme: transport.Scheme(ref.Context().Registry), + Scheme: ref.Context().Registry.Scheme(), Host: ref.Context().RegistryStr(), Path: fmt.Sprintf("/v2/%s/manifests/%s", ref.Context().RepositoryStr(), ref.Identifier()), } diff --git a/vendor/github.com/google/go-containerregistry/v1/remote/doc.go b/vendor/github.com/google/go-containerregistry/pkg/v1/remote/doc.go similarity index 100% rename from vendor/github.com/google/go-containerregistry/v1/remote/doc.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/remote/doc.go diff --git a/vendor/github.com/google/go-containerregistry/v1/remote/error.go b/vendor/github.com/google/go-containerregistry/pkg/v1/remote/error.go similarity index 98% rename from vendor/github.com/google/go-containerregistry/v1/remote/error.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/remote/error.go index 8c4b814e247f..076274821e8d 100644 --- a/vendor/github.com/google/go-containerregistry/v1/remote/error.go +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/remote/error.go @@ -83,7 +83,7 @@ const ( UnsupportedErrorCode ErrorCode = "UNSUPPORTED" ) -func checkError(resp *http.Response, codes ...int) error { +func CheckError(resp *http.Response, codes ...int) error { for _, code := range codes { if resp.StatusCode == code { // This is one of the supported status codes. diff --git a/vendor/github.com/google/go-containerregistry/v1/remote/image.go b/vendor/github.com/google/go-containerregistry/pkg/v1/remote/image.go similarity index 68% rename from vendor/github.com/google/go-containerregistry/v1/remote/image.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/remote/image.go index 4b5dcee4015c..e2995a00f56d 100644 --- a/vendor/github.com/google/go-containerregistry/v1/remote/image.go +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/remote/image.go @@ -19,18 +19,17 @@ import ( "fmt" "io" "io/ioutil" - "log" "net/http" "net/url" "sync" - "github.com/google/go-containerregistry/authn" - "github.com/google/go-containerregistry/name" - "github.com/google/go-containerregistry/v1" - "github.com/google/go-containerregistry/v1/partial" - "github.com/google/go-containerregistry/v1/remote/transport" - "github.com/google/go-containerregistry/v1/types" - "github.com/google/go-containerregistry/v1/v1util" + "github.com/google/go-containerregistry/pkg/authn" + "github.com/google/go-containerregistry/pkg/name" + "github.com/google/go-containerregistry/pkg/v1" + "github.com/google/go-containerregistry/pkg/v1/partial" + "github.com/google/go-containerregistry/pkg/v1/remote/transport" + "github.com/google/go-containerregistry/pkg/v1/types" + "github.com/google/go-containerregistry/pkg/v1/v1util" ) // remoteImage accesses an image from a remote registry @@ -43,23 +42,58 @@ type remoteImage struct { config []byte } +type ImageOption func(*imageOpener) error + var _ partial.CompressedImageCore = (*remoteImage)(nil) -// Image accesses a given image reference over the provided transport, with the provided authentication. -func Image(ref name.Reference, auth authn.Authenticator, t http.RoundTripper) (v1.Image, error) { - tr, err := transport.New(ref, auth, t, transport.PullScope) +type imageOpener struct { + auth authn.Authenticator + transport http.RoundTripper + ref name.Reference + client *http.Client +} + +func (i *imageOpener) Open() (v1.Image, error) { + tr, err := transport.New(i.ref.Context().Registry, i.auth, i.transport, []string{i.ref.Scope(transport.PullScope)}) if err != nil { return nil, err } - return partial.CompressedToImage(&remoteImage{ - ref: ref, + ri := &remoteImage{ + ref: i.ref, client: &http.Client{Transport: tr}, - }) + } + imgCore, err := partial.CompressedToImage(ri) + if err != nil { + return imgCore, err + } + // Wrap the v1.Layers returned by this v1.Image in a hint for downstream + // remote.Write calls to facilitate cross-repo "mounting". + return &mountableImage{ + Image: imgCore, + Reference: i.ref, + }, nil +} + +// Image provides access to a remote image reference, applying functional options +// to the underlying imageOpener before resolving the reference into a v1.Image. +func Image(ref name.Reference, options ...ImageOption) (v1.Image, error) { + img := &imageOpener{ + auth: authn.Anonymous, + transport: http.DefaultTransport, + ref: ref, + } + + for _, option := range options { + if err := option(img); err != nil { + return nil, err + } + } + return img.Open() } func (r *remoteImage) url(resource, identifier string) url.URL { return url.URL{ - Scheme: transport.Scheme(r.ref.Context().Registry), + Scheme: r.ref.Context().Registry.Scheme(), Host: r.ref.Context().RegistryStr(), Path: fmt.Sprintf("/v2/%s/%s/%s", r.ref.Context().RepositoryStr(), resource, identifier), } @@ -91,7 +125,7 @@ func (r *remoteImage) RawManifest() ([]byte, error) { } defer resp.Body.Close() - if err := checkError(resp, http.StatusOK); err != nil { + if err := CheckError(resp, http.StatusOK); err != nil { return nil, err } @@ -100,7 +134,7 @@ func (r *remoteImage) RawManifest() ([]byte, error) { return nil, err } - digest, _, err := v1.SHA256(ioutil.NopCloser(bytes.NewReader(manifest))) + digest, _, err := v1.SHA256(bytes.NewReader(manifest)) if err != nil { return nil, err } @@ -114,7 +148,6 @@ func (r *remoteImage) RawManifest() ([]byte, error) { err := fmt.Errorf("manifest digest: %q does not match Docker-Content-Digest: %q for %q", digest, checksum, r.ref) if r.ref.Context().RegistryStr() == name.DefaultRegistry { // TODO(docker/distribution#2395): Remove this check. - log.Println(err) } else { // When pulling by tag, we can only validate that the digest matches what the registry told us it should be. return nil, err @@ -173,7 +206,7 @@ func (rl *remoteLayer) Compressed() (io.ReadCloser, error) { return nil, err } - if err := checkError(resp, http.StatusOK); err != nil { + if err := CheckError(resp, http.StatusOK); err != nil { resp.Body.Close() return nil, err } @@ -192,6 +225,17 @@ func (rl *remoteLayer) Size() (int64, error) { return partial.BlobSize(rl, rl.digest) } +// ConfigFile implements partial.WithManifestAndConfigFile so that we can use partial.BlobToDiffID below. +func (rl *remoteLayer) ConfigFile() (*v1.ConfigFile, error) { + return partial.ConfigFile(rl.ri) +} + +// DiffID implements partial.WithDiffID so that we don't recompute a DiffID that we already have +// available in our ConfigFile. +func (rl *remoteLayer) DiffID() (v1.Hash, error) { + return partial.BlobToDiffID(rl, rl.digest) +} + // LayerByDigest implements partial.CompressedLayer func (r *remoteImage) LayerByDigest(h v1.Hash) (partial.CompressedLayer, error) { return &remoteLayer{ diff --git a/vendor/github.com/google/go-containerregistry/pkg/v1/remote/list.go b/vendor/github.com/google/go-containerregistry/pkg/v1/remote/list.go new file mode 100644 index 000000000000..17c00b5e762e --- /dev/null +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/remote/list.go @@ -0,0 +1,64 @@ +// 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 remote + +import ( + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/google/go-containerregistry/pkg/authn" + "github.com/google/go-containerregistry/pkg/name" + "github.com/google/go-containerregistry/pkg/v1/remote/transport" +) + +type Tags struct { + Name string `json:"name"` + Tags []string `json:"tags"` +} + +// TODO(jonjohnsonjr): return []name.Tag? +func List(repo name.Repository, auth authn.Authenticator, t http.RoundTripper) ([]string, error) { + scopes := []string{repo.Scope(transport.PullScope)} + tr, err := transport.New(repo.Registry, auth, t, scopes) + if err != nil { + return nil, err + } + + uri := url.URL{ + Scheme: repo.Registry.Scheme(), + Host: repo.Registry.RegistryStr(), + Path: fmt.Sprintf("/v2/%s/tags/list", repo.RepositoryStr()), + } + + client := http.Client{Transport: tr} + resp, err := client.Get(uri.String()) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + if err := CheckError(resp, http.StatusOK); err != nil { + return nil, err + } + + tags := Tags{} + if err := json.NewDecoder(resp.Body).Decode(&tags); err != nil { + return nil, err + } + + return tags.Tags, nil +} diff --git a/vendor/github.com/google/go-containerregistry/pkg/v1/remote/mount.go b/vendor/github.com/google/go-containerregistry/pkg/v1/remote/mount.go new file mode 100644 index 000000000000..13b79064da0a --- /dev/null +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/remote/mount.go @@ -0,0 +1,77 @@ +// 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 remote + +import ( + "github.com/google/go-containerregistry/pkg/name" + "github.com/google/go-containerregistry/pkg/v1" +) + +// MountableLayer wraps a v1.Layer in a shim that enables the layer to be +// "mounted" when published to another registry. +type MountableLayer struct { + v1.Layer + + Reference name.Reference +} + +// mountableImage wraps the v1.Layer references returned by the embedded v1.Image +// in MountableLayer's so that remote.Write might attempt to mount them from their +// source repository. +type mountableImage struct { + v1.Image + + Reference name.Reference +} + +// Layers implements v1.Image +func (mi *mountableImage) Layers() ([]v1.Layer, error) { + ls, err := mi.Image.Layers() + if err != nil { + return nil, err + } + mls := make([]v1.Layer, 0, len(ls)) + for _, l := range ls { + mls = append(mls, &MountableLayer{ + Layer: l, + Reference: mi.Reference, + }) + } + return mls, nil +} + +// LayerByDigest implements v1.Image +func (mi *mountableImage) LayerByDigest(d v1.Hash) (v1.Layer, error) { + l, err := mi.Image.LayerByDigest(d) + if err != nil { + return nil, err + } + return &MountableLayer{ + Layer: l, + Reference: mi.Reference, + }, nil +} + +// LayerByDiffID implements v1.Image +func (mi *mountableImage) LayerByDiffID(d v1.Hash) (v1.Layer, error) { + l, err := mi.Image.LayerByDiffID(d) + if err != nil { + return nil, err + } + return &MountableLayer{ + Layer: l, + Reference: mi.Reference, + }, nil +} diff --git a/vendor/github.com/google/go-containerregistry/pkg/v1/remote/options.go b/vendor/github.com/google/go-containerregistry/pkg/v1/remote/options.go new file mode 100644 index 000000000000..a6e9584ee3bf --- /dev/null +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/remote/options.go @@ -0,0 +1,56 @@ +// 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 remote + +import ( + "log" + "net/http" + + "github.com/google/go-containerregistry/pkg/authn" +) + +// WithTransport is a functional option for overriding the default transport +// on a remote image +func WithTransport(t http.RoundTripper) ImageOption { + return func(i *imageOpener) error { + i.transport = t + return nil + } +} + +// WithAuth is a functional option for overriding the default authenticator +// on a remote image +func WithAuth(auth authn.Authenticator) ImageOption { + return func(i *imageOpener) error { + i.auth = auth + return nil + } +} + +// WithAuthFromKeychain is a functional option for overriding the default +// authenticator on a remote image using an authn.Keychain +func WithAuthFromKeychain(keys authn.Keychain) ImageOption { + return func(i *imageOpener) error { + auth, err := keys.Resolve(i.ref.Context().Registry) + if err != nil { + return err + } + if auth == authn.Anonymous { + log.Println("No matching credentials were found, falling back on anonymous") + } + i.auth = auth + return nil + } +} diff --git a/vendor/github.com/google/go-containerregistry/v1/remote/transport/basic.go b/vendor/github.com/google/go-containerregistry/pkg/v1/remote/transport/basic.go similarity index 96% rename from vendor/github.com/google/go-containerregistry/v1/remote/transport/basic.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/remote/transport/basic.go index a9ab46beb33d..752038cb1fd0 100644 --- a/vendor/github.com/google/go-containerregistry/v1/remote/transport/basic.go +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/remote/transport/basic.go @@ -17,7 +17,7 @@ package transport import ( "net/http" - "github.com/google/go-containerregistry/authn" + "github.com/google/go-containerregistry/pkg/authn" ) type basicTransport struct { diff --git a/vendor/github.com/google/go-containerregistry/v1/remote/transport/bearer.go b/vendor/github.com/google/go-containerregistry/pkg/v1/remote/transport/bearer.go similarity index 76% rename from vendor/github.com/google/go-containerregistry/v1/remote/transport/bearer.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/remote/transport/bearer.go index febe7dc8a9d8..7dd49ae6f859 100644 --- a/vendor/github.com/google/go-containerregistry/v1/remote/transport/bearer.go +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/remote/transport/bearer.go @@ -15,13 +15,15 @@ package transport import ( + "fmt" + "encoding/json" "io/ioutil" "net/http" "net/url" - "github.com/google/go-containerregistry/authn" - "github.com/google/go-containerregistry/name" + "github.com/google/go-containerregistry/pkg/authn" + "github.com/google/go-containerregistry/pkg/name" ) type bearerTransport struct { @@ -37,7 +39,7 @@ type bearerTransport struct { realm string // See https://docs.docker.com/registry/spec/auth/token/ service string - scope string + scopes []string } var _ http.RoundTripper = (*bearerTransport)(nil) @@ -75,7 +77,7 @@ func (bt *bearerTransport) refresh() error { client := http.Client{Transport: b} u.RawQuery = url.Values{ - "scope": []string{bt.scope}, + "scope": bt.scopes, "service": []string{bt.service}, }.Encode() @@ -90,12 +92,28 @@ func (bt *bearerTransport) refresh() error { return err } - // Parse the response into a Bearer authenticator - bearer := &authn.Bearer{} - if err := json.Unmarshal(content, bearer); err != nil { + // Some registries don't have "token" in the response. See #54. + type tokenResponse struct { + Token string `json:"token"` + AccessToken string `json:"access_token"` + } + + var response tokenResponse + if err := json.Unmarshal(content, &response); err != nil { return err } + + // Find a token to turn into a Bearer authenticator + var bearer authn.Bearer + if response.Token != "" { + bearer = authn.Bearer{Token: response.Token} + } else if response.AccessToken != "" { + bearer = authn.Bearer{Token: response.AccessToken} + } else { + return fmt.Errorf("no token in bearer response:\n%s", content) + } + // Replace our old bearer authenticator (if we had one) with our newly refreshed authenticator. - bt.bearer = bearer + bt.bearer = &bearer return nil } diff --git a/vendor/github.com/google/go-containerregistry/v1/remote/transport/doc.go b/vendor/github.com/google/go-containerregistry/pkg/v1/remote/transport/doc.go similarity index 100% rename from vendor/github.com/google/go-containerregistry/v1/remote/transport/doc.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/remote/transport/doc.go diff --git a/vendor/github.com/google/go-containerregistry/v1/remote/transport/ping.go b/vendor/github.com/google/go-containerregistry/pkg/v1/remote/transport/ping.go similarity index 85% rename from vendor/github.com/google/go-containerregistry/v1/remote/transport/ping.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/remote/transport/ping.go index 82d754649066..89133e32637d 100644 --- a/vendor/github.com/google/go-containerregistry/v1/remote/transport/ping.go +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/remote/transport/ping.go @@ -19,15 +19,15 @@ import ( "net/http" "strings" - "github.com/google/go-containerregistry/name" + "github.com/google/go-containerregistry/pkg/name" ) type challenge string const ( - anonymous challenge = "Anonymous" - basic challenge = "Basic" - bearer challenge = "Bearer" + anonymous challenge = "anonymous" + basic challenge = "basic" + bearer challenge = "bearer" ) type pingResp struct { @@ -38,6 +38,10 @@ type pingResp struct { parameters map[string]string } +func (c challenge) Canonical() challenge { + return challenge(strings.ToLower(string(c))) +} + func parseChallenge(suffix string) map[string]string { kv := make(map[string]string) for _, token := range strings.Split(suffix, ",") { @@ -59,7 +63,7 @@ func parseChallenge(suffix string) map[string]string { func ping(reg name.Registry, t http.RoundTripper) (*pingResp, error) { client := http.Client{Transport: t} - url := fmt.Sprintf("%s://%s/v2/", Scheme(reg), reg.Name()) + url := fmt.Sprintf("%s://%s/v2/", reg.Scheme(), reg.Name()) resp, err := client.Get(url) if err != nil { return nil, err @@ -75,13 +79,13 @@ func ping(reg name.Registry, t http.RoundTripper) (*pingResp, error) { if parts := strings.SplitN(wac, " ", 2); len(parts) == 2 { // If there are two parts, then parse the challenge parameters. return &pingResp{ - challenge: challenge(strings.Title(parts[0])), + challenge: challenge(parts[0]).Canonical(), parameters: parseChallenge(parts[1]), }, nil } // Otherwise, just return the challenge without parameters. return &pingResp{ - challenge: challenge(strings.Title(wac)), + challenge: challenge(wac).Canonical(), }, nil default: return nil, fmt.Errorf("unrecognized HTTP status: %v", resp.Status) diff --git a/vendor/github.com/google/go-containerregistry/v1/remote/transport/scope.go b/vendor/github.com/google/go-containerregistry/pkg/v1/remote/transport/scope.go similarity index 73% rename from vendor/github.com/google/go-containerregistry/v1/remote/transport/scope.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/remote/transport/scope.go index 7f5a8bf0a5a7..c3b56f7a41c1 100644 --- a/vendor/github.com/google/go-containerregistry/v1/remote/transport/scope.go +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/remote/transport/scope.go @@ -14,14 +14,11 @@ package transport -// Scope is an enumeration of the supported scopes to pass a transport. -type Scope string - -// Scopes suitable to pass to New() +// Scopes suitable to qualify each Repository const ( - PullScope Scope = "pull" - PushScope Scope = "push,pull" + PullScope string = "pull" + PushScope string = "push,pull" // For now DELETE is PUSH, which is the read/write ACL. - DeleteScope Scope = PushScope - CatalogScope Scope = "catalog" + DeleteScope string = PushScope + CatalogScope string = "catalog" ) diff --git a/vendor/github.com/google/go-containerregistry/v1/remote/transport/transport.go b/vendor/github.com/google/go-containerregistry/pkg/v1/remote/transport/transport.go similarity index 78% rename from vendor/github.com/google/go-containerregistry/v1/remote/transport/transport.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/remote/transport/transport.go index 9ef17ac1c2d0..6140ab2ce3e5 100644 --- a/vendor/github.com/google/go-containerregistry/v1/remote/transport/transport.go +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/remote/transport/transport.go @@ -18,8 +18,8 @@ import ( "fmt" "net/http" - "github.com/google/go-containerregistry/authn" - "github.com/google/go-containerregistry/name" + "github.com/google/go-containerregistry/pkg/authn" + "github.com/google/go-containerregistry/pkg/name" ) const ( @@ -27,9 +27,9 @@ const ( ) // New returns a new RoundTripper based on the provided RoundTripper that has been -// setup to authenticate with the remote registry hosting "ref", in the capacity -// laid out by the specified Scope. -func New(ref name.Reference, auth authn.Authenticator, t http.RoundTripper, a Scope) (http.RoundTripper, error) { +// setup to authenticate with the remote registry "reg", in the capacity +// laid out by the specified scopes. +func New(reg name.Registry, auth authn.Authenticator, t http.RoundTripper, scopes []string) (http.RoundTripper, error) { // The handshake: // 1. Use "t" to ping() the registry for the authentication challenge. // @@ -44,16 +44,16 @@ func New(ref name.Reference, auth authn.Authenticator, t http.RoundTripper, a Sc // First we ping the registry to determine the parameters of the authentication handshake // (if one is even necessary). - pr, err := ping(ref.Context().Registry, t) + pr, err := ping(reg, t) if err != nil { return nil, err } - switch pr.challenge { + switch pr.challenge.Canonical() { case anonymous: return t, nil case basic: - return &basicTransport{inner: t, auth: auth, target: ref.Context().RegistryStr()}, nil + return &basicTransport{inner: t, auth: auth, target: reg.RegistryStr()}, nil case bearer: // We require the realm, which tells us where to send our Basic auth to turn it into Bearer auth. realm, ok := pr.parameters["realm"] @@ -64,15 +64,15 @@ func New(ref name.Reference, auth authn.Authenticator, t http.RoundTripper, a Sc if !ok { // If the service parameter is not specified, then default it to the registry // with which we are talking. - service = ref.Context().Registry.String() + service = reg.String() } bt := &bearerTransport{ inner: t, basic: auth, realm: realm, - registry: ref.Context().Registry, + registry: reg, service: service, - scope: ref.Scope(string(a)), + scopes: scopes, } if err := bt.refresh(); err != nil { return nil, err diff --git a/vendor/github.com/google/go-containerregistry/v1/remote/write.go b/vendor/github.com/google/go-containerregistry/pkg/v1/remote/write.go similarity index 70% rename from vendor/github.com/google/go-containerregistry/v1/remote/write.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/remote/write.go index fe8eb69c6f5a..af61e361becf 100644 --- a/vendor/github.com/google/go-containerregistry/v1/remote/write.go +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/remote/write.go @@ -22,24 +22,29 @@ import ( "net/http" "net/url" - "github.com/google/go-containerregistry/authn" - "github.com/google/go-containerregistry/name" - "github.com/google/go-containerregistry/v1" - "github.com/google/go-containerregistry/v1/remote/transport" + "github.com/google/go-containerregistry/pkg/authn" + "github.com/google/go-containerregistry/pkg/name" + "github.com/google/go-containerregistry/pkg/v1" + "github.com/google/go-containerregistry/pkg/v1/remote/transport" ) // WriteOptions are used to expose optional information to guide or // control the image write. type WriteOptions struct { - // The set of paths from which to attempt to mount blobs. - MountPaths []name.Repository // TODO(mattmoor): Expose "threads" to limit parallelism? } // Write pushes the provided img to the specified image reference. func Write(ref name.Reference, img v1.Image, auth authn.Authenticator, t http.RoundTripper, wo WriteOptions) error { - tr, err := transport.New(ref, auth, t, transport.PushScope) + + ls, err := img.Layers() + if err != nil { + return err + } + + scopes := scopesForUploadingImage(ref, ls) + tr, err := transport.New(ref.Context().Registry, auth, t, scopes) if err != nil { return err } @@ -93,7 +98,7 @@ type writer struct { // url returns a url.Url for the specified path in the context of this remote image reference. func (w *writer) url(path string) url.URL { return url.URL{ - Scheme: transport.Scheme(w.ref.Context().Registry), + Scheme: w.ref.Context().Registry.Scheme(), Host: w.ref.Context().RegistryStr(), Path: path, } @@ -115,6 +120,26 @@ func (w *writer) nextLocation(resp *http.Response) (string, error) { return resp.Request.URL.ResolveReference(u).String(), nil } +// checkExisting checks if a blob exists already in the repository by making a +// HEAD request to the blob store API. GCR performs an existence check on the +// initiation if "mount" is specified, even if no "from" sources are specified. +// However, this is not broadly applicable to all registries, e.g. ECR. +func (w *writer) checkExisting(h v1.Hash) (bool, error) { + u := w.url(fmt.Sprintf("/v2/%s/blobs/%s", w.ref.Context().RepositoryStr(), h.String())) + + resp, err := w.client.Head(u.String()) + if err != nil { + return false, err + } + defer resp.Body.Close() + + if err := CheckError(resp, http.StatusOK, http.StatusNotFound); err != nil { + return false, err + } + + return resp.StatusCode == http.StatusOK, nil +} + // initiateUpload initiates the blob upload, which starts with a POST that can // optionally include the hash of the layer and a list of repositories from // which that layer might be read. On failure, an error is returned. @@ -126,16 +151,15 @@ func (w *writer) initiateUpload(h v1.Hash) (location string, mounted bool, err e uv := url.Values{ "mount": []string{h.String()}, } - var from []string - for _, m := range w.options.MountPaths { - from = append(from, m.RepositoryStr()) + l, err := w.img.LayerByDigest(h) + if err != nil { + return "", false, err } - // We currently avoid HEAD because it's semi-redundant with the mount that is part - // of initiating the blob upload. GCR will perform an existence check on the initiation - // if "mount" is specified, even if no "from" sources are specified. If this turns out - // to not be broadly applicable then we should replace mounts without "from"s with a HEAD. - if len(from) > 0 { - uv["from"] = from + + if ml, ok := l.(*MountableLayer); ok { + if w.ref.Context().RegistryStr() == ml.Reference.Context().RegistryStr() { + uv["from"] = []string{ml.Reference.Context().RepositoryStr()} + } } u.RawQuery = uv.Encode() @@ -146,7 +170,7 @@ func (w *writer) initiateUpload(h v1.Hash) (location string, mounted bool, err e } defer resp.Body.Close() - if err := checkError(resp, http.StatusCreated, http.StatusAccepted); err != nil { + if err := CheckError(resp, http.StatusCreated, http.StatusAccepted); err != nil { return "", false, err } @@ -189,7 +213,7 @@ func (w *writer) streamBlob(h v1.Hash, streamLocation string) (commitLocation st } defer resp.Body.Close() - if err := checkError(resp, http.StatusNoContent, http.StatusAccepted, http.StatusCreated); err != nil { + if err := CheckError(resp, http.StatusNoContent, http.StatusAccepted, http.StatusCreated); err != nil { return "", err } @@ -219,16 +243,25 @@ func (w *writer) commitBlob(h v1.Hash, location string) (err error) { } defer resp.Body.Close() - return checkError(resp, http.StatusCreated) + return CheckError(resp, http.StatusCreated) } // uploadOne performs a complete upload of a single layer. func (w *writer) uploadOne(h v1.Hash) error { + existing, err := w.checkExisting(h) + if err != nil { + return err + } + if existing { + log.Printf("existing blob: %v", h) + return nil + } + location, mounted, err := w.initiateUpload(h) if err != nil { return err } else if mounted { - log.Printf("mounted %v", h) + log.Printf("mounted blob: %v", h) return nil } @@ -240,7 +273,7 @@ func (w *writer) uploadOne(h v1.Hash) error { if err := w.commitBlob(h, location); err != nil { return err } - log.Printf("pushed %v", h) + log.Printf("pushed blob %v", h) return nil } @@ -270,12 +303,42 @@ func (w *writer) commitImage() error { } defer resp.Body.Close() - if err := checkError(resp, http.StatusOK, http.StatusCreated, http.StatusAccepted); err != nil { + if err := CheckError(resp, http.StatusOK, http.StatusCreated, http.StatusAccepted); err != nil { return err } + + digest, err := w.img.Digest() + if err != nil { + return err + } + // The image was successfully pushed! - log.Printf("pushed %v", w.ref) + log.Printf("%v: digest: %v size: %d", w.ref, digest, len(raw)) return nil } +func scopesForUploadingImage(ref name.Reference, layers []v1.Layer) []string { + // use a map as set to remove duplicates scope strings + scopeSet := map[string]struct{}{} + + for _, l := range layers { + if ml, ok := l.(*MountableLayer); ok { + // we add push scope for ref.Context() after the loop + if ml.Reference.Context() != ref.Context() { + scopeSet[ml.Reference.Context().Scope(transport.PullScope)] = struct{}{} + } + } + } + + scopes := make([]string, 0) + // Push scope should be the first element because a few registries just look at the first scope to determine access. + scopes = append(scopes, ref.Scope(transport.PushScope)) + + for scope, _ := range scopeSet { + scopes = append(scopes, scope) + } + + return scopes +} + // TODO(mattmoor): WriteIndex diff --git a/vendor/github.com/google/go-containerregistry/v1/tarball/doc.go b/vendor/github.com/google/go-containerregistry/pkg/v1/tarball/doc.go similarity index 100% rename from vendor/github.com/google/go-containerregistry/v1/tarball/doc.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/tarball/doc.go diff --git a/vendor/github.com/google/go-containerregistry/v1/tarball/image.go b/vendor/github.com/google/go-containerregistry/pkg/v1/tarball/image.go similarity index 82% rename from vendor/github.com/google/go-containerregistry/v1/tarball/image.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/tarball/image.go index 47126f0f6834..2a62327ce6c4 100644 --- a/vendor/github.com/google/go-containerregistry/v1/tarball/image.go +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/tarball/image.go @@ -25,15 +25,15 @@ import ( "os" "sync" - "github.com/google/go-containerregistry/name" - "github.com/google/go-containerregistry/v1" - "github.com/google/go-containerregistry/v1/partial" - "github.com/google/go-containerregistry/v1/types" - "github.com/google/go-containerregistry/v1/v1util" + "github.com/google/go-containerregistry/pkg/name" + "github.com/google/go-containerregistry/pkg/v1" + "github.com/google/go-containerregistry/pkg/v1/partial" + "github.com/google/go-containerregistry/pkg/v1/types" + "github.com/google/go-containerregistry/pkg/v1/v1util" ) type image struct { - path string + opener Opener td *tarDescriptor config []byte imgDescriptor *singleImageTarDescriptor @@ -51,11 +51,26 @@ type compressedImage struct { manifest *v1.Manifest } +var _ partial.UncompressedImageCore = (*uncompressedImage)(nil) +var _ partial.CompressedImageCore = (*compressedImage)(nil) + +type Opener func() (io.ReadCloser, error) + +func pathOpener(path string) Opener { + return func() (io.ReadCloser, error) { + return os.Open(path) + } +} + +func ImageFromPath(path string, tag *name.Tag) (v1.Image, error) { + return Image(pathOpener(path), tag) +} + // Image exposes an image from the tarball at the provided path. -func Image(path string, tag *name.Tag) (v1.Image, error) { +func Image(opener Opener, tag *name.Tag) (v1.Image, error) { img := &image{ - path: path, - tag: tag, + opener: opener, + tag: tag, } if err := img.loadTarDescriptorAndConfig(); err != nil { return nil, err @@ -121,7 +136,7 @@ func (i *image) areLayersCompressed() (bool, error) { return false, errors.New("0 layers found in image") } layer := i.imgDescriptor.Layers[0] - blob, err := extractFileFromTar(i.path, layer) + blob, err := extractFileFromTar(i.opener, layer) if err != nil { return false, err } @@ -130,7 +145,7 @@ func (i *image) areLayersCompressed() (bool, error) { } func (i *image) loadTarDescriptorAndConfig() error { - td, err := extractFileFromTar(i.path, "manifest.json") + td, err := extractFileFromTar(i.opener, "manifest.json") if err != nil { return err } @@ -145,7 +160,7 @@ func (i *image) loadTarDescriptorAndConfig() error { return err } - cfg, err := extractFileFromTar(i.path, i.imgDescriptor.Config) + cfg, err := extractFileFromTar(i.opener, i.imgDescriptor.Config) if err != nil { return err } @@ -168,8 +183,8 @@ type tarFile struct { io.Closer } -func extractFileFromTar(tarPath string, filePath string) (io.ReadCloser, error) { - f, err := os.Open(tarPath) +func extractFileFromTar(opener Opener, filePath string) (io.ReadCloser, error) { + f, err := opener() if err != nil { return nil, err } @@ -195,7 +210,7 @@ func extractFileFromTar(tarPath string, filePath string) (io.ReadCloser, error) // uncompressedLayerFromTarball implements partial.UncompressedLayer type uncompressedLayerFromTarball struct { diffID v1.Hash - tarPath string + opener Opener filePath string } @@ -206,7 +221,7 @@ func (ulft *uncompressedLayerFromTarball) DiffID() (v1.Hash, error) { // Uncompressed implements partial.UncompressedLayer func (ulft *uncompressedLayerFromTarball) Uncompressed() (io.ReadCloser, error) { - return extractFileFromTar(ulft.tarPath, ulft.filePath) + return extractFileFromTar(ulft.opener, ulft.filePath) } func (i *uncompressedImage) LayerByDiffID(h v1.Hash) (partial.UncompressedLayer, error) { @@ -218,7 +233,7 @@ func (i *uncompressedImage) LayerByDiffID(h v1.Hash) (partial.UncompressedLayer, if diffID == h { return &uncompressedLayerFromTarball{ diffID: diffID, - tarPath: i.path, + opener: i.opener, filePath: i.imgDescriptor.Layers[idx], }, nil } @@ -238,7 +253,7 @@ func (c *compressedImage) Manifest() (*v1.Manifest, error) { return nil, err } - cfgHash, cfgSize, err := v1.SHA256(v1util.NopReadCloser(bytes.NewBuffer(b))) + cfgHash, cfgSize, err := v1.SHA256(bytes.NewReader(b)) if err != nil { return nil, err } @@ -254,10 +269,11 @@ func (c *compressedImage) Manifest() (*v1.Manifest, error) { } for _, p := range c.imgDescriptor.Layers { - l, err := extractFileFromTar(c.path, p) + l, err := extractFileFromTar(c.opener, p) if err != nil { return nil, err } + defer l.Close() sha, size, err := v1.SHA256(l) if err != nil { return nil, err @@ -278,18 +294,18 @@ func (c *compressedImage) RawManifest() ([]byte, error) { // compressedLayerFromTarball implements partial.CompressedLayer type compressedLayerFromTarball struct { digest v1.Hash - tarPath string + opener Opener filePath string } -// DiffID implements partial.CompressedLayer +// Digest implements partial.CompressedLayer func (clft *compressedLayerFromTarball) Digest() (v1.Hash, error) { return clft.digest, nil } // Compressed implements partial.CompressedLayer func (clft *compressedLayerFromTarball) Compressed() (io.ReadCloser, error) { - return extractFileFromTar(clft.tarPath, clft.filePath) + return extractFileFromTar(clft.opener, clft.filePath) } // Size implements partial.CompressedLayer @@ -298,6 +314,7 @@ func (clft *compressedLayerFromTarball) Size() (int64, error) { if err != nil { return -1, err } + defer r.Close() _, i, err := v1.SHA256(r) return i, err } @@ -312,7 +329,7 @@ func (c *compressedImage) LayerByDigest(h v1.Hash) (partial.CompressedLayer, err fp := c.imgDescriptor.Layers[i] return &compressedLayerFromTarball{ digest: h, - tarPath: c.path, + opener: c.opener, filePath: fp, }, nil } diff --git a/vendor/github.com/google/go-containerregistry/pkg/v1/tarball/layer.go b/vendor/github.com/google/go-containerregistry/pkg/v1/tarball/layer.go new file mode 100644 index 000000000000..6d43ff7d49de --- /dev/null +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/tarball/layer.go @@ -0,0 +1,144 @@ +// 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 tarball + +import ( + "compress/gzip" + "io" + "io/ioutil" + "os" + + "github.com/google/go-containerregistry/pkg/v1" + "github.com/google/go-containerregistry/pkg/v1/v1util" +) + +type layer struct { + digest v1.Hash + diffID v1.Hash + size int64 + opener Opener + compressed bool +} + +func (l *layer) Digest() (v1.Hash, error) { + return l.digest, nil +} + +func (l *layer) DiffID() (v1.Hash, error) { + return l.diffID, nil +} + +func (l *layer) Compressed() (io.ReadCloser, error) { + rc, err := l.opener() + if err == nil && !l.compressed { + return v1util.GzipReadCloser(rc) + } + + return rc, err +} + +func (l *layer) Uncompressed() (io.ReadCloser, error) { + rc, err := l.opener() + if err == nil && l.compressed { + return v1util.GunzipReadCloser(rc) + } + + return rc, err +} + +func (l *layer) Size() (int64, error) { + return l.size, nil +} + +// LayerFromFile returns a v1.Layer given a tarball +func LayerFromFile(path string) (v1.Layer, error) { + opener := func() (io.ReadCloser, error) { + return os.Open(path) + } + return LayerFromOpener(opener) +} + +// LayerFromOpener returns a v1.Layer given an Opener function +func LayerFromOpener(opener Opener) (v1.Layer, error) { + rc, err := opener() + if err != nil { + return nil, err + } + defer rc.Close() + + compressed, err := v1util.IsGzipped(rc) + if err != nil { + return nil, err + } + + var digest v1.Hash + var size int64 + if digest, size, err = computeDigest(opener, compressed); err != nil { + return nil, err + } + + diffID, err := computeDiffID(opener, compressed) + if err != nil { + return nil, err + } + + return &layer{ + digest: digest, + diffID: diffID, + size: size, + compressed: compressed, + opener: opener, + }, nil +} + +func computeDigest(opener Opener, compressed bool) (v1.Hash, int64, error) { + rc, err := opener() + if err != nil { + return v1.Hash{}, 0, err + } + defer rc.Close() + + if compressed { + return v1.SHA256(rc) + } + + reader, err := v1util.GzipReadCloser(ioutil.NopCloser(rc)) + if err != nil { + return v1.Hash{}, 0, err + } + + return v1.SHA256(reader) +} + +func computeDiffID(opener Opener, compressed bool) (v1.Hash, error) { + rc, err := opener() + if err != nil { + return v1.Hash{}, err + } + defer rc.Close() + + if !compressed { + digest, _, err := v1.SHA256(rc) + return digest, err + } + + reader, err := gzip.NewReader(rc) + if err != nil { + return v1.Hash{}, err + } + + diffID, _, err := v1.SHA256(reader) + return diffID, err +} diff --git a/vendor/github.com/google/go-containerregistry/v1/tarball/write.go b/vendor/github.com/google/go-containerregistry/pkg/v1/tarball/write.go similarity index 50% rename from vendor/github.com/google/go-containerregistry/v1/tarball/write.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/tarball/write.go index cb84e19d4418..a7f72cd988fa 100644 --- a/vendor/github.com/google/go-containerregistry/v1/tarball/write.go +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/tarball/write.go @@ -18,11 +18,12 @@ import ( "archive/tar" "bytes" "encoding/json" + "fmt" "io" "os" - "github.com/google/go-containerregistry/name" - "github.com/google/go-containerregistry/v1" + "github.com/google/go-containerregistry/pkg/name" + "github.com/google/go-containerregistry/pkg/v1" ) // WriteOptions are used to expose optional information to guide or @@ -31,20 +32,24 @@ type WriteOptions struct { // TODO(mattmoor): Whether to store things compressed? } -// Write saves the image as the given tag in a tarball at the given path. -func Write(p string, tag name.Tag, img v1.Image, wo *WriteOptions) error { - // Write in the compressed format. - // This is a tarball, on-disk, with: - // One manifest.json file at the top level containing information about several images. - // One file for each layer, named after the layer's SHA. - // One file for the config blob, named after its SHA. - - w, err := os.OpenFile(p, os.O_WRONLY, 0644) +// WriteToFile writes in the compressed format to a tarball, on disk. +// This is just syntactic sugar wrapping tarball.Write with a new file. +func WriteToFile(p string, tag name.Tag, img v1.Image, wo *WriteOptions) error { + w, err := os.Create(p) if err != nil { return err } defer w.Close() + return Write(tag, img, wo, w) +} + +// Write the contents of the image to the provided reader, in the compressed format. +// The contents are written in the following format: +// One manifest.json file at the top level containing information about several images. +// One file for each layer, named after the layer's SHA. +// One file for the config blob, named after its SHA. +func Write(tag name.Tag, img v1.Image, wo *WriteOptions, w io.Writer) error { tf := tar.NewWriter(w) defer tf.Close() @@ -53,15 +58,11 @@ func Write(p string, tag name.Tag, img v1.Image, wo *WriteOptions) error { if err != nil { return err } - cfg, err := img.ConfigFile() + cfgBlob, err := img.RawConfigFile() if err != nil { return err } - cfgBlob, err := json.Marshal(cfg) - if err != nil { - return err - } - if err := writeFile(tf, cfgName.String(), bytes.NewReader(cfgBlob), int64(len(cfgBlob))); err != nil { + if err := writeTarEntry(tf, cfgName.String(), bytes.NewReader(cfgBlob), int64(len(cfgBlob))); err != nil { return err } @@ -70,13 +71,24 @@ func Write(p string, tag name.Tag, img v1.Image, wo *WriteOptions) error { if err != nil { return err } - layerPaths := []string{} - for _, l := range layers { + layerFiles := make([]string, len(layers)) + for i, l := range layers { d, err := l.Digest() if err != nil { return err } - layerPaths = append(layerPaths, d.String()) + + // Munge the file name to appease ancient technology. + // + // tar assumes anything with a colon is a remote tape drive: + // https://www.gnu.org/software/tar/manual/html_section/tar_45.html + // Drop the algorithm prefix, e.g. "sha256:" + hex := d.Hex + + // gunzip expects certain file extensions: + // https://www.gnu.org/software/gzip/manual/html_node/Overview.html + layerFiles[i] = fmt.Sprintf("%s.tar.gz", hex) + r, err := l.Compressed() if err != nil { return err @@ -86,7 +98,7 @@ func Write(p string, tag name.Tag, img v1.Image, wo *WriteOptions) error { return err } - if err := writeFile(tf, d.String(), r, blobSize); err != nil { + if err := writeTarEntry(tf, layerFiles[i], r, blobSize); err != nil { return err } } @@ -96,17 +108,18 @@ func Write(p string, tag name.Tag, img v1.Image, wo *WriteOptions) error { singleImageTarDescriptor{ Config: cfgName.String(), RepoTags: []string{tag.String()}, - Layers: layerPaths, + Layers: layerFiles, }, } tdBytes, err := json.Marshal(td) if err != nil { return err } - return writeFile(tf, "manifest.json", bytes.NewReader(tdBytes), int64(len(tdBytes))) + return writeTarEntry(tf, "manifest.json", bytes.NewReader(tdBytes), int64(len(tdBytes))) } -func writeFile(tf *tar.Writer, path string, r io.Reader, size int64) error { +// write a file to the provided writer with a corresponding tar header +func writeTarEntry(tf *tar.Writer, path string, r io.Reader, size int64) error { hdr := &tar.Header{ Mode: 0644, Typeflag: tar.TypeReg, diff --git a/vendor/github.com/google/go-containerregistry/v1/types/types.go b/vendor/github.com/google/go-containerregistry/pkg/v1/types/types.go similarity index 100% rename from vendor/github.com/google/go-containerregistry/v1/types/types.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/types/types.go diff --git a/vendor/github.com/google/go-containerregistry/v1/v1util/and_closer.go b/vendor/github.com/google/go-containerregistry/pkg/v1/v1util/and_closer.go similarity index 100% rename from vendor/github.com/google/go-containerregistry/v1/v1util/and_closer.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/v1util/and_closer.go diff --git a/vendor/github.com/google/go-containerregistry/v1/v1util/nop.go b/vendor/github.com/google/go-containerregistry/pkg/v1/v1util/nop.go similarity index 100% rename from vendor/github.com/google/go-containerregistry/v1/v1util/nop.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/v1util/nop.go diff --git a/vendor/github.com/google/go-containerregistry/v1/v1util/verify.go b/vendor/github.com/google/go-containerregistry/pkg/v1/v1util/verify.go similarity index 97% rename from vendor/github.com/google/go-containerregistry/v1/v1util/verify.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/v1util/verify.go index 610ca5c01b4b..7ebb9dde9f4d 100644 --- a/vendor/github.com/google/go-containerregistry/v1/v1util/verify.go +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/v1util/verify.go @@ -20,7 +20,7 @@ import ( "hash" "io" - "github.com/google/go-containerregistry/v1" + "github.com/google/go-containerregistry/pkg/v1" ) type verifyReader struct { diff --git a/vendor/github.com/google/go-containerregistry/v1/v1util/zip.go b/vendor/github.com/google/go-containerregistry/pkg/v1/v1util/zip.go similarity index 81% rename from vendor/github.com/google/go-containerregistry/v1/v1util/zip.go rename to vendor/github.com/google/go-containerregistry/pkg/v1/v1util/zip.go index d484d32e6ff1..f12d0ed88779 100644 --- a/vendor/github.com/google/go-containerregistry/v1/v1util/zip.go +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/v1util/zip.go @@ -24,17 +24,32 @@ var gzipMagicHeader = []byte{'\x1f', '\x8b'} // GzipReadCloser reads uncompressed input data from the io.ReadCloser and // returns an io.ReadCloser from which compressed data may be read. +// This uses gzip.BestSpeed for the compression level. func GzipReadCloser(r io.ReadCloser) (io.ReadCloser, error) { - defer r.Close() + return GzipReadCloserLevel(r, gzip.BestSpeed) +} - // TODO(mattmoor): How to avoid buffering this whole thing into memory? - data := bytes.NewBuffer(nil) - gw := gzip.NewWriter(data) - defer gw.Close() - if _, err := io.Copy(gw, r); err != nil { - return nil, err - } - return NopReadCloser(data), nil +// GzipReadCloserLevel reads uncompressed input data from the io.ReadCloser and +// returns an io.ReadCloser from which compressed data may be read. +// Refer to compress/gzip for the level: +// https://golang.org/pkg/compress/gzip/#pkg-constants +func GzipReadCloserLevel(r io.ReadCloser, level int) (io.ReadCloser, error) { + pr, pw := io.Pipe() + + go func() { + defer pw.Close() + defer r.Close() + + gw, _ := gzip.NewWriterLevel(pw, level) + defer gw.Close() + + _, err := io.Copy(gw, r) + if err != nil { + pr.CloseWithError(err) + } + }() + + return pr, nil } // GunzipReadCloser reads compressed input data from the io.ReadCloser and diff --git a/vendor/github.com/google/go-containerregistry/pkg/v1/zz_deepcopy_generated.go b/vendor/github.com/google/go-containerregistry/pkg/v1/zz_deepcopy_generated.go new file mode 100644 index 000000000000..3440b5e13069 --- /dev/null +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/zz_deepcopy_generated.go @@ -0,0 +1,314 @@ +// +build !ignore_autogenerated + +// 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. + +// Code generated by deepcopy-gen. DO NOT EDIT. + +package v1 + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Config) DeepCopyInto(out *Config) { + *out = *in + if in.Cmd != nil { + in, out := &in.Cmd, &out.Cmd + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.Healthcheck != nil { + in, out := &in.Healthcheck, &out.Healthcheck + *out = new(HealthConfig) + (*in).DeepCopyInto(*out) + } + if in.Entrypoint != nil { + in, out := &in.Entrypoint, &out.Entrypoint + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.Env != nil { + in, out := &in.Env, &out.Env + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.Labels != nil { + in, out := &in.Labels, &out.Labels + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + if in.OnBuild != nil { + in, out := &in.OnBuild, &out.OnBuild + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.Volumes != nil { + in, out := &in.Volumes, &out.Volumes + *out = make(map[string]struct{}, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + if in.ExposedPorts != nil { + in, out := &in.ExposedPorts, &out.ExposedPorts + *out = make(map[string]struct{}, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + if in.Shell != nil { + in, out := &in.Shell, &out.Shell + *out = make([]string, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Config. +func (in *Config) DeepCopy() *Config { + if in == nil { + return nil + } + out := new(Config) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ConfigFile) DeepCopyInto(out *ConfigFile) { + *out = *in + in.Created.DeepCopyInto(&out.Created) + if in.History != nil { + in, out := &in.History, &out.History + *out = make([]History, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + in.RootFS.DeepCopyInto(&out.RootFS) + in.Config.DeepCopyInto(&out.Config) + in.ContainerConfig.DeepCopyInto(&out.ContainerConfig) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConfigFile. +func (in *ConfigFile) DeepCopy() *ConfigFile { + if in == nil { + return nil + } + out := new(ConfigFile) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Descriptor) DeepCopyInto(out *Descriptor) { + *out = *in + out.Digest = in.Digest + if in.URLs != nil { + in, out := &in.URLs, &out.URLs + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.Annotations != nil { + in, out := &in.Annotations, &out.Annotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + if in.Platform != nil { + in, out := &in.Platform, &out.Platform + *out = new(Platform) + (*in).DeepCopyInto(*out) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Descriptor. +func (in *Descriptor) DeepCopy() *Descriptor { + if in == nil { + return nil + } + out := new(Descriptor) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Hash) DeepCopyInto(out *Hash) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Hash. +func (in *Hash) DeepCopy() *Hash { + if in == nil { + return nil + } + out := new(Hash) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *HealthConfig) DeepCopyInto(out *HealthConfig) { + *out = *in + if in.Test != nil { + in, out := &in.Test, &out.Test + *out = make([]string, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HealthConfig. +func (in *HealthConfig) DeepCopy() *HealthConfig { + if in == nil { + return nil + } + out := new(HealthConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *History) DeepCopyInto(out *History) { + *out = *in + in.Created.DeepCopyInto(&out.Created) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new History. +func (in *History) DeepCopy() *History { + if in == nil { + return nil + } + out := new(History) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IndexManifest) DeepCopyInto(out *IndexManifest) { + *out = *in + if in.Manifests != nil { + in, out := &in.Manifests, &out.Manifests + *out = make([]Descriptor, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.Annotations != nil { + in, out := &in.Annotations, &out.Annotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IndexManifest. +func (in *IndexManifest) DeepCopy() *IndexManifest { + if in == nil { + return nil + } + out := new(IndexManifest) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Manifest) DeepCopyInto(out *Manifest) { + *out = *in + in.Config.DeepCopyInto(&out.Config) + if in.Layers != nil { + in, out := &in.Layers, &out.Layers + *out = make([]Descriptor, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.Annotations != nil { + in, out := &in.Annotations, &out.Annotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Manifest. +func (in *Manifest) DeepCopy() *Manifest { + if in == nil { + return nil + } + out := new(Manifest) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Platform) DeepCopyInto(out *Platform) { + *out = *in + if in.OSFeatures != nil { + in, out := &in.OSFeatures, &out.OSFeatures + *out = make([]string, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Platform. +func (in *Platform) DeepCopy() *Platform { + if in == nil { + return nil + } + out := new(Platform) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RootFS) DeepCopyInto(out *RootFS) { + *out = *in + if in.DiffIDs != nil { + in, out := &in.DiffIDs, &out.DiffIDs + *out = make([]Hash, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RootFS. +func (in *RootFS) DeepCopy() *RootFS { + if in == nil { + return nil + } + out := new(RootFS) + in.DeepCopyInto(out) + return out +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Time. +func (in *Time) DeepCopy() *Time { + if in == nil { + return nil + } + out := new(Time) + in.DeepCopyInto(out) + return out +} diff --git a/vendor/github.com/google/go-containerregistry/v1/BUILD.bazel b/vendor/github.com/google/go-containerregistry/v1/BUILD.bazel deleted file mode 100644 index 9877a0b72b50..000000000000 --- a/vendor/github.com/google/go-containerregistry/v1/BUILD.bazel +++ /dev/null @@ -1,26 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") - -go_library( - name = "go_default_library", - srcs = [ - "config.go", - "doc.go", - "hash.go", - "image.go", - "layer.go", - "manifest.go", - ], - importpath = "github.com/google/go-containerregistry/v1", - visibility = ["//visibility:public"], - deps = ["//v1/types:go_default_library"], -) - -go_test( - name = "go_default_test", - srcs = [ - "hash_test.go", - "manifest_test.go", - ], - embed = [":go_default_library"], - deps = ["//vendor/github.com/google/go-cmp/cmp:go_default_library"], -) diff --git a/vendor/github.com/google/go-containerregistry/v1/partial/BUILD.bazel b/vendor/github.com/google/go-containerregistry/v1/partial/BUILD.bazel deleted file mode 100644 index 1d5f48305acd..000000000000 --- a/vendor/github.com/google/go-containerregistry/v1/partial/BUILD.bazel +++ /dev/null @@ -1,19 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") - -go_library( - name = "go_default_library", - srcs = [ - "compressed.go", - "doc.go", - "image.go", - "uncompressed.go", - "with.go", - ], - importpath = "github.com/google/go-containerregistry/v1/partial", - visibility = ["//visibility:public"], - deps = [ - "//v1:go_default_library", - "//v1/types:go_default_library", - "//v1/v1util:go_default_library", - ], -) diff --git a/vendor/github.com/google/go-containerregistry/v1/remote/BUILD.bazel b/vendor/github.com/google/go-containerregistry/v1/remote/BUILD.bazel deleted file mode 100644 index e063649c5352..000000000000 --- a/vendor/github.com/google/go-containerregistry/v1/remote/BUILD.bazel +++ /dev/null @@ -1,44 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") - -go_library( - name = "go_default_library", - srcs = [ - "delete.go", - "doc.go", - "error.go", - "image.go", - "write.go", - ], - importpath = "github.com/google/go-containerregistry/v1/remote", - visibility = ["//visibility:public"], - deps = [ - "//authn:go_default_library", - "//name:go_default_library", - "//v1:go_default_library", - "//v1/partial:go_default_library", - "//v1/remote/transport:go_default_library", - "//v1/types:go_default_library", - "//v1/v1util:go_default_library", - ], -) - -go_test( - name = "go_default_test", - srcs = [ - "delete_test.go", - "error_test.go", - "image_test.go", - "write_test.go", - ], - embed = [":go_default_library"], - deps = [ - "//authn:go_default_library", - "//name:go_default_library", - "//v1:go_default_library", - "//v1/random:go_default_library", - "//v1/remote/transport:go_default_library", - "//v1/types:go_default_library", - "//v1/v1util:go_default_library", - "//vendor/github.com/google/go-cmp/cmp:go_default_library", - ], -) diff --git a/vendor/github.com/google/go-containerregistry/v1/remote/transport/BUILD.bazel b/vendor/github.com/google/go-containerregistry/v1/remote/transport/BUILD.bazel deleted file mode 100644 index e99b8a6f0430..000000000000 --- a/vendor/github.com/google/go-containerregistry/v1/remote/transport/BUILD.bazel +++ /dev/null @@ -1,37 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") - -go_library( - name = "go_default_library", - srcs = [ - "basic.go", - "bearer.go", - "doc.go", - "ping.go", - "scheme.go", - "scope.go", - "transport.go", - ], - importpath = "github.com/google/go-containerregistry/v1/remote/transport", - visibility = ["//visibility:public"], - deps = [ - "//authn:go_default_library", - "//name:go_default_library", - ], -) - -go_test( - name = "go_default_test", - srcs = [ - "basic_test.go", - "bearer_test.go", - "ping_test.go", - "scheme_test.go", - "transport_test.go", - ], - embed = [":go_default_library"], - deps = [ - "//authn:go_default_library", - "//name:go_default_library", - "//vendor/github.com/google/go-cmp/cmp:go_default_library", - ], -) diff --git a/vendor/github.com/google/go-containerregistry/v1/tarball/BUILD.bazel b/vendor/github.com/google/go-containerregistry/v1/tarball/BUILD.bazel deleted file mode 100644 index b48a7ea6b6db..000000000000 --- a/vendor/github.com/google/go-containerregistry/v1/tarball/BUILD.bazel +++ /dev/null @@ -1,68 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") - -go_library( - name = "go_default_library", - srcs = [ - "doc.go", - "image.go", - "write.go", - ], - importpath = "github.com/google/go-containerregistry/v1/tarball", - visibility = ["//visibility:public"], - deps = [ - "//name:go_default_library", - "//v1:go_default_library", - "//v1/partial:go_default_library", - "//v1/types:go_default_library", - "//v1/v1util:go_default_library", - ], -) - -go_test( - name = "go_default_test", - srcs = [ - "image_test.go", - "write_test.go", - ], - data = glob(["testdata/**"]) + [ - ":test_image_1.tar", # keep - ":test_image_2.tar", # keep - ":test_bundle.tar", # keep - ], - embed = [":go_default_library"], - deps = [ - "//name:go_default_library", - "//v1/random:go_default_library", - "//vendor/github.com/google/go-cmp/cmp:go_default_library", - ], -) - -load( - "@io_bazel_rules_docker//container:container.bzl", - "container_image", - "container_bundle", -) - -container_image( - name = "test_image_1", - files = [ - "testdata/bar", - "testdata/foo", - ], -) - -container_image( - name = "test_image_2", - files = [ - "testdata/bat/bat", - "testdata/baz", - ], -) - -container_bundle( - name = "test_bundle", - images = { - "test_image_1": ":test_image_1", - "test_image_2": ":test_image_2", - }, -) diff --git a/vendor/github.com/google/go-containerregistry/v1/types/BUILD.bazel b/vendor/github.com/google/go-containerregistry/v1/types/BUILD.bazel deleted file mode 100644 index b3f45c41c155..000000000000 --- a/vendor/github.com/google/go-containerregistry/v1/types/BUILD.bazel +++ /dev/null @@ -1,8 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") - -go_library( - name = "go_default_library", - srcs = ["types.go"], - importpath = "github.com/google/go-containerregistry/v1/types", - visibility = ["//visibility:public"], -) diff --git a/vendor/github.com/google/go-containerregistry/v1/v1util/BUILD.bazel b/vendor/github.com/google/go-containerregistry/v1/v1util/BUILD.bazel deleted file mode 100644 index f2c9c8648827..000000000000 --- a/vendor/github.com/google/go-containerregistry/v1/v1util/BUILD.bazel +++ /dev/null @@ -1,25 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") - -go_library( - name = "go_default_library", - srcs = [ - "and_closer.go", - "nop.go", - "verify.go", - "zip.go", - ], - importpath = "github.com/google/go-containerregistry/v1/v1util", - visibility = ["//visibility:public"], - deps = ["//v1:go_default_library"], -) - -go_test( - name = "go_default_test", - srcs = [ - "and_closer_test.go", - "verify_test.go", - "zip_test.go", - ], - embed = [":go_default_library"], - deps = ["//v1:go_default_library"], -) From a8cd8e2a82d2f5d8663a3c1d59dce91c60099a60 Mon Sep 17 00:00:00 2001 From: dlorenc Date: Wed, 22 Aug 2018 08:50:30 -0700 Subject: [PATCH 2/2] Manual changes for go-containerregistry update. --- pkg/minikube/machine/cache_images.go | 23 ++++++++++++----------- test/integration/persistence_test.go | 3 ++- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/pkg/minikube/machine/cache_images.go b/pkg/minikube/machine/cache_images.go index c8dd64798ec3..155782c876fa 100644 --- a/pkg/minikube/machine/cache_images.go +++ b/pkg/minikube/machine/cache_images.go @@ -18,7 +18,6 @@ package machine import ( "io/ioutil" - "net/http" "os" "os/exec" "path" @@ -26,12 +25,12 @@ import ( "runtime" "strings" - "github.com/google/go-containerregistry/v1/tarball" + "github.com/google/go-containerregistry/pkg/v1/tarball" - "github.com/google/go-containerregistry/authn" + "github.com/google/go-containerregistry/pkg/authn" - "github.com/google/go-containerregistry/name" - "github.com/google/go-containerregistry/v1/remote" + "github.com/google/go-containerregistry/pkg/name" + "github.com/google/go-containerregistry/pkg/v1/remote" "golang.org/x/sync/errgroup" @@ -296,14 +295,16 @@ func CacheImage(image, dst string) error { return errors.Wrap(err, "creating docker image name") } - auth, err := authn.DefaultKeychain.Resolve(tag.Registry) - if err != nil { - return errors.Wrap(err, "setting up registry auth") - } - img, err := remote.Image(tag, auth, http.DefaultTransport) + img, err := remote.Image(tag, remote.WithAuthFromKeychain(authn.DefaultKeychain)) if err != nil { return errors.Wrap(err, "fetching remote image") } - return tarball.Write(dstPath, tag, img, nil) + glog.Infoln("OPENING: ", dstPath) + f, err := os.Create(dstPath) + if err != nil { + return err + } + defer f.Close() + return tarball.Write(tag, img, nil, f) } diff --git a/test/integration/persistence_test.go b/test/integration/persistence_test.go index d98dc2a570a1..b63538f7ca41 100644 --- a/test/integration/persistence_test.go +++ b/test/integration/persistence_test.go @@ -20,6 +20,7 @@ package integration import ( "path/filepath" + "strings" "testing" "time" @@ -28,10 +29,10 @@ import ( ) func TestPersistence(t *testing.T) { + minikubeRunner := NewMinikubeRunner(t) if strings.Contains(minikubeRunner.StartArgs, "--vm-driver=none") { t.Skip("skipping test as none driver does not support persistence") } - minikubeRunner := NewMinikubeRunner(t) minikubeRunner.EnsureRunning() kubectlRunner := util.NewKubectlRunner(t)