github.com/rahart/packer@v0.12.2-0.20161229105310-282bb6ad370f/builder/docker/step_commit.go (about) 1 package docker 2 3 import ( 4 "fmt" 5 "github.com/mitchellh/multistep" 6 "github.com/mitchellh/packer/packer" 7 ) 8 9 // StepCommit commits the container to a image. 10 type StepCommit struct { 11 imageId string 12 } 13 14 func (s *StepCommit) Run(state multistep.StateBag) multistep.StepAction { 15 driver := state.Get("driver").(Driver) 16 containerId := state.Get("container_id").(string) 17 config := state.Get("config").(*Config) 18 ui := state.Get("ui").(packer.Ui) 19 20 ui.Say("Committing the container") 21 imageId, err := driver.Commit(containerId, config.Author, config.Changes, config.Message) 22 if err != nil { 23 state.Put("error", err) 24 ui.Error(err.Error()) 25 return multistep.ActionHalt 26 } 27 28 // Save the container ID 29 s.imageId = imageId 30 state.Put("image_id", s.imageId) 31 ui.Message(fmt.Sprintf("Image ID: %s", s.imageId)) 32 33 return multistep.ActionContinue 34 } 35 36 func (s *StepCommit) Cleanup(state multistep.StateBag) {}