From 0a2e8fcadadd2a318f28d0cf2fa676448427cd4e Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Thu, 23 Jun 2022 08:49:33 -0300 Subject: [PATCH] fix: improve docker publish skipping (#3184) Signed-off-by: Carlos A Becker --- internal/pipe/docker/docker.go | 25 +++++++++++++++---------- internal/pipe/docker/docker_test.go | 12 ++++++++---- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/internal/pipe/docker/docker.go b/internal/pipe/docker/docker.go index c01c5bc6a..25c414f65 100644 --- a/internal/pipe/docker/docker.go +++ b/internal/pipe/docker/docker.go @@ -88,13 +88,18 @@ func validateImager(use string) error { // Publish the docker images. func (Pipe) Publish(ctx *context.Context) error { + skips := pipe.SkipMemento{} images := ctx.Artifacts.Filter(artifact.ByType(artifact.PublishableDockerImage)).List() for _, image := range images { if err := dockerPush(ctx, image); err != nil { + if pipe.IsSkip(err) { + skips.Remember(err) + continue + } return err } } - return nil + return skips.Evaluate() } // Run the pipe. @@ -187,15 +192,6 @@ func process(ctx *context.Context, docker config.Docker, artifacts []*artifact.A return err } - if strings.TrimSpace(docker.SkipPush) == "true" { - return pipe.Skip("docker.skip_push is set") - } - if ctx.SkipPublish { - return pipe.ErrSkipPublishEnabled - } - if strings.TrimSpace(docker.SkipPush) == "auto" && ctx.Semver.Prerelease != "" { - return pipe.Skip("prerelease detected with 'auto' push, skipping docker publish") - } for _, img := range images { ctx.Artifacts.Add(&artifact.Artifact{ Type: artifact.PublishableDockerImage, @@ -245,10 +241,19 @@ func processBuildFlagTemplates(ctx *context.Context, docker config.Docker) ([]st func dockerPush(ctx *context.Context, image *artifact.Artifact) error { log.WithField("image", image.Name).Info("pushing") + docker := image.Extra[dockerConfigExtra].(config.Docker) + if strings.TrimSpace(docker.SkipPush) == "true" { + return pipe.Skip("docker.skip_push is set: " + image.Name) + } + if strings.TrimSpace(docker.SkipPush) == "auto" && ctx.Semver.Prerelease != "" { + return pipe.Skip("prerelease detected with 'auto' push, skipping docker publish: " + image.Name) + } + if err := imagers[docker.Use].Push(ctx, image.Name, docker.PushFlags); err != nil { return err } + art := &artifact.Artifact{ Type: artifact.DockerImage, Name: image.Name, diff --git a/internal/pipe/docker/docker_test.go b/internal/pipe/docker/docker_test.go index ab656b9ce..584bb6228 100644 --- a/internal/pipe/docker/docker_test.go +++ b/internal/pipe/docker/docker_test.go @@ -655,8 +655,10 @@ func TestRunPipe(t *testing.T) { expect: []string{ registry + "goreleaser/test_run_pipe:latest", }, - assertImageLabels: noLabels, - assertError: testlib.AssertSkipped, + assertImageLabels: noLabels, + assertError: shouldNotErr, + pubAssertError: testlib.AssertSkipped, + manifestAssertError: shouldNotErr, }, "one_img_error_with_skip_push": { dockers: []config.Docker{ @@ -839,8 +841,10 @@ func TestRunPipe(t *testing.T) { registry + "goreleaser/mybin:v1.0.0-123", registry + "goreleaser/mybin:latest", }, - assertImageLabels: noLabels, - assertError: testlib.AssertSkipped, + assertImageLabels: noLabels, + assertError: shouldNotErr, + pubAssertError: testlib.AssertSkipped, + manifestAssertError: shouldNotErr, }, "no_permissions": { dockers: []config.Docker{