2013-11-09 02:43:41 -05:00
|
|
|
package docker
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2013-11-09 02:43:41 -05:00
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
// StepTempDir creates a temporary directory that we use in order to
|
|
|
|
// share data with the docker container over the communicator.
|
|
|
|
type StepTempDir struct {
|
|
|
|
tempDir string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepTempDir) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
|
|
|
|
ui.Say("Creating a temporary directory for sharing data...")
|
2015-10-16 20:36:29 -04:00
|
|
|
|
|
|
|
var err error
|
|
|
|
var tempdir string
|
|
|
|
|
|
|
|
configTmpDir, err := packer.ConfigTmpDir()
|
|
|
|
if err == nil {
|
|
|
|
tempdir, err = ioutil.TempDir(configTmpDir, "packer-docker")
|
|
|
|
}
|
2013-11-09 02:43:41 -05:00
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf("Error making temp dir: %s", err)
|
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2015-10-16 20:36:29 -04:00
|
|
|
s.tempDir = tempdir
|
2013-11-09 02:43:41 -05:00
|
|
|
state.Put("temp_dir", s.tempDir)
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepTempDir) Cleanup(state multistep.StateBag) {
|
|
|
|
if s.tempDir != "" {
|
|
|
|
os.RemoveAll(s.tempDir)
|
|
|
|
}
|
|
|
|
}
|