diff options
author | Daniel Nephin <dnephin@docker.com> | 2017-06-05 11:12:26 -0400 |
---|---|---|
committer | Daniel Nephin <dnephin@docker.com> | 2017-06-06 10:52:29 -0400 |
commit | f1ade82d82e6436971c6b7d08eb1da57ed9ba756 (patch) | |
tree | 3b138e26d107bbcf2dd45638a73bd9d3c3da5c0c /integration-cli/docker_api_build_test.go | |
parent | c8141a1fb1ff33b2bfab85a40e5da9a282f36cdc (diff) | |
download | docker-f1ade82d82e6436971c6b7d08eb1da57ed9ba756.tar.gz |
Fix Cache with ONBUILD
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Diffstat (limited to 'integration-cli/docker_api_build_test.go')
-rw-r--r-- | integration-cli/docker_api_build_test.go | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/integration-cli/docker_api_build_test.go b/integration-cli/docker_api_build_test.go index 12d3374dd5..64ad7c3251 100644 --- a/integration-cli/docker_api_build_test.go +++ b/integration-cli/docker_api_build_test.go @@ -3,6 +3,7 @@ package main import ( "archive/tar" "bytes" + "encoding/json" "io/ioutil" "net/http" "regexp" @@ -15,6 +16,9 @@ import ( "github.com/docker/docker/integration-cli/request" "github.com/docker/docker/pkg/testutil" "github.com/go-check/check" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "golang.org/x/net/context" ) func (s *DockerSuite) TestBuildAPIDockerFileRemote(c *check.C) { @@ -274,3 +278,68 @@ func (s *DockerSuite) TestBuildOnBuildWithCopy(c *check.C) { c.Assert(err, checker.IsNil) c.Assert(string(out), checker.Contains, "Successfully built") } + +func (s *DockerSuite) TestBuildOnBuildCache(c *check.C) { + build := func(dockerfile string) []byte { + ctx := fakecontext.New(c, "", + fakecontext.WithDockerfile(dockerfile), + ) + defer ctx.Close() + + res, body, err := request.Post( + "/build", + request.RawContent(ctx.AsTarReader(c)), + request.ContentType("application/x-tar")) + require.NoError(c, err) + assert.Equal(c, http.StatusOK, res.StatusCode) + + out, err := testutil.ReadBody(body) + require.NoError(c, err) + assert.Contains(c, string(out), "Successfully built") + return out + } + + dockerfile := ` + FROM ` + minimalBaseImage() + ` as onbuildbase + ENV something=bar + ONBUILD ENV foo=bar + ` + build(dockerfile) + + dockerfile += "FROM onbuildbase" + out := build(dockerfile) + + imageIDs := getImageIDsFromBuild(c, out) + assert.Len(c, imageIDs, 2) + parentID, childID := imageIDs[0], imageIDs[1] + + client, err := request.NewClient() + require.NoError(c, err) + + // check parentID is correct + image, _, err := client.ImageInspectWithRaw(context.Background(), childID) + require.NoError(c, err) + assert.Equal(c, parentID, image.Parent) +} + +type buildLine struct { + Stream string + Aux struct { + ID string + } +} + +func getImageIDsFromBuild(c *check.C, output []byte) []string { + ids := []string{} + for _, line := range bytes.Split(output, []byte("\n")) { + if len(line) == 0 { + continue + } + entry := buildLine{} + require.NoError(c, json.Unmarshal(line, &entry)) + if entry.Aux.ID != "" { + ids = append(ids, entry.Aux.ID) + } + } + return ids +} |