improve docker_tag cast to avoid failures

This commit is contained in:
sylviamoss 2020-09-29 14:25:15 +02:00
parent 49bc7665c1
commit c8874c9382
2 changed files with 23 additions and 7 deletions

View File

@ -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, " "))

View File

@ -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)