mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-19 20:57:53 +02:00
fix: improve docker publish skipping (#3184)
Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
8424c92102
commit
0a2e8fcada
@ -88,13 +88,18 @@ func validateImager(use string) error {
|
|||||||
|
|
||||||
// Publish the docker images.
|
// Publish the docker images.
|
||||||
func (Pipe) Publish(ctx *context.Context) error {
|
func (Pipe) Publish(ctx *context.Context) error {
|
||||||
|
skips := pipe.SkipMemento{}
|
||||||
images := ctx.Artifacts.Filter(artifact.ByType(artifact.PublishableDockerImage)).List()
|
images := ctx.Artifacts.Filter(artifact.ByType(artifact.PublishableDockerImage)).List()
|
||||||
for _, image := range images {
|
for _, image := range images {
|
||||||
if err := dockerPush(ctx, image); err != nil {
|
if err := dockerPush(ctx, image); err != nil {
|
||||||
|
if pipe.IsSkip(err) {
|
||||||
|
skips.Remember(err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return skips.Evaluate()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run the pipe.
|
// Run the pipe.
|
||||||
@ -187,15 +192,6 @@ func process(ctx *context.Context, docker config.Docker, artifacts []*artifact.A
|
|||||||
return err
|
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 {
|
for _, img := range images {
|
||||||
ctx.Artifacts.Add(&artifact.Artifact{
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
Type: artifact.PublishableDockerImage,
|
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 {
|
func dockerPush(ctx *context.Context, image *artifact.Artifact) error {
|
||||||
log.WithField("image", image.Name).Info("pushing")
|
log.WithField("image", image.Name).Info("pushing")
|
||||||
|
|
||||||
docker := image.Extra[dockerConfigExtra].(config.Docker)
|
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 {
|
if err := imagers[docker.Use].Push(ctx, image.Name, docker.PushFlags); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
art := &artifact.Artifact{
|
art := &artifact.Artifact{
|
||||||
Type: artifact.DockerImage,
|
Type: artifact.DockerImage,
|
||||||
Name: image.Name,
|
Name: image.Name,
|
||||||
|
@ -656,7 +656,9 @@ func TestRunPipe(t *testing.T) {
|
|||||||
registry + "goreleaser/test_run_pipe:latest",
|
registry + "goreleaser/test_run_pipe:latest",
|
||||||
},
|
},
|
||||||
assertImageLabels: noLabels,
|
assertImageLabels: noLabels,
|
||||||
assertError: testlib.AssertSkipped,
|
assertError: shouldNotErr,
|
||||||
|
pubAssertError: testlib.AssertSkipped,
|
||||||
|
manifestAssertError: shouldNotErr,
|
||||||
},
|
},
|
||||||
"one_img_error_with_skip_push": {
|
"one_img_error_with_skip_push": {
|
||||||
dockers: []config.Docker{
|
dockers: []config.Docker{
|
||||||
@ -840,7 +842,9 @@ func TestRunPipe(t *testing.T) {
|
|||||||
registry + "goreleaser/mybin:latest",
|
registry + "goreleaser/mybin:latest",
|
||||||
},
|
},
|
||||||
assertImageLabels: noLabels,
|
assertImageLabels: noLabels,
|
||||||
assertError: testlib.AssertSkipped,
|
assertError: shouldNotErr,
|
||||||
|
pubAssertError: testlib.AssertSkipped,
|
||||||
|
manifestAssertError: shouldNotErr,
|
||||||
},
|
},
|
||||||
"no_permissions": {
|
"no_permissions": {
|
||||||
dockers: []config.Docker{
|
dockers: []config.Docker{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user