Fix ONBUILD COPY

the source was missing from the second dispatch

Signed-off-by: Daniel Nephin <dnephin@docker.com>
(cherry picked from commit 3f2604157790408acf5ad05c74cebe105f2b6979)
This commit is contained in:
Daniel Nephin
2017-06-05 08:01:05 -07:00
committed by Kenfe-Mickael Laventure
parent 09185931e1
commit 9e9c4b52b9
4 changed files with 41 additions and 3 deletions
@@ -2,9 +2,12 @@ package fakecontext
import (
"bytes"
"io"
"io/ioutil"
"os"
"path/filepath"
"github.com/docker/docker/pkg/archive"
)
type testingT interface {
@@ -110,3 +113,12 @@ func (f *Fake) Delete(file string) error {
func (f *Fake) Close() error {
return os.RemoveAll(f.Dir)
}
// AsTarReader returns a ReadCloser with the contents of Dir as a tar archive.
func (f *Fake) AsTarReader(t testingT) io.ReadCloser {
reader, err := archive.TarWithOptions(f.Dir, &archive.TarOptions{})
if err != nil {
t.Fatalf("Failed to create tar from %s: %s", f.Dir, err)
}
return reader
}
@@ -249,3 +249,28 @@ func (s *DockerSuite) TestBuildAPIUnnormalizedTarPaths(c *check.C) {
c.Assert(imageA, checker.Not(checker.Equals), imageB)
}
func (s *DockerSuite) TestBuildOnBuildWithCopy(c *check.C) {
dockerfile := `
FROM ` + minimalBaseImage() + ` as onbuildbase
ONBUILD COPY file /file
FROM onbuildbase
`
ctx := fakecontext.New(c, "",
fakecontext.WithDockerfile(dockerfile),
fakecontext.WithFile("file", "some content"),
)
defer ctx.Close()
res, body, err := request.Post(
"/build",
request.RawContent(ctx.AsTarReader(c)),
request.ContentType("application/x-tar"))
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
out, err := testutil.ReadBody(body)
c.Assert(err, checker.IsNil)
c.Assert(string(out), checker.Contains, "Successfully built")
}