From aa9c162c607b90a95335d37ac1f99bddbbc8b827 Mon Sep 17 00:00:00 2001 From: sylviamoss Date: Mon, 28 Sep 2020 10:52:28 +0200 Subject: [PATCH] improve docker_tags artifact state read --- builder/docker/artifact_import.go | 15 +++++---------- post-processor/docker-push/post-processor.go | 9 +++------ 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/builder/docker/artifact_import.go b/builder/docker/artifact_import.go index b6d0b3a5b..b5f71751b 100644 --- a/builder/docker/artifact_import.go +++ b/builder/docker/artifact_import.go @@ -30,17 +30,12 @@ func (a *ImportArtifact) Id() string { } func (a *ImportArtifact) String() string { - tags := a.StateData["docker_tags"] - if tags == nil { - return fmt.Sprintf("Imported Docker image: %s", a.Id()) + tags, _ := a.StateData["docker_tags"].([]string) + if len(tags) > 0 { + return fmt.Sprintf("Imported Docker image: %s with tags %s", + a.Id(), strings.Join(tags, " ")) } - cast := tags.([]string) - names := []string{} - for _, name := range cast { - names = append(names, name) - } - return fmt.Sprintf("Imported Docker image: %s with tags %s", - a.Id(), strings.Join(names, " ")) + return fmt.Sprintf("Imported Docker image: %s", a.Id()) } func (a *ImportArtifact) State(name string) interface{} { diff --git a/post-processor/docker-push/post-processor.go b/post-processor/docker-push/post-processor.go index 440ce2989..5c12e85f3 100644 --- a/post-processor/docker-push/post-processor.go +++ b/post-processor/docker-push/post-processor.go @@ -104,12 +104,9 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact } names := []string{artifact.Id()} - tags := artifact.State("docker_tags") - if tags != nil { - cast := tags.([]string) - for _, name := range cast { - names = append(names, name) - } + tags, _ := artifact.State("docker_tags").([]string) + if len(tags) > 0 { + names = append(names, tags...) } // Get the name.