github.com/mitchellh/packer@v1.3.2/builder/docker/step_commit.go (about)

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