Skip to content

Commit

Permalink
Fix tagging image built by Jib
Browse files Browse the repository at this point in the history
Fixes GoogleContainerTools#1460

All credits goes to [email protected]

Signed-off-by: David Gageot <[email protected]>
  • Loading branch information
dgageot committed Jan 14, 2019
1 parent ae14267 commit 74b7fe2
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,41 +23,26 @@ 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"
)

func AddTag(src, target string) error {
srcRef, err := name.ParseReference(src, name.WeakValidation)
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.WeakValidation)
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 @@ -94,5 +79,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 74b7fe2

Please sign in to comment.