mirror of
https://github.com/hashicorp/packer.git
synced 2026-06-11 01:30:06 -04:00
Merge pull request #9996 from hashicorp/fix_9995
Make shell-local post-processor return copy of previous artifact
This commit is contained in:
commit
721cbac645
3 changed files with 49 additions and 29 deletions
|
|
@ -30,19 +30,22 @@ 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())
|
||||
}
|
||||
cast := tags.([]interface{})
|
||||
names := []string{}
|
||||
for _, name := range cast {
|
||||
if n, ok := name.(string); ok {
|
||||
names = append(names, n)
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("Imported Docker image: %s with tags %s",
|
||||
a.Id(), strings.Join(names, " "))
|
||||
if len(tags) > 0 {
|
||||
return fmt.Sprintf("Imported Docker image: %s with tags %s",
|
||||
a.Id(), strings.Join(tags, " "))
|
||||
}
|
||||
return fmt.Sprintf("Imported Docker image: %s", a.Id())
|
||||
}
|
||||
|
||||
func (a *ImportArtifact) State(name string) interface{} {
|
||||
|
|
|
|||
|
|
@ -99,28 +99,42 @@ func (p *PostProcessorServer) PostProcess(streamId uint32, reply *PostProcessorP
|
|||
if err != nil {
|
||||
return NewBasicError(err)
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
if p.context == nil {
|
||||
p.context, p.contextCancel = context.WithCancel(context.Background())
|
||||
}
|
||||
|
||||
streamId = 0
|
||||
artifactResult, keep, forceOverride, err := p.p.PostProcess(p.context, client.Ui(), client.Artifact())
|
||||
if err == nil && artifactResult != nil {
|
||||
streamId = p.mux.NextId()
|
||||
server := newServerWithMux(p.mux, streamId)
|
||||
server.RegisterArtifact(artifactResult)
|
||||
go server.Serve()
|
||||
}
|
||||
|
||||
artifact := client.Artifact()
|
||||
artifactResult, keep, forceOverride, err := p.p.PostProcess(p.context, client.Ui(), artifact)
|
||||
*reply = PostProcessorProcessResponse{
|
||||
Err: NewBasicError(err),
|
||||
Keep: keep,
|
||||
ForceOverride: forceOverride,
|
||||
StreamId: streamId,
|
||||
StreamId: 0,
|
||||
}
|
||||
if err != nil {
|
||||
log.Printf("error: %v", err)
|
||||
client.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
if artifactResult != artifact {
|
||||
// Sometimes, the artifact returned by PostProcess is the artifact from
|
||||
// client.Artifact() and in that case we don't want to close client;
|
||||
// otherwise the outcome is sort of undetermined. See [GH-9995] for a
|
||||
// good test file.
|
||||
defer client.Close()
|
||||
}
|
||||
|
||||
if artifactResult != nil {
|
||||
streamId = p.mux.NextId()
|
||||
reply.StreamId = streamId
|
||||
server := newServerWithMux(p.mux, streamId)
|
||||
if err := server.RegisterArtifact(artifactResult); err != nil {
|
||||
return err
|
||||
}
|
||||
go server.Serve()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,17 +102,21 @@ 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.([]interface{})
|
||||
for _, name := range cast {
|
||||
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 {
|
||||
names = append(names, n)
|
||||
tags = append(tags, n)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
names := []string{artifact.Id()}
|
||||
names = append(names, tags...)
|
||||
|
||||
// Get the name.
|
||||
for _, name := range names {
|
||||
ui.Message("Pushing: " + name)
|
||||
|
|
|
|||
Loading…
Reference in a new issue