1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-11 14:39:28 +02:00

feat: allow to template dockers.skip_push and docker_manifests.skip_push (#4008)

This commit is contained in:
Carlos Alexandro Becker 2023-05-12 01:51:02 -03:00 committed by GitHub
parent dcbe842893
commit 05d25567f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 9 deletions

View File

@ -285,10 +285,14 @@ func dockerPush(ctx *context.Context, image *artifact.Artifact) error {
return err
}
if strings.TrimSpace(docker.SkipPush) == "true" {
skip, err := tmpl.New(ctx).Apply(docker.SkipPush)
if err != nil {
return err
}
if strings.TrimSpace(skip) == "true" {
return pipe.Skip("docker.skip_push is set: " + image.Name)
}
if strings.TrimSpace(docker.SkipPush) == "auto" && ctx.Semver.Prerelease != "" {
if strings.TrimSpace(skip) == "auto" && ctx.Semver.Prerelease != "" {
return pipe.Skip("prerelease detected with 'auto' push, skipping docker publish: " + image.Name)
}

View File

@ -118,6 +118,7 @@ func TestRunPipe(t *testing.T) {
assertImageLabels: noLabels,
},
"manifest autoskip no prerelease": {
env: map[string]string{"AUTO": "auto"},
dockers: []config.Docker{
{
ImageTemplates: []string{registry + "goreleaser/test_manifestskip:test-amd64"},
@ -132,7 +133,7 @@ func TestRunPipe(t *testing.T) {
ImageTemplates: []string{
registry + "goreleaser/test_manifestskip:test-amd64",
},
SkipPush: "auto",
SkipPush: "{{ .Env.AUTO }}",
},
},
expect: []string{
@ -625,6 +626,7 @@ func TestRunPipe(t *testing.T) {
manifestAssertError: shouldNotErr,
},
"valid_skip_push": {
env: map[string]string{"TRUE": "true"},
dockers: []config.Docker{
{
ImageTemplates: []string{
@ -633,7 +635,7 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Goarch: "amd64",
Dockerfile: "testdata/Dockerfile",
SkipPush: "true",
SkipPush: "{{.Env.TRUE}}",
},
},
expect: []string{

View File

@ -60,11 +60,15 @@ 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" {
skip, err := tmpl.New(ctx).Apply(manifest.SkipPush)
if err != nil {
return err
}
if strings.TrimSpace(skip) == "true" {
return pipe.Skip("docker_manifest.skip_push is set")
}
if strings.TrimSpace(manifest.SkipPush) == "auto" && ctx.Semver.Prerelease != "" {
if strings.TrimSpace(skip) == "auto" && ctx.Semver.Prerelease != "" {
return pipe.Skip("prerelease detected with 'auto' push, skipping docker manifest")
}

View File

@ -95,6 +95,8 @@ dockers:
#
# If set to auto, the release will not be pushed to the Docker repository
# in case there is an indicator of a prerelease in the tag, e.g. v1.0.0-rc1.
#
# Templates: allowed (since v1.19)
skip_push: false
# Path to the Dockerfile (from the project root).

View File

@ -53,11 +53,13 @@ docker_manifests:
- --insecure
# Skips the Docker manifest.
# If you set this to `false` or `auto` on your source Docker configs,
# If you set this to `false` or `auto` on your source Docker configuration,
# 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.
#
# Templates: allowed (since v1.19)
skip_push: false
# Set the "backend" for the Docker manifest pipe.
@ -65,8 +67,8 @@ docker_manifests:
#
# Relevant notes:
# 1. podman is a GoReleaser Pro feature and is only available on Linux;
# 2. if you set podman here, the respective docker configs need to use podman
# too.
# 2. if you set podman here, the respective docker configuration need to use
# podman too.
#
# Default: 'docker'
use: docker