1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #33500 from dnephin/fix-onbuild-copy

Fix ONBUILD COPY
This commit is contained in:
Vincent Demeester 2017-06-05 11:48:57 +02:00 committed by GitHub
commit 34f1cd26b6
4 changed files with 41 additions and 3 deletions

View file

@ -274,7 +274,7 @@ func BuildFromConfig(config *container.Config, changes []string) (*container.Con
} }
dispatchState := newDispatchState() dispatchState := newDispatchState()
dispatchState.runConfig = config dispatchState.runConfig = config
return dispatchFromDockerfile(b, dockerfile, dispatchState) return dispatchFromDockerfile(b, dockerfile, dispatchState, nil)
} }
func checkDispatchDockerfile(dockerfile *parser.Node) error { func checkDispatchDockerfile(dockerfile *parser.Node) error {
@ -286,7 +286,7 @@ func checkDispatchDockerfile(dockerfile *parser.Node) error {
return nil return nil
} }
func dispatchFromDockerfile(b *Builder, result *parser.Result, dispatchState *dispatchState) (*container.Config, error) { func dispatchFromDockerfile(b *Builder, result *parser.Result, dispatchState *dispatchState, source builder.Source) (*container.Config, error) {
shlex := NewShellLex(result.EscapeToken) shlex := NewShellLex(result.EscapeToken)
ast := result.AST ast := result.AST
total := len(ast.Children) total := len(ast.Children)
@ -297,6 +297,7 @@ func dispatchFromDockerfile(b *Builder, result *parser.Result, dispatchState *di
stepMsg: formatStep(i, total), stepMsg: formatStep(i, total),
node: n, node: n,
shlex: shlex, shlex: shlex,
source: source,
} }
if _, err := b.dispatch(opts); err != nil { if _, err := b.dispatch(opts); err != nil {
return nil, err return nil, err

View file

@ -325,7 +325,7 @@ func processOnBuild(req dispatchRequest) error {
} }
} }
if _, err := dispatchFromDockerfile(req.builder, dockerfile, dispatchState); err != nil { if _, err := dispatchFromDockerfile(req.builder, dockerfile, dispatchState, req.source); err != nil {
return err return err
} }
} }

View file

@ -2,9 +2,12 @@ package fakecontext
import ( import (
"bytes" "bytes"
"io"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"github.com/docker/docker/pkg/archive"
) )
type testingT interface { type testingT interface {
@ -110,3 +113,12 @@ func (f *Fake) Delete(file string) error {
func (f *Fake) Close() error { func (f *Fake) Close() error {
return os.RemoveAll(f.Dir) 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
}

View file

@ -249,3 +249,28 @@ func (s *DockerSuite) TestBuildAPIUnnormalizedTarPaths(c *check.C) {
c.Assert(imageA, checker.Not(checker.Equals), imageB) 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")
}