From 77c76a3170d819f98b90a80156dd9c5b34aafb95 Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Sat, 30 May 2015 11:31:51 +0200 Subject: [PATCH] Update api documentation to add labels in commit It is already possible to set labels at commit when using the API. But it is not present in the API documentation. Added an integration test too, to validate this work (and will be in the future). Signed-off-by: Vincent Demeester Upstream-commit: c61fa8471a567b4890e0861f8aaff91a68c42e4f Component: engine --- .../reference/api/docker_remote_api_v1.19.md | 4 ++ .../reference/api/docker_remote_api_v1.20.md | 4 ++ .../docker_api_containers_test.go | 51 +++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/components/engine/docs/sources/reference/api/docker_remote_api_v1.19.md b/components/engine/docs/sources/reference/api/docker_remote_api_v1.19.md index d6399b8fbd..6ac6f33de5 100644 --- a/components/engine/docs/sources/reference/api/docker_remote_api_v1.19.md +++ b/components/engine/docs/sources/reference/api/docker_remote_api_v1.19.md @@ -1752,6 +1752,10 @@ Create a new image from a container's changes "Volumes": { "/tmp": {} }, + "Labels": { + "key1": "value1", + "key2": "value2" + }, "WorkingDir": "", "NetworkDisabled": false, "ExposedPorts": { diff --git a/components/engine/docs/sources/reference/api/docker_remote_api_v1.20.md b/components/engine/docs/sources/reference/api/docker_remote_api_v1.20.md index c3a42410dd..82739d6294 100644 --- a/components/engine/docs/sources/reference/api/docker_remote_api_v1.20.md +++ b/components/engine/docs/sources/reference/api/docker_remote_api_v1.20.md @@ -1743,6 +1743,10 @@ Create a new image from a container's changes "Volumes": { "/tmp": {} }, + "Labels": { + "key1": "value1", + "key2": "value2" + }, "WorkingDir": "", "NetworkDisabled": false, "ExposedPorts": { diff --git a/components/engine/integration-cli/docker_api_containers_test.go b/components/engine/integration-cli/docker_api_containers_test.go index 8bdc13b6d7..d7bf9e97f9 100644 --- a/components/engine/integration-cli/docker_api_containers_test.go +++ b/components/engine/integration-cli/docker_api_containers_test.go @@ -725,6 +725,57 @@ func (s *DockerSuite) TestContainerApiCommit(c *check.C) { } } +func (s *DockerSuite) TestContainerApiCommitWithLabelInConfig(c *check.C) { + cName := "testapicommitwithconfig" + out, err := exec.Command(dockerBinary, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test").CombinedOutput() + if err != nil { + c.Fatal(err, out) + } + + config := map[string]interface{}{ + "Labels": map[string]string{"key1": "value1", "key2": "value2"}, + } + + name := "TestContainerApiCommitWithConfig" + status, b, err := sockRequest("POST", "/commit?repo="+name+"&container="+cName, config) + c.Assert(status, check.Equals, http.StatusCreated) + c.Assert(err, check.IsNil) + + type resp struct { + Id string + } + var img resp + if err := json.Unmarshal(b, &img); err != nil { + c.Fatal(err) + } + + label1, err := inspectFieldMap(img.Id, "Config.Labels", "key1") + if err != nil { + c.Fatal(err) + } + c.Assert(label1, check.Equals, "value1") + + label2, err := inspectFieldMap(img.Id, "Config.Labels", "key2") + if err != nil { + c.Fatal(err) + } + c.Assert(label2, check.Equals, "value2") + + cmd, err := inspectField(img.Id, "Config.Cmd") + if err != nil { + c.Fatal(err) + } + if cmd != "{[/bin/sh -c touch /test]}" { + c.Fatalf("got wrong Cmd from commit: %q", cmd) + } + + // sanity check, make sure the image is what we think it is + out, err = exec.Command(dockerBinary, "run", img.Id, "ls", "/test").CombinedOutput() + if err != nil { + c.Fatalf("error checking committed image: %v - %q", err, string(out)) + } +} + func (s *DockerSuite) TestContainerApiCreate(c *check.C) { config := map[string]interface{}{ "Image": "busybox",