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"`
|
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
|
||||||
|
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
|
||||||
|
|
|
@ -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, 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
|
||||||
|
|
|
@ -42,11 +42,24 @@ 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, author string, changes []string, message 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"}
|
||||||
|
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.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, 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
|
||||||
|
|
|
@ -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.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())
|
||||||
|
|
|
@ -86,6 +86,8 @@ You must specify (only) one of `commit`, `discard`, or `export_path`.
|
||||||
|
|
||||||
### Optional:
|
### Optional:
|
||||||
|
|
||||||
|
- `author` (string) - Set the author (e-mail) of a commit.
|
||||||
|
|
||||||
- `aws_access_key` (string) - The AWS access key used to communicate with AWS.
|
- `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)
|
[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`
|
probably don't need it. This will also be read from the `AWS_SESSION_TOKEN`
|
||||||
environmental variable.
|
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
|
- `ecr_login` (boolean) - Defaults to false. If true, the builder will login in
|
||||||
order to pull the image from
|
order to pull the image from
|
||||||
[Amazon EC2 Container Registry (ECR)](https://aws.amazon.com/ecr/).
|
[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.
|
- `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` (boolean) - If true, run the docker container with the
|
||||||
`--privileged` flag. This defaults to false if not set.
|
`--privileged` flag. This defaults to false if not set.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue