diff --git a/internal/pipe/docker/docker.go b/internal/pipe/docker/docker.go index 09559ea83..0e54d810b 100644 --- a/internal/pipe/docker/docker.go +++ b/internal/pipe/docker/docker.go @@ -188,10 +188,18 @@ func process(ctx *context.Context, docker config.Docker, bins []artifact.Artifac if err := dockerBuild(ctx, tmp, images, buildFlags); err != nil { return err } - if docker.SkipPush { - // TODO: this should also be better handled - log.Warn(pipe.Skip("skip_push is set").Error()) - return nil + + if strings.TrimSpace(docker.SkipPush) == "true" { + return pipe.Skip("docker.skip_push is set") + } + if ctx.SkipPublish { + return pipe.ErrSkipPublishEnabled + } + if ctx.Config.Release.Draft { + return pipe.Skip("release is marked as draft") + } + 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{ diff --git a/internal/pipe/docker/docker_test.go b/internal/pipe/docker/docker_test.go index 65013fbef..2f4a42fa8 100644 --- a/internal/pipe/docker/docker_test.go +++ b/internal/pipe/docker/docker_test.go @@ -13,6 +13,7 @@ import ( "github.com/goreleaser/goreleaser/internal/artifact" "github.com/goreleaser/goreleaser/internal/pipe" + "github.com/goreleaser/goreleaser/internal/testlib" "github.com/goreleaser/goreleaser/pkg/config" "github.com/goreleaser/goreleaser/pkg/context" "github.com/stretchr/testify/assert" @@ -223,15 +224,14 @@ func TestRunPipe(t *testing.T) { Goarch: "amd64", Dockerfile: "testdata/Dockerfile", Binaries: []string{"mybin"}, - SkipPush: true, + SkipPush: "true", }, }, expect: []string{ registry + "goreleaser/test_run_pipe:latest", }, assertImageLabels: noLabels, - assertError: shouldNotErr, - pubAssertError: shouldNotErr, + assertError: testlib.AssertSkipped, }, "valid_no_latest": { dockers: []config.Docker{ @@ -384,7 +384,7 @@ func TestRunPipe(t *testing.T) { Goarch: "amd64", Dockerfile: "testdata/Dockerfile", Binaries: []string{"mybin"}, - SkipPush: true, + SkipPush: "true", }, }, env: map[string]string{ @@ -395,8 +395,7 @@ func TestRunPipe(t *testing.T) { registry + "goreleaser/mybin:latest", }, assertImageLabels: noLabels, - assertError: shouldNotErr, - pubAssertError: shouldNotErr, + assertError: testlib.AssertSkipped, }, "no_permissions": { dockers: []config.Docker{ @@ -768,7 +767,7 @@ func Test_processImageTemplates(t *testing.T) { "gcr.io/image:{{.Tag}}-{{.Env.FOO}}", "gcr.io/image:v{{.Major}}.{{.Minor}}", }, - SkipPush: true, + SkipPush: "true", }, }, }, diff --git a/internal/pipe/publish/publish_test.go b/internal/pipe/publish/publish_test.go index d214495f3..9b610d243 100644 --- a/internal/pipe/publish/publish_test.go +++ b/internal/pipe/publish/publish_test.go @@ -23,7 +23,7 @@ func TestPublish(t *testing.T) { var ctx = context.New(config.Project{}) ctx.Config.Release.Disable = true for i := range ctx.Config.Dockers { - ctx.Config.Dockers[i].SkipPush = true + ctx.Config.Dockers[i].SkipPush = "true" } require.NoError(t, Pipe{}.Run(ctx)) } diff --git a/pkg/config/config.go b/pkg/config/config.go index 225ebf0dd..0346c5499 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -251,7 +251,7 @@ type Docker struct { Image string `yaml:",omitempty"` Dockerfile string `yaml:",omitempty"` ImageTemplates []string `yaml:"image_templates,omitempty"` - SkipPush bool `yaml:"skip_push,omitempty"` + SkipPush string `yaml:"skip_push,omitempty"` TagTemplates []string `yaml:"tag_templates,omitempty"` Files []string `yaml:"extra_files,omitempty"` BuildFlagTemplates []string `yaml:"build_flag_templates,omitempty"` diff --git a/www/content/docker.md b/www/content/docker.md index b84f71fd7..eec3547d4 100644 --- a/www/content/docker.md +++ b/www/content/docker.md @@ -65,6 +65,8 @@ dockers: - "myuser/myimage:v{{ .Major }}" - "gcr.io/myuser/myimage:latest" # Skips the docker push. Could be useful if you also do draft releases. + # If set to auto, the release will not be pushed to the docker repository + # in case there is an indicator for prerelease in the tag e.g. v1.0.0-rc1 # Defaults to false. skip_push: false # Path to the Dockerfile (from the project root).