Skip to content

Commit

Permalink
Merge pull request #1475 from nkubala/jib_tagging
Browse files Browse the repository at this point in the history
Fix jib tagging
  • Loading branch information
dgageot authored Jan 16, 2019
2 parents da2090d + 227c4a9 commit 0c8435e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
11 changes: 8 additions & 3 deletions pkg/skaffold/build/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,20 @@ func (b *Builder) runBuildForArtifact(ctx context.Context, out io.Writer, artifa
}
}

func (b *Builder) retagAndPush(ctx context.Context, out io.Writer, initialTag string, newTag string, artifact *latest.Artifact) error {
func (b *Builder) retagAndPush(ctx context.Context, out io.Writer, digest string, newTag string, artifact *latest.Artifact) error {
if b.pushImages && (artifact.JibMavenArtifact != nil || artifact.JibGradleArtifact != nil) {
if err := docker.AddTag(initialTag, newTag); err != nil {
// when pushing images, jib builds them directly to the registry. all we need to do here is add a tag to the remote.

// NOTE: the digest returned by the jib builder when in push mode is the digest of the remote image that was built to the registry.
// when adding the tag to the remote, we need to specify the registry it was built to so go-containerregistry knows
// where to look when grabbing the remote image reference.
if err := docker.AddTag(fmt.Sprintf("%s@%s", artifact.ImageName, digest), newTag); err != nil {
return errors.Wrap(err, "tagging image")
}
return nil
}

if err := b.localDocker.Tag(ctx, initialTag, newTag); err != nil {
if err := b.localDocker.Tag(ctx, digest, newTag); err != nil {
return err
}

Expand Down
8 changes: 5 additions & 3 deletions pkg/skaffold/docker/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ import (
"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 {
srcRef, err := name.ParseReference(src, name.WeakValidation)
logrus.Debugf("attempting to add tag %s to src %s", target, src)
srcRef, err := name.ParseReference(src, name.StrictValidation)
if err != nil {
return errors.Wrap(err, "getting source reference")
}
Expand All @@ -38,7 +40,7 @@ func AddTag(src, target string) error {
return err
}

targetRef, err := name.ParseReference(target, name.WeakValidation)
targetRef, err := name.ParseReference(target, name.StrictValidation)
if err != nil {
return errors.Wrap(err, "getting target reference")
}
Expand Down Expand Up @@ -84,7 +86,7 @@ func retrieveRemoteConfig(identifier string) (*v1.ConfigFile, error) {
}

func remoteImage(identifier string) (v1.Image, error) {
ref, err := name.ParseReference(identifier, name.WeakValidation)
ref, err := name.ParseReference(identifier, name.StrictValidation)
if err != nil {
return nil, errors.Wrap(err, "parsing initial ref")
}
Expand Down

0 comments on commit 0c8435e

Please sign in to comment.