Handle commit author & message the same way

This commit is contained in:
Florian Rey 2016-11-24 13:33:42 +01:00
parent 06bebb63d0
commit 73c5eac4f0
5 changed files with 12 additions and 4 deletions

View File

@ -32,7 +32,9 @@ 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"`
Author string
Changes []string Changes []string
Message 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

View File

@ -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, changes []string) (string, error) Commit(id string, author string, changes []string, message 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

View File

@ -42,14 +42,20 @@ func (d *DockerDriver) DeleteImage(id string) error {
return nil return nil
} }
func (d *DockerDriver) Commit(id string, changes []string) (string, error) { func (d *DockerDriver) Commit(id string, author string, changes []string, message string) (string, error) {
var stdout bytes.Buffer var stdout bytes.Buffer
var stderr bytes.Buffer var stderr bytes.Buffer
args := []string{"commit"} args := []string{"commit"}
if author != "" {
args = append(args, "--author", author)
}
for _, change := range changes { for _, change := range changes {
args = append(args, "--change", change) args = append(args, "--change", change)
} }
if message != "" {
args = append(args, "--message", message)
}
args = append(args, id) args = append(args, id)
log.Printf("Committing container with args: %v", args) log.Printf("Committing container with args: %v", args)

View File

@ -76,7 +76,7 @@ type MockDriver struct {
VersionVersion string VersionVersion string
} }
func (d *MockDriver) Commit(id string, changes []string) (string, error) { func (d *MockDriver) Commit(id string, author string, changes []string, message 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

View File

@ -18,7 +18,7 @@ func (s *StepCommit) Run(state multistep.StateBag) multistep.StepAction {
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, config.Changes) imageId, err := driver.Commit(containerId, config.Author, config.Changes, config.Message)
if err != nil { if err != nil {
state.Put("error", err) state.Put("error", err)
ui.Error(err.Error()) ui.Error(err.Error())