Merge pull request #9182 from hashicorp/fix_9131

support pushing multiple tags
This commit is contained in:
Megan Marsh 2020-05-07 12:09:19 -07:00 committed by GitHub
commit 26d05abd4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 7 deletions

View File

@ -2,6 +2,7 @@ package docker
import (
"fmt"
"strings"
)
// ImportArtifact is an Artifact implementation for when a container is
@ -29,7 +30,19 @@ func (a *ImportArtifact) Id() string {
}
func (a *ImportArtifact) String() string {
return fmt.Sprintf("Imported Docker image: %s", a.Id())
tags := a.StateData["docker_tags"]
if tags == nil {
return fmt.Sprintf("Imported Docker image: %s", a.Id())
}
cast := tags.([]interface{})
names := []string{}
for _, name := range cast {
if n, ok := name.(string); ok {
names = append(names, n)
}
}
return fmt.Sprintf("Imported Docker image: %s with tags %s",
a.Id(), strings.Join(names, " "))
}
func (a *ImportArtifact) State(name string) interface{} {

View File

@ -103,18 +103,30 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact
}()
}
// Get the name.
name := artifact.Id()
names := []string{artifact.Id()}
tags := artifact.State("docker_tags")
if tags != nil {
cast := tags.([]interface{})
for _, name := range cast {
if n, ok := name.(string); ok {
names = append(names, n)
}
}
}
ui.Message("Pushing: " + name)
if err := driver.Push(name); err != nil {
return nil, false, false, err
// Get the name.
for _, name := range names {
ui.Message("Pushing: " + name)
if err := driver.Push(name); err != nil {
return nil, false, false, err
}
}
artifact = &docker.ImportArtifact{
BuilderIdValue: BuilderIdImport,
Driver: driver,
IdValue: name,
IdValue: names[0],
StateData: map[string]interface{}{"docker_tags": tags},
}
return artifact, true, false, nil

View File

@ -68,6 +68,7 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact
importRepo := p.config.Repository
var lastTaggedRepo = importRepo
RepoTags := []string{}
if len(p.config.Tag) > 0 {
for _, tag := range p.config.Tag {
local := importRepo + ":" + tag
@ -79,6 +80,7 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact
return nil, false, true, err
}
RepoTags = append(RepoTags, local)
lastTaggedRepo = local
}
} else {
@ -95,6 +97,7 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact
BuilderIdValue: BuilderId,
Driver: driver,
IdValue: lastTaggedRepo,
StateData: map[string]interface{}{"docker_tags": RepoTags},
}
// If we tag an image and then delete it, there was no point in creating the