Modified func Upload to use docker cp

This commit is contained in:
Michael Juliano 2017-08-22 04:43:11 -04:00 committed by Matthew Hooker
parent 60649e2b7b
commit c8db128dc5
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
2 changed files with 11 additions and 11 deletions

1
.gitignore vendored
View File

@ -21,3 +21,4 @@ packer-test*.log
.idea/
*.iml
Thumbs.db

View File

@ -79,21 +79,20 @@ func (c *Communicator) Upload(dst string, src io.Reader, fi *os.FileInfo) error
}
tempfile.Close()
// Copy the file into place by copying the temporary file we put
// into the shared folder into the proper location in the container
cmd := &packer.RemoteCmd{
Command: fmt.Sprintf("command cp %s/%s %s", c.ContainerDir,
filepath.Base(tempfile.Name()), dst),
}
// Use docker cp to copy the file from the host to the container
// command format: docker cp /path/to/infile containerid:/path/to/outfile
cmd := exec.Command("docker", "cp", tempfile.Name(), fmt.Sprintf("%s:%s", c.ContainerId, dst))
if err := c.Start(cmd); err != nil {
log.Printf("Copying %s to %s on container %s.", tempfile.Name(), dst, c.ContainerId)
if err := cmd.Start(); err != nil {
return err
}
// Wait for the copy to complete
cmd.Wait()
if cmd.ExitStatus != 0 {
return fmt.Errorf("Upload failed with non-zero exit status: %d", cmd.ExitStatus)
if err := cmd.Wait(); err != nil {
err = fmt.Errorf("Error uploading %s: %s",
tempfile.Name(),
err)
return err
}
return nil