github.com/sneal/packer@v0.5.2/builder/docker/step_export.go (about) 1 package docker 2 3 import ( 4 "fmt" 5 "github.com/mitchellh/multistep" 6 "github.com/mitchellh/packer/packer" 7 "os" 8 ) 9 10 // StepExport exports the container to a flat tar file. 11 type StepExport struct{} 12 13 func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction { 14 config := state.Get("config").(*Config) 15 driver := state.Get("driver").(Driver) 16 containerId := state.Get("container_id").(string) 17 ui := state.Get("ui").(packer.Ui) 18 19 // Open the file that we're going to write to 20 f, err := os.Create(config.ExportPath) 21 if err != nil { 22 err := fmt.Errorf("Error creating output file: %s", err) 23 state.Put("error", err) 24 ui.Error(err.Error()) 25 return multistep.ActionHalt 26 } 27 28 ui.Say("Exporting the container") 29 if err := driver.Export(containerId, f); err != nil { 30 f.Close() 31 os.Remove(f.Name()) 32 33 state.Put("error", err) 34 ui.Error(err.Error()) 35 return multistep.ActionHalt 36 } 37 38 f.Close() 39 return multistep.ActionContinue 40 } 41 42 func (s *StepExport) Cleanup(state multistep.StateBag) {}