Introduce docker commit changes
This commit is contained in:
parent
80aa6f3445
commit
c925acf502
|
@ -32,6 +32,7 @@ type Config struct {
|
||||||
RunCommand []string `mapstructure:"run_command"`
|
RunCommand []string `mapstructure:"run_command"`
|
||||||
Volumes map[string]string
|
Volumes map[string]string
|
||||||
Privileged bool `mapstructure:"privileged"`
|
Privileged bool `mapstructure:"privileged"`
|
||||||
|
Changes []string
|
||||||
|
|
||||||
// This is used to login to dockerhub to pull a private base container. For
|
// This is used to login to dockerhub to pull a private base container. For
|
||||||
// pushing to dockerhub, see the docker post-processors
|
// pushing to dockerhub, see the docker post-processors
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
// a mock driver can be shimmed in.
|
// a mock driver can be shimmed in.
|
||||||
type Driver interface {
|
type Driver interface {
|
||||||
// Commit the container to a tag
|
// 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
|
// Delete an image that is imported into Docker
|
||||||
DeleteImage(id string) error
|
DeleteImage(id string) error
|
||||||
|
|
|
@ -42,11 +42,17 @@ func (d *DockerDriver) DeleteImage(id string) error {
|
||||||
return nil
|
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 stdout bytes.Buffer
|
||||||
var stderr 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.Stdout = &stdout
|
||||||
cmd.Stderr = &stderr
|
cmd.Stderr = &stderr
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ type MockDriver struct {
|
||||||
VersionVersion string
|
VersionVersion string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *MockDriver) Commit(id string) (string, error) {
|
func (d *MockDriver) Commit(id string, changes []string) (string, error) {
|
||||||
d.CommitCalled = true
|
d.CommitCalled = true
|
||||||
d.CommitContainerId = id
|
d.CommitContainerId = id
|
||||||
return d.CommitImageId, d.CommitErr
|
return d.CommitImageId, d.CommitErr
|
||||||
|
|
|
@ -14,10 +14,11 @@ type StepCommit struct {
|
||||||
func (s *StepCommit) Run(state multistep.StateBag) multistep.StepAction {
|
func (s *StepCommit) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
driver := state.Get("driver").(Driver)
|
driver := state.Get("driver").(Driver)
|
||||||
containerId := state.Get("container_id").(string)
|
containerId := state.Get("container_id").(string)
|
||||||
|
config := state.Get("config").(*Config)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
|
||||||
ui.Say("Committing the container")
|
ui.Say("Committing the container")
|
||||||
imageId, err := driver.Commit(containerId)
|
imageId, err := driver.Commit(containerId, config.Changes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
|
|
Loading…
Reference in New Issue