From 227c4a902318f686f8da1360b6dc3a64180859e5 Mon Sep 17 00:00:00 2001 From: Nick Kubala Date: Tue, 15 Jan 2019 13:45:00 -0800 Subject: [PATCH] fix jib tagging --- pkg/skaffold/build/local/local.go | 11 ++++++++--- pkg/skaffold/docker/remote.go | 8 +++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/pkg/skaffold/build/local/local.go b/pkg/skaffold/build/local/local.go index cbe075f407d..99a29d969bb 100644 --- a/pkg/skaffold/build/local/local.go +++ b/pkg/skaffold/build/local/local.go @@ -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 } diff --git a/pkg/skaffold/docker/remote.go b/pkg/skaffold/docker/remote.go index ef029deff11..5d8d3d7ab65 100644 --- a/pkg/skaffold/docker/remote.go +++ b/pkg/skaffold/docker/remote.go @@ -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") } @@ -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") } @@ -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") }