diff --git a/builder/docker/artifact_import.go b/builder/docker/artifact_import.go index acc34019d..c626a9df3 100644 --- a/builder/docker/artifact_import.go +++ b/builder/docker/artifact_import.go @@ -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{} { diff --git a/post-processor/docker-push/post-processor.go b/post-processor/docker-push/post-processor.go index a276b0fca..979ea2896 100644 --- a/post-processor/docker-push/post-processor.go +++ b/post-processor/docker-push/post-processor.go @@ -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 diff --git a/post-processor/docker-tag/post-processor.go b/post-processor/docker-tag/post-processor.go index b4af223e6..b4b27350a 100644 --- a/post-processor/docker-tag/post-processor.go +++ b/post-processor/docker-tag/post-processor.go @@ -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