packer-cn/builder/docker/step_export.go

44 lines
999 B
Go
Raw Normal View History

2013-11-09 12:48:36 -05:00
package docker
import (
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"os"
)
// StepExport exports the container to a flat tar file.
type StepExport struct{}
func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*Config)
2013-11-09 16:15:51 -05:00
driver := state.Get("driver").(Driver)
2013-11-09 12:48:36 -05:00
containerId := state.Get("container_id").(string)
ui := state.Get("ui").(packer.Ui)
// Open the file that we're going to write to
f, err := os.Create(config.ExportPath)
if err != nil {
err := fmt.Errorf("Error creating output file: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
2013-11-09 16:15:51 -05:00
ui.Say("Exporting the container")
if err := driver.Export(containerId, f); err != nil {
f.Close()
os.Remove(f.Name())
2013-11-09 12:48:36 -05:00
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
2013-11-09 16:15:51 -05:00
f.Close()
2013-11-09 12:48:36 -05:00
return multistep.ActionContinue
}
func (s *StepExport) Cleanup(state multistep.StateBag) {}