Merge pull request #4202 from nervo/docker-commit-changes
Introduce docker commit changes
This commit is contained in:
commit
e36b98ecd5
|
@ -32,6 +32,9 @@ type Config struct {
|
|||
RunCommand []string `mapstructure:"run_command"`
|
||||
Volumes map[string]string
|
||||
Privileged bool `mapstructure:"privileged"`
|
||||
Author string
|
||||
Changes []string
|
||||
Message string
|
||||
|
||||
// This is used to login to dockerhub to pull a private base container. For
|
||||
// pushing to dockerhub, see the docker post-processors
|
||||
|
|
|
@ -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, author string, changes []string, message string) (string, error)
|
||||
|
||||
// Delete an image that is imported into Docker
|
||||
DeleteImage(id string) error
|
||||
|
|
|
@ -42,11 +42,24 @@ func (d *DockerDriver) DeleteImage(id string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (d *DockerDriver) Commit(id string) (string, error) {
|
||||
func (d *DockerDriver) Commit(id string, author string, changes []string, message string) (string, error) {
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
|
||||
cmd := exec.Command("docker", "commit", id)
|
||||
args := []string{"commit"}
|
||||
if author != "" {
|
||||
args = append(args, "--author", author)
|
||||
}
|
||||
for _, change := range changes {
|
||||
args = append(args, "--change", change)
|
||||
}
|
||||
if message != "" {
|
||||
args = append(args, "--message", message)
|
||||
}
|
||||
args = append(args, id)
|
||||
|
||||
log.Printf("Committing container with args: %v", args)
|
||||
cmd := exec.Command("docker", args...)
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = &stderr
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ type MockDriver struct {
|
|||
VersionVersion string
|
||||
}
|
||||
|
||||
func (d *MockDriver) Commit(id string) (string, error) {
|
||||
func (d *MockDriver) Commit(id string, author string, changes []string, message string) (string, error) {
|
||||
d.CommitCalled = true
|
||||
d.CommitContainerId = id
|
||||
return d.CommitImageId, d.CommitErr
|
||||
|
|
|
@ -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.Author, config.Changes, config.Message)
|
||||
if err != nil {
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
|
|
|
@ -86,6 +86,8 @@ You must specify (only) one of `commit`, `discard`, or `export_path`.
|
|||
|
||||
### Optional:
|
||||
|
||||
- `author` (string) - Set the author (e-mail) of a commit.
|
||||
|
||||
- `aws_access_key` (string) - The AWS access key used to communicate with AWS.
|
||||
[Learn how to set this.](/docs/builders/amazon.html#specifying-amazon-credentials)
|
||||
|
||||
|
@ -97,6 +99,10 @@ You must specify (only) one of `commit`, `discard`, or `export_path`.
|
|||
probably don't need it. This will also be read from the `AWS_SESSION_TOKEN`
|
||||
environmental variable.
|
||||
|
||||
- `changes` (array of strings) - Dockerfile instructions to add to the commit.
|
||||
Example of instructions are `CMD`, `ENTRYPOINT`, `ENV`, and `EXPOSE`. Example:
|
||||
`[ "USER ubuntu", "WORKDIR /app", "EXPOSE 8080" ]`
|
||||
|
||||
- `ecr_login` (boolean) - Defaults to false. If true, the builder will login in
|
||||
order to pull the image from
|
||||
[Amazon EC2 Container Registry (ECR)](https://aws.amazon.com/ecr/).
|
||||
|
@ -116,6 +122,8 @@ You must specify (only) one of `commit`, `discard`, or `export_path`.
|
|||
|
||||
- `login_server` (string) - The server address to login to.
|
||||
|
||||
- `message` (string) - Set a message for the commit.
|
||||
|
||||
- `privileged` (boolean) - If true, run the docker container with the
|
||||
`--privileged` flag. This defaults to false if not set.
|
||||
|
||||
|
|
Loading…
Reference in New Issue