1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-09-16 09:26:52 +02:00

feat: docker_manifests.skip_push (#2302)

* feat: docker_manifests.skip_push

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* fix: lint

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* test: fix

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
This commit is contained in:
Carlos Alexandro Becker
2021-06-16 23:00:08 -03:00
committed by GitHub
parent 10f3021afe
commit e437344718
5 changed files with 110 additions and 2 deletions

View File

@@ -146,6 +146,94 @@ func TestRunPipe(t *testing.T) {
manifestAssertError: shouldNotErr,
assertImageLabels: noLabels,
},
"manifest autoskip no prerelease": {
dockers: []config.Docker{
{
ImageTemplates: []string{registry + "goreleaser/test_manifestskip:test-amd64"},
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
},
},
manifests: []config.DockerManifest{
{
NameTemplate: registry + "goreleaser/test_manifestskip:test",
ImageTemplates: []string{
registry + "goreleaser/test_manifestskip:test-amd64",
},
CreateFlags: []string{"--insecure"},
PushFlags: []string{"--insecure"},
SkipPush: "auto",
},
},
expect: []string{
registry + "goreleaser/test_manifestskip:test-amd64",
},
assertError: shouldNotErr,
pubAssertError: shouldNotErr,
manifestAssertError: shouldNotErr,
assertImageLabels: noLabels,
},
"manifest autoskip prerelease": {
dockers: []config.Docker{
{
ImageTemplates: []string{registry + "goreleaser/test_manifestskip-prerelease:test-amd64"},
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
},
},
manifests: []config.DockerManifest{
{
NameTemplate: registry + "goreleaser/test_manifestskip-prerelease:test",
ImageTemplates: []string{
registry + "goreleaser/test_manifestskip-prerelease:test-amd64",
},
CreateFlags: []string{"--insecure"},
PushFlags: []string{"--insecure"},
SkipPush: "auto",
},
},
expect: []string{
registry + "goreleaser/test_manifestskip-prerelease:test-amd64",
},
assertError: shouldNotErr,
pubAssertError: shouldNotErr,
manifestAssertError: testlib.AssertSkipped,
assertImageLabels: noLabels,
extraPrepare: func(t *testing.T, ctx *context.Context) {
t.Helper()
ctx.Semver.Prerelease = "beta"
},
},
"manifest skip": {
dockers: []config.Docker{
{
ImageTemplates: []string{registry + "goreleaser/test_manifestskip-true:test-amd64"},
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
},
},
manifests: []config.DockerManifest{
{
NameTemplate: registry + "goreleaser/test_manifestskip-true:test",
ImageTemplates: []string{
registry + "goreleaser/test_manifestskip-true:test-amd64",
},
CreateFlags: []string{"--insecure"},
PushFlags: []string{"--insecure"},
SkipPush: "true",
},
},
expect: []string{
registry + "goreleaser/test_manifestskip-true:test-amd64",
},
assertError: shouldNotErr,
pubAssertError: shouldNotErr,
manifestAssertError: testlib.AssertSkipped,
assertImageLabels: noLabels,
},
"multiarch with previous existing manifest": {
dockers: []config.Docker{
{

View File

@@ -31,6 +31,12 @@ func (ManifestPipe) Publish(ctx *context.Context) error {
for _, manifest := range ctx.Config.DockerManifests {
manifest := manifest
g.Go(func() error {
if strings.TrimSpace(manifest.SkipPush) == "true" {
return pipe.Skip("docker_manifest.skip_push is set")
}
if strings.TrimSpace(manifest.SkipPush) == "auto" && ctx.Semver.Prerelease != "" {
return pipe.Skip("prerelease detected with 'auto' push, skipping docker manifest")
}
name, err := manifestName(ctx, manifest)
if err != nil {
return err

View File

@@ -518,6 +518,7 @@ type Docker struct {
// DockerManifest config.
type DockerManifest struct {
NameTemplate string `yaml:"name_template,omitempty"`
SkipPush string `yaml:"skip_push,omitempty"`
ImageTemplates []string `yaml:"image_templates,omitempty"`
CreateFlags []string `yaml:"create_flags,omitempty"`
PushFlags []string `yaml:"push_flags,omitempty"`

View File

@@ -70,9 +70,12 @@ dockers:
- "myuser/myimage:v{{ .Major }}"
- "gcr.io/myuser/myimage:latest"
# Skips the docker push. Could be useful if you also do draft releases.
# 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
# in case there is an indicator of a prerelease in the tag, e.g. v1.0.0-rc1.
#
# Defaults to false.
skip_push: false

View File

@@ -47,6 +47,16 @@ docker_manifests:
# Defaults to empty.
push_flags:
- --insecure
# Skips the docker manifest.
# If you set this to 'false' or 'auto' on your source docker configs,
# you'll probably want to do the same here.
#
# If set to 'auto', the manifest will not be created in case there is an
# indicator of a prerelease in the tag, e.g. v1.0.0-rc1.
#
# Defaults to false.
skip_push: false
```
!!! tip