From 6ac597128828ecde1e59cd66980378649bbfb799 Mon Sep 17 00:00:00 2001 From: Ladar Levison Date: Mon, 17 Dec 2018 22:59:41 -0600 Subject: [PATCH] Fixed cmd order for docker driver. Added config to post proc. --- builder/docker/driver_docker.go | 17 +++++++++-------- post-processor/docker-import/post-processor.go | 3 ++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/builder/docker/driver_docker.go b/builder/docker/driver_docker.go index 59fb8f9c3..918dfdb2c 100644 --- a/builder/docker/driver_docker.go +++ b/builder/docker/driver_docker.go @@ -99,13 +99,6 @@ func (d *DockerDriver) Export(id string, dst io.Writer) error { func (d *DockerDriver) Import(path string, changes []string, repo string) (string, error) { var stdout, stderr bytes.Buffer - cmd.Stdout = &stdout - cmd.Stderr = &stderr - stdin, err := cmd.StdinPipe() - - if err != nil { - return "", err - } args := []string{"import"} @@ -115,7 +108,15 @@ func (d *DockerDriver) Import(path string, changes []string, repo string) (strin args = append(args, "-") args = append(args, repo) + cmd := exec.Command("docker", args...) + cmd.Stdout = &stdout + cmd.Stderr = &stderr + stdin, err := cmd.StdinPipe() + + if err != nil { + return "", err + } // There should be only one artifact of the Docker builder file, err := os.Open(path) @@ -124,7 +125,7 @@ func (d *DockerDriver) Import(path string, changes []string, repo string) (strin } defer file.Close() - log.Printf("Importing container with args: %v", args) + log.Printf("Importing tarball with args: %v", args) if err := cmd.Start(); err != nil { return "", err diff --git a/post-processor/docker-import/post-processor.go b/post-processor/docker-import/post-processor.go index 80b99c8b3..c3488b22a 100644 --- a/post-processor/docker-import/post-processor.go +++ b/post-processor/docker-import/post-processor.go @@ -18,6 +18,7 @@ type Config struct { Repository string `mapstructure:"repository"` Tag string `mapstructure:"tag"` + Changes []string ctx interpolate.Context } @@ -62,7 +63,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac ui.Message("Importing image: " + artifact.Id()) ui.Message("Repository: " + importRepo) - id, err := driver.Import(artifact.Files()[0], importRepo) + id, err := driver.Import(artifact.Files()[0], p.config.Changes, importRepo) if err != nil { return nil, false, err }