diff --git a/builder/docker/artifact_import.go b/builder/docker/artifact_import.go index b5f71751b..a53c0a52b 100644 --- a/builder/docker/artifact_import.go +++ b/builder/docker/artifact_import.go @@ -30,7 +30,17 @@ func (a *ImportArtifact) Id() string { } func (a *ImportArtifact) String() string { - tags, _ := a.StateData["docker_tags"].([]string) + var tags []string + switch t := a.StateData["docker_tags"].(type) { + case []string: + tags = t + case []interface{}: + for _, name := range t { + if n, ok := name.(string); ok { + tags = append(tags, n) + } + } + } if len(tags) > 0 { return fmt.Sprintf("Imported Docker image: %s with tags %s", a.Id(), strings.Join(tags, " ")) diff --git a/post-processor/docker-push/post-processor.go b/post-processor/docker-push/post-processor.go index 831ba1a7c..97ffb8627 100644 --- a/post-processor/docker-push/post-processor.go +++ b/post-processor/docker-push/post-processor.go @@ -5,7 +5,6 @@ package dockerpush import ( "context" "fmt" - "github.com/hashicorp/hcl/v2/hcldec" "github.com/hashicorp/packer/builder/docker" "github.com/hashicorp/packer/common" @@ -103,14 +102,21 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact }() } - names := []string{artifact.Id()} - tags, _ := artifact.State("docker_tags").([]interface{}) - for _, tag := range tags { - if name, ok := tag.(string); ok { - names = append(names, name) + var tags []string + switch t := artifact.State("docker_tags").(type) { + case []string: + tags = t + case []interface{}: + for _, name := range t { + if n, ok := name.(string); ok { + tags = append(tags, n) + } } } + names := []string{artifact.Id()} + names = append(names, tags...) + // Get the name. for _, name := range names { ui.Message("Pushing: " + name)