support `changes` in commit job

In addition to config env, `commit` now will also accepts a `changes` env which
is a string contains new-line separated Dockerfile instructions.
`commit` will evaluate `changes` into `runconfig.Config` and merge it with
`config` env, and then finally commit a new image with the changed config

Docker-DCO-1.1-Signed-off-by: Daniel, Dao Quang Minh <dqminh89@gmail.com> (github: dqminh)

Docker-DCO-1.1-Signed-off-by: Daniel, Dao Quang Minh <dqminh89@gmail.com> (github: rhatdan)
This commit is contained in:
Daniel, Dao Quang Minh 2014-10-01 05:35:44 -04:00 коммит произвёл Dan Walsh
Родитель 7f091eca70
Коммит b30257ccf9
2 изменённых файлов: 49 добавлений и 3 удалений

Просмотреть файл

@ -1,6 +1,9 @@
package daemon
import (
"bytes"
"encoding/json"
"github.com/docker/docker/engine"
"github.com/docker/docker/image"
"github.com/docker/docker/runconfig"
@ -18,11 +21,21 @@ func (daemon *Daemon) ContainerCommit(job *engine.Job) engine.Status {
}
var (
config = container.Config
newConfig runconfig.Config
config = container.Config
stdoutBuffer = bytes.NewBuffer(nil)
newConfig runconfig.Config
)
if err := job.GetenvJson("config", &newConfig); err != nil {
buildConfigJob := daemon.eng.Job("build_config")
buildConfigJob.Stdout.Add(stdoutBuffer)
buildConfigJob.Setenv("changes", job.Getenv("changes"))
// FIXME this should be remove when we remove deprecated config param
buildConfigJob.Setenv("config", job.Getenv("config"))
if err := buildConfigJob.Run(); err != nil {
return job.Error(err)
}
if err := json.NewDecoder(stdoutBuffer).Decode(&newConfig); err != nil {
return job.Error(err)
}

Просмотреть файл

@ -202,3 +202,36 @@ func TestCommitWithHostBindMount(t *testing.T) {
logDone("commit - commit bind mounted file")
}
func TestCommitChange(t *testing.T) {
defer deleteAllContainers()
cmd(t, "run", "--name", "test", "busybox", "true")
cmd := exec.Command(dockerBinary, "commit",
"--change", "EXPOSE 8080",
"--change", "ENV DEBUG true",
"test", "test-commit")
imageId, _, err := runCommandWithOutput(cmd)
if err != nil {
t.Fatal(imageId, err)
}
imageId = strings.Trim(imageId, "\r\n")
defer deleteImages(imageId)
expected := map[string]string{
"Config.ExposedPorts": "map[8080/tcp:map[]]",
"Config.Env": "[DEBUG=true PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin]",
}
for conf, value := range expected {
res, err := inspectField(imageId, conf)
if err != nil {
t.Errorf("failed to get value %s, error: %s", conf, err)
}
if res != value {
t.Errorf("%s('%s'), expected %s", conf, res, value)
}
}
logDone("commit - commit --change")
}