Merge pull request #21664 from calavera/label_one_layer_images
Apply build labels to images with only a FROM tag. Upstream-commit: 47fa54aea39035515f45a4c98408e75c5085a2cb Component: engine
This commit is contained in:
@@ -6680,11 +6680,9 @@ func (s *DockerSuite) TestBuildLabel(c *check.C) {
|
||||
_, err := buildImage(name, `
|
||||
FROM `+minimalBaseImage()+`
|
||||
LABEL default foo
|
||||
`, false, []string{"--label", testLabel}...)
|
||||
`, false, "--label", testLabel)
|
||||
|
||||
if err != nil {
|
||||
c.Fatal("error building image with labels", err)
|
||||
}
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
res := inspectFieldJSON(c, name, "Config.Labels")
|
||||
|
||||
@@ -6699,6 +6697,28 @@ func (s *DockerSuite) TestBuildLabel(c *check.C) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildLabelOneNode(c *check.C) {
|
||||
name := "testbuildlabel"
|
||||
|
||||
_, err := buildImage(name, "FROM busybox", false, "--label", "foo=bar")
|
||||
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
res, err := inspectImage(name, "json .Config.Labels")
|
||||
c.Assert(err, checker.IsNil)
|
||||
var labels map[string]string
|
||||
|
||||
if err := json.Unmarshal([]byte(res), &labels); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
v, ok := labels["foo"]
|
||||
if !ok {
|
||||
c.Fatal("label `foo` not found in image")
|
||||
}
|
||||
c.Assert(v, checker.Equals, "bar")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildLabelCacheCommit(c *check.C) {
|
||||
name := "testbuildlabelcachecommit"
|
||||
testLabel := "foo"
|
||||
@@ -6713,11 +6733,9 @@ func (s *DockerSuite) TestBuildLabelCacheCommit(c *check.C) {
|
||||
_, err := buildImage(name, `
|
||||
FROM `+minimalBaseImage()+`
|
||||
LABEL default foo
|
||||
`, true, []string{"--label", testLabel}...)
|
||||
`, true, "--label", testLabel)
|
||||
|
||||
if err != nil {
|
||||
c.Fatal("error building image with labels", err)
|
||||
}
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
res := inspectFieldJSON(c, name, "Config.Labels")
|
||||
|
||||
|
||||
@@ -890,6 +890,21 @@ func inspectMountPointJSON(j, destination string) (types.MountPoint, error) {
|
||||
return *m, nil
|
||||
}
|
||||
|
||||
func inspectImage(name, filter string) (string, error) {
|
||||
args := []string{"inspect", "--type", "image"}
|
||||
if filter != "" {
|
||||
format := fmt.Sprintf("{{%s}}", filter)
|
||||
args = append(args, "-f", format)
|
||||
}
|
||||
args = append(args, name)
|
||||
inspectCmd := exec.Command(dockerBinary, args...)
|
||||
out, exitCode, err := runCommandWithOutput(inspectCmd)
|
||||
if err != nil || exitCode != 0 {
|
||||
return "", fmt.Errorf("failed to inspect %s: %s", name, out)
|
||||
}
|
||||
return strings.TrimSpace(out), nil
|
||||
}
|
||||
|
||||
func getIDByName(name string) (string, error) {
|
||||
return inspectFieldWithError(name, "Id")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user