Browse code

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 <vincent@sbr.pm>

Vincent Demeester authored on 2015/05/30 18:31:51
Showing 3 changed files
... ...
@@ -1752,6 +1752,10 @@ Create a new image from a container's changes
1752 1752
          "Volumes": {
1753 1753
                  "/tmp": {}
1754 1754
          },
1755
+         "Labels": {
1756
+                 "key1": "value1",
1757
+                 "key2": "value2"
1758
+          },
1755 1759
          "WorkingDir": "",
1756 1760
          "NetworkDisabled": false,
1757 1761
          "ExposedPorts": {
... ...
@@ -1743,6 +1743,10 @@ Create a new image from a container's changes
1743 1743
          "Volumes": {
1744 1744
                  "/tmp": {}
1745 1745
          },
1746
+         "Labels": {
1747
+                 "key1": "value1",
1748
+                 "key2": "value2"
1749
+          },
1746 1750
          "WorkingDir": "",
1747 1751
          "NetworkDisabled": false,
1748 1752
          "ExposedPorts": {
... ...
@@ -725,6 +725,57 @@ func (s *DockerSuite) TestContainerApiCommit(c *check.C) {
725 725
 	}
726 726
 }
727 727
 
728
+func (s *DockerSuite) TestContainerApiCommitWithLabelInConfig(c *check.C) {
729
+	cName := "testapicommitwithconfig"
730
+	out, err := exec.Command(dockerBinary, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test").CombinedOutput()
731
+	if err != nil {
732
+		c.Fatal(err, out)
733
+	}
734
+
735
+	config := map[string]interface{}{
736
+		"Labels": map[string]string{"key1": "value1", "key2": "value2"},
737
+	}
738
+
739
+	name := "TestContainerApiCommitWithConfig"
740
+	status, b, err := sockRequest("POST", "/commit?repo="+name+"&container="+cName, config)
741
+	c.Assert(status, check.Equals, http.StatusCreated)
742
+	c.Assert(err, check.IsNil)
743
+
744
+	type resp struct {
745
+		Id string
746
+	}
747
+	var img resp
748
+	if err := json.Unmarshal(b, &img); err != nil {
749
+		c.Fatal(err)
750
+	}
751
+
752
+	label1, err := inspectFieldMap(img.Id, "Config.Labels", "key1")
753
+	if err != nil {
754
+		c.Fatal(err)
755
+	}
756
+	c.Assert(label1, check.Equals, "value1")
757
+
758
+	label2, err := inspectFieldMap(img.Id, "Config.Labels", "key2")
759
+	if err != nil {
760
+		c.Fatal(err)
761
+	}
762
+	c.Assert(label2, check.Equals, "value2")
763
+
764
+	cmd, err := inspectField(img.Id, "Config.Cmd")
765
+	if err != nil {
766
+		c.Fatal(err)
767
+	}
768
+	if cmd != "{[/bin/sh -c touch /test]}" {
769
+		c.Fatalf("got wrong Cmd from commit: %q", cmd)
770
+	}
771
+
772
+	// sanity check, make sure the image is what we think it is
773
+	out, err = exec.Command(dockerBinary, "run", img.Id, "ls", "/test").CombinedOutput()
774
+	if err != nil {
775
+		c.Fatalf("error checking committed image: %v - %q", err, string(out))
776
+	}
777
+}
778
+
728 779
 func (s *DockerSuite) TestContainerApiCreate(c *check.C) {
729 780
 	config := map[string]interface{}{
730 781
 		"Image": "busybox",