Skip to content

Commit

Permalink
Merge pull request #1464 from dgageot/fix-1460
Browse files Browse the repository at this point in the history
Simplify docker.AddTag()
  • Loading branch information
nkubala authored Jan 17, 2019
2 parents 69776b1 + c1265a9 commit 6de6a34
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions pkg/skaffold/docker/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,28 @@ 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)
if err != nil {
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) {
Expand Down Expand Up @@ -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))
}

0 comments on commit 6de6a34

Please sign in to comment.