github.com/sneal/packer@v0.5.2/builder/docker/step_temp_dir.go (about) 1 package docker 2 3 import ( 4 "fmt" 5 "github.com/mitchellh/multistep" 6 "github.com/mitchellh/packer/packer" 7 "io/ioutil" 8 "os" 9 ) 10 11 // StepTempDir creates a temporary directory that we use in order to 12 // share data with the docker container over the communicator. 13 type StepTempDir struct { 14 tempDir string 15 } 16 17 func (s *StepTempDir) Run(state multistep.StateBag) multistep.StepAction { 18 ui := state.Get("ui").(packer.Ui) 19 20 ui.Say("Creating a temporary directory for sharing data...") 21 td, err := ioutil.TempDir("", "packer-docker") 22 if err != nil { 23 err := fmt.Errorf("Error making temp dir: %s", err) 24 state.Put("error", err) 25 ui.Error(err.Error()) 26 return multistep.ActionHalt 27 } 28 29 s.tempDir = td 30 state.Put("temp_dir", s.tempDir) 31 return multistep.ActionContinue 32 } 33 34 func (s *StepTempDir) Cleanup(state multistep.StateBag) { 35 if s.tempDir != "" { 36 os.RemoveAll(s.tempDir) 37 } 38 }