From c1265a9489cfc01b1ee0399edab8ca375ce76c51 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Mon, 14 Jan 2019 16:30:46 -0500 Subject: [PATCH] Fix tagging image built by Jib Fixes #1460 All credits goes to jonjohnson@google.com Signed-off-by: David Gageot --- pkg/skaffold/docker/remote.go | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/pkg/skaffold/docker/remote.go b/pkg/skaffold/docker/remote.go index 5d8d3d7ab65..3c189f4a1b3 100644 --- a/pkg/skaffold/docker/remote.go +++ b/pkg/skaffold/docker/remote.go @@ -23,21 +23,15 @@ import ( "github.com/google/go-containerregistry/pkg/name" v1 "github.com/google/go-containerregistry/pkg/v1" "github.com/google/go-containerregistry/pkg/v1/remote" - "github.com/google/go-containerregistry/pkg/v1/remote/transport" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) func AddTag(src, target string) error { logrus.Debugf("attempting to add tag %s to src %s", target, src) - srcRef, err := name.ParseReference(src, name.StrictValidation) + img, err := remoteImage(src) if err != nil { - return errors.Wrap(err, "getting source reference") - } - - auth, err := authn.DefaultKeychain.Resolve(srcRef.Context().Registry) - if err != nil { - return err + return errors.Wrap(err, "getting image") } targetRef, err := name.ParseReference(target, name.StrictValidation) @@ -45,21 +39,12 @@ func AddTag(src, target string) error { return errors.Wrap(err, "getting target reference") } - return addTag(srcRef, targetRef, auth, http.DefaultTransport) -} - -func addTag(ref name.Reference, targetRef name.Reference, auth authn.Authenticator, t http.RoundTripper) error { - tr, err := transport.New(ref.Context().Registry, auth, t, []string{targetRef.Scope(transport.PushScope)}) - if err != nil { - return err - } - - img, err := remote.Image(ref, remote.WithAuth(auth), remote.WithTransport(tr)) + auth, err := authn.DefaultKeychain.Resolve(targetRef.Context().Registry) if err != nil { return err } - return remote.Write(targetRef, img, auth, t) + return remote.Write(targetRef, img, auth, http.DefaultTransport) } func RemoteDigest(identifier string) (string, error) { @@ -96,5 +81,5 @@ func remoteImage(identifier string) (v1.Image, error) { return nil, errors.Wrap(err, "getting default keychain auth") } - return remote.Image(ref, remote.WithAuth(auth), remote.WithTransport(http.DefaultTransport)) + return remote.Image(ref, remote.WithAuth(auth)) }