Introduce docker commit changes

This commit is contained in:
Florian Rey 2016-11-24 11:42:34 +01:00
parent 80aa6f3445
commit c925acf502
5 changed files with 13 additions and 5 deletions

View File

@ -32,6 +32,7 @@ type Config struct {
RunCommand []string `mapstructure:"run_command"`
Volumes map[string]string
Privileged bool `mapstructure:"privileged"`
Changes []string
// This is used to login to dockerhub to pull a private base container. For
// pushing to dockerhub, see the docker post-processors

View File

@ -11,7 +11,7 @@ import (
// a mock driver can be shimmed in.
type Driver interface {
// Commit the container to a tag
Commit(id string) (string, error)
Commit(id string, changes []string) (string, error)
// Delete an image that is imported into Docker
DeleteImage(id string) error

View File

@ -42,11 +42,17 @@ func (d *DockerDriver) DeleteImage(id string) error {
return nil
}
func (d *DockerDriver) Commit(id string) (string, error) {
func (d *DockerDriver) Commit(id string, changes []string) (string, error) {
var stdout bytes.Buffer
var stderr bytes.Buffer
cmd := exec.Command("docker", "commit", id)
args := []string{"commit"}
for _, change := range changes {
args = append(args, "--change", change)
}
args = append(args, id)
cmd := exec.Command("docker", args...)
cmd.Stdout = &stdout
cmd.Stderr = &stderr

View File

@ -76,7 +76,7 @@ type MockDriver struct {
VersionVersion string
}
func (d *MockDriver) Commit(id string) (string, error) {
func (d *MockDriver) Commit(id string, changes []string) (string, error) {
d.CommitCalled = true
d.CommitContainerId = id
return d.CommitImageId, d.CommitErr

View File

@ -14,10 +14,11 @@ type StepCommit struct {
func (s *StepCommit) Run(state multistep.StateBag) multistep.StepAction {
driver := state.Get("driver").(Driver)
containerId := state.Get("container_id").(string)
config := state.Get("config").(*Config)
ui := state.Get("ui").(packer.Ui)
ui.Say("Committing the container")
imageId, err := driver.Commit(containerId)
imageId, err := driver.Commit(containerId, config.Changes)
if err != nil {
state.Put("error", err)
ui.Error(err.Error())