improve docker_tags artifact state read

This commit is contained in:
sylviamoss 2020-09-28 10:52:28 +02:00
parent e758891878
commit aa9c162c60
2 changed files with 8 additions and 16 deletions

View File

@ -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{} {

View File

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