… and continue emptying `docker_utils_test.go` from build related function.
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
| ... | ... |
@@ -14,6 +14,7 @@ import ( |
| 14 | 14 |
"github.com/docker/docker/api/types/swarm" |
| 15 | 15 |
cliconfig "github.com/docker/docker/cli/config" |
| 16 | 16 |
"github.com/docker/docker/integration-cli/cli" |
| 17 |
+ "github.com/docker/docker/integration-cli/cli/build/fakestorage" |
|
| 17 | 18 |
"github.com/docker/docker/integration-cli/daemon" |
| 18 | 19 |
"github.com/docker/docker/integration-cli/environment" |
| 19 | 20 |
"github.com/docker/docker/integration-cli/registry" |
| ... | ... |
@@ -65,6 +66,7 @@ func TestMain(m *testing.M) {
|
| 65 | 65 |
|
| 66 | 66 |
func Test(t *testing.T) {
|
| 67 | 67 |
cli.EnsureTestEnvIsLoaded(t) |
| 68 |
+ fakestorage.EnsureTestEnvIsLoaded(t) |
|
| 68 | 69 |
cmd := exec.Command(dockerBinary, "images", "-f", "dangling=false", "--format", "{{.Repository}}:{{.Tag}}")
|
| 69 | 70 |
cmd.Env = appendBaseEnv(true) |
| 70 | 71 |
out, err := cmd.CombinedOutput() |
| ... | ... |
@@ -1,11 +1,30 @@ |
| 1 | 1 |
package build |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "io" |
|
| 4 | 5 |
"strings" |
| 5 | 6 |
|
| 7 |
+ "github.com/docker/docker/integration-cli/cli/build/fakecontext" |
|
| 6 | 8 |
icmd "github.com/docker/docker/pkg/testutil/cmd" |
| 7 | 9 |
) |
| 8 | 10 |
|
| 11 |
+type testingT interface {
|
|
| 12 |
+ Fatal(args ...interface{})
|
|
| 13 |
+ Fatalf(string, ...interface{})
|
|
| 14 |
+} |
|
| 15 |
+ |
|
| 16 |
+// WithStdinContext sets the build context from the standard input with the specified reader |
|
| 17 |
+func WithStdinContext(closer io.ReadCloser) func(*icmd.Cmd) func() {
|
|
| 18 |
+ return func(cmd *icmd.Cmd) func() {
|
|
| 19 |
+ cmd.Command = append(cmd.Command, "-") |
|
| 20 |
+ cmd.Stdin = closer |
|
| 21 |
+ return func() {
|
|
| 22 |
+ // FIXME(vdemeester) we should not ignore the error here… |
|
| 23 |
+ closer.Close() |
|
| 24 |
+ } |
|
| 25 |
+ } |
|
| 26 |
+} |
|
| 27 |
+ |
|
| 9 | 28 |
// WithDockerfile creates / returns a CmdOperator to set the Dockerfile for a build operation |
| 10 | 29 |
func WithDockerfile(dockerfile string) func(*icmd.Cmd) func() {
|
| 11 | 30 |
return func(cmd *icmd.Cmd) func() {
|
| ... | ... |
@@ -28,3 +47,36 @@ func WithContextPath(path string) func(*icmd.Cmd) func() {
|
| 28 | 28 |
return nil |
| 29 | 29 |
} |
| 30 | 30 |
} |
| 31 |
+ |
|
| 32 |
+// WithExternalBuildContext use the specified context as build context |
|
| 33 |
+func WithExternalBuildContext(ctx *fakecontext.Fake) func(*icmd.Cmd) func() {
|
|
| 34 |
+ return func(cmd *icmd.Cmd) func() {
|
|
| 35 |
+ cmd.Dir = ctx.Dir |
|
| 36 |
+ cmd.Command = append(cmd.Command, ".") |
|
| 37 |
+ return nil |
|
| 38 |
+ } |
|
| 39 |
+} |
|
| 40 |
+ |
|
| 41 |
+// WithBuildContext sets up the build context |
|
| 42 |
+func WithBuildContext(t testingT, contextOperators ...func(*fakecontext.Fake) error) func(*icmd.Cmd) func() {
|
|
| 43 |
+ // FIXME(vdemeester) de-duplicate that |
|
| 44 |
+ ctx := fakecontext.New(t, "", contextOperators...) |
|
| 45 |
+ return func(cmd *icmd.Cmd) func() {
|
|
| 46 |
+ cmd.Dir = ctx.Dir |
|
| 47 |
+ cmd.Command = append(cmd.Command, ".") |
|
| 48 |
+ return closeBuildContext(t, ctx) |
|
| 49 |
+ } |
|
| 50 |
+} |
|
| 51 |
+ |
|
| 52 |
+// WithFile adds the specified file (with content) in the build context |
|
| 53 |
+func WithFile(name, content string) func(*fakecontext.Fake) error {
|
|
| 54 |
+ return fakecontext.WithFile(name, content) |
|
| 55 |
+} |
|
| 56 |
+ |
|
| 57 |
+func closeBuildContext(t testingT, ctx *fakecontext.Fake) func() {
|
|
| 58 |
+ return func() {
|
|
| 59 |
+ if err := ctx.Close(); err != nil {
|
|
| 60 |
+ t.Fatal(err) |
|
| 61 |
+ } |
|
| 62 |
+ } |
|
| 63 |
+} |
| 31 | 64 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,112 @@ |
| 0 |
+package fakecontext |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "bytes" |
|
| 4 |
+ "io/ioutil" |
|
| 5 |
+ "os" |
|
| 6 |
+ "path/filepath" |
|
| 7 |
+) |
|
| 8 |
+ |
|
| 9 |
+type testingT interface {
|
|
| 10 |
+ Fatal(args ...interface{})
|
|
| 11 |
+ Fatalf(string, ...interface{})
|
|
| 12 |
+} |
|
| 13 |
+ |
|
| 14 |
+// New creates a fake build context |
|
| 15 |
+func New(t testingT, dir string, modifiers ...func(*Fake) error) *Fake {
|
|
| 16 |
+ fakeContext := &Fake{Dir: dir}
|
|
| 17 |
+ if dir == "" {
|
|
| 18 |
+ if err := newDir(fakeContext); err != nil {
|
|
| 19 |
+ t.Fatal(err) |
|
| 20 |
+ } |
|
| 21 |
+ } |
|
| 22 |
+ |
|
| 23 |
+ for _, modifier := range modifiers {
|
|
| 24 |
+ if err := modifier(fakeContext); err != nil {
|
|
| 25 |
+ t.Fatal(err) |
|
| 26 |
+ } |
|
| 27 |
+ } |
|
| 28 |
+ |
|
| 29 |
+ return fakeContext |
|
| 30 |
+} |
|
| 31 |
+ |
|
| 32 |
+func newDir(fake *Fake) error {
|
|
| 33 |
+ tmp, err := ioutil.TempDir("", "fake-context")
|
|
| 34 |
+ if err != nil {
|
|
| 35 |
+ return err |
|
| 36 |
+ } |
|
| 37 |
+ if err := os.Chmod(tmp, 0755); err != nil {
|
|
| 38 |
+ return err |
|
| 39 |
+ } |
|
| 40 |
+ fake.Dir = tmp |
|
| 41 |
+ return nil |
|
| 42 |
+} |
|
| 43 |
+ |
|
| 44 |
+// WithFile adds the specified file (with content) in the build context |
|
| 45 |
+func WithFile(name, content string) func(*Fake) error {
|
|
| 46 |
+ return func(ctx *Fake) error {
|
|
| 47 |
+ return ctx.Add(name, content) |
|
| 48 |
+ } |
|
| 49 |
+} |
|
| 50 |
+ |
|
| 51 |
+// WithDockerfile adds the specified content as Dockerfile in the build context |
|
| 52 |
+func WithDockerfile(content string) func(*Fake) error {
|
|
| 53 |
+ return WithFile("Dockerfile", content)
|
|
| 54 |
+} |
|
| 55 |
+ |
|
| 56 |
+// WithFiles adds the specified files in the build context, content is a string |
|
| 57 |
+func WithFiles(files map[string]string) func(*Fake) error {
|
|
| 58 |
+ return func(fakeContext *Fake) error {
|
|
| 59 |
+ for file, content := range files {
|
|
| 60 |
+ if err := fakeContext.Add(file, content); err != nil {
|
|
| 61 |
+ return err |
|
| 62 |
+ } |
|
| 63 |
+ } |
|
| 64 |
+ return nil |
|
| 65 |
+ } |
|
| 66 |
+} |
|
| 67 |
+ |
|
| 68 |
+// WithBinaryFiles adds the specified files in the build context, content is binary |
|
| 69 |
+func WithBinaryFiles(files map[string]*bytes.Buffer) func(*Fake) error {
|
|
| 70 |
+ return func(fakeContext *Fake) error {
|
|
| 71 |
+ for file, content := range files {
|
|
| 72 |
+ if err := fakeContext.Add(file, string(content.Bytes())); err != nil {
|
|
| 73 |
+ return err |
|
| 74 |
+ } |
|
| 75 |
+ } |
|
| 76 |
+ return nil |
|
| 77 |
+ } |
|
| 78 |
+} |
|
| 79 |
+ |
|
| 80 |
+// Fake creates directories that can be used as a build context |
|
| 81 |
+type Fake struct {
|
|
| 82 |
+ Dir string |
|
| 83 |
+} |
|
| 84 |
+ |
|
| 85 |
+// Add a file at a path, creating directories where necessary |
|
| 86 |
+func (f *Fake) Add(file, content string) error {
|
|
| 87 |
+ return f.addFile(file, []byte(content)) |
|
| 88 |
+} |
|
| 89 |
+ |
|
| 90 |
+func (f *Fake) addFile(file string, content []byte) error {
|
|
| 91 |
+ fp := filepath.Join(f.Dir, filepath.FromSlash(file)) |
|
| 92 |
+ dirpath := filepath.Dir(fp) |
|
| 93 |
+ if dirpath != "." {
|
|
| 94 |
+ if err := os.MkdirAll(dirpath, 0755); err != nil {
|
|
| 95 |
+ return err |
|
| 96 |
+ } |
|
| 97 |
+ } |
|
| 98 |
+ return ioutil.WriteFile(fp, content, 0644) |
|
| 99 |
+ |
|
| 100 |
+} |
|
| 101 |
+ |
|
| 102 |
+// Delete a file at a path |
|
| 103 |
+func (f *Fake) Delete(file string) error {
|
|
| 104 |
+ fp := filepath.Join(f.Dir, filepath.FromSlash(file)) |
|
| 105 |
+ return os.RemoveAll(fp) |
|
| 106 |
+} |
|
| 107 |
+ |
|
| 108 |
+// Close deletes the context |
|
| 109 |
+func (f *Fake) Close() error {
|
|
| 110 |
+ return os.RemoveAll(f.Dir) |
|
| 111 |
+} |
| 0 | 112 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,67 @@ |
| 0 |
+package fakestorage |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "io/ioutil" |
|
| 4 |
+ "os" |
|
| 5 |
+ "os/exec" |
|
| 6 |
+ "path/filepath" |
|
| 7 |
+ "sync" |
|
| 8 |
+ |
|
| 9 |
+ "github.com/docker/docker/integration-cli/cli" |
|
| 10 |
+) |
|
| 11 |
+ |
|
| 12 |
+var ensureHTTPServerOnce sync.Once |
|
| 13 |
+ |
|
| 14 |
+func ensureHTTPServerImage(t testingT) {
|
|
| 15 |
+ var doIt bool |
|
| 16 |
+ ensureHTTPServerOnce.Do(func() {
|
|
| 17 |
+ doIt = true |
|
| 18 |
+ }) |
|
| 19 |
+ |
|
| 20 |
+ if !doIt {
|
|
| 21 |
+ return |
|
| 22 |
+ } |
|
| 23 |
+ |
|
| 24 |
+ defer testEnv.ProtectImage(t, "httpserver:latest") |
|
| 25 |
+ |
|
| 26 |
+ tmp, err := ioutil.TempDir("", "docker-http-server-test")
|
|
| 27 |
+ if err != nil {
|
|
| 28 |
+ t.Fatalf("could not build http server: %v", err)
|
|
| 29 |
+ } |
|
| 30 |
+ defer os.RemoveAll(tmp) |
|
| 31 |
+ |
|
| 32 |
+ goos := testEnv.DaemonPlatform() |
|
| 33 |
+ if goos == "" {
|
|
| 34 |
+ goos = "linux" |
|
| 35 |
+ } |
|
| 36 |
+ goarch := os.Getenv("DOCKER_ENGINE_GOARCH")
|
|
| 37 |
+ if goarch == "" {
|
|
| 38 |
+ goarch = "amd64" |
|
| 39 |
+ } |
|
| 40 |
+ |
|
| 41 |
+ goCmd, lookErr := exec.LookPath("go")
|
|
| 42 |
+ if lookErr != nil {
|
|
| 43 |
+ t.Fatalf("could not build http server: %v", lookErr)
|
|
| 44 |
+ } |
|
| 45 |
+ |
|
| 46 |
+ cmd := exec.Command(goCmd, "build", "-o", filepath.Join(tmp, "httpserver"), "github.com/docker/docker/contrib/httpserver") |
|
| 47 |
+ cmd.Env = append(os.Environ(), []string{
|
|
| 48 |
+ "CGO_ENABLED=0", |
|
| 49 |
+ "GOOS=" + goos, |
|
| 50 |
+ "GOARCH=" + goarch, |
|
| 51 |
+ }...) |
|
| 52 |
+ var out []byte |
|
| 53 |
+ if out, err = cmd.CombinedOutput(); err != nil {
|
|
| 54 |
+ t.Fatalf("could not build http server: %s", string(out))
|
|
| 55 |
+ } |
|
| 56 |
+ |
|
| 57 |
+ cpCmd, lookErr := exec.LookPath("cp")
|
|
| 58 |
+ if lookErr != nil {
|
|
| 59 |
+ t.Fatalf("could not build http server: %v", lookErr)
|
|
| 60 |
+ } |
|
| 61 |
+ if out, err = exec.Command(cpCmd, "../contrib/httpserver/Dockerfile", filepath.Join(tmp, "Dockerfile")).CombinedOutput(); err != nil {
|
|
| 62 |
+ t.Fatalf("could not build http server: %v", string(out))
|
|
| 63 |
+ } |
|
| 64 |
+ |
|
| 65 |
+ cli.DockerCmd(t, "build", "-q", "-t", "httpserver", tmp) |
|
| 66 |
+} |
| 0 | 67 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,176 @@ |
| 0 |
+package fakestorage |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "fmt" |
|
| 4 |
+ "net" |
|
| 5 |
+ "net/http" |
|
| 6 |
+ "net/http/httptest" |
|
| 7 |
+ "net/url" |
|
| 8 |
+ "os" |
|
| 9 |
+ "strings" |
|
| 10 |
+ "sync" |
|
| 11 |
+ |
|
| 12 |
+ "github.com/docker/docker/integration-cli/cli" |
|
| 13 |
+ "github.com/docker/docker/integration-cli/cli/build" |
|
| 14 |
+ "github.com/docker/docker/integration-cli/cli/build/fakecontext" |
|
| 15 |
+ "github.com/docker/docker/integration-cli/environment" |
|
| 16 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 17 |
+ "github.com/docker/docker/pkg/stringutils" |
|
| 18 |
+) |
|
| 19 |
+ |
|
| 20 |
+var ( |
|
| 21 |
+ testEnv *environment.Execution |
|
| 22 |
+ onlyOnce sync.Once |
|
| 23 |
+) |
|
| 24 |
+ |
|
| 25 |
+// EnsureTestEnvIsLoaded make sure the test environment is loaded for this package |
|
| 26 |
+func EnsureTestEnvIsLoaded(t testingT) {
|
|
| 27 |
+ var doIt bool |
|
| 28 |
+ var err error |
|
| 29 |
+ onlyOnce.Do(func() {
|
|
| 30 |
+ doIt = true |
|
| 31 |
+ }) |
|
| 32 |
+ |
|
| 33 |
+ if !doIt {
|
|
| 34 |
+ return |
|
| 35 |
+ } |
|
| 36 |
+ testEnv, err = environment.New() |
|
| 37 |
+ if err != nil {
|
|
| 38 |
+ t.Fatalf("error loading testenv : %v", err)
|
|
| 39 |
+ } |
|
| 40 |
+} |
|
| 41 |
+ |
|
| 42 |
+type testingT interface {
|
|
| 43 |
+ logT |
|
| 44 |
+ Fatal(args ...interface{})
|
|
| 45 |
+ Fatalf(string, ...interface{})
|
|
| 46 |
+} |
|
| 47 |
+ |
|
| 48 |
+type logT interface {
|
|
| 49 |
+ Logf(string, ...interface{})
|
|
| 50 |
+} |
|
| 51 |
+ |
|
| 52 |
+// Fake is a static file server. It might be running locally or remotely |
|
| 53 |
+// on test host. |
|
| 54 |
+type Fake interface {
|
|
| 55 |
+ Close() error |
|
| 56 |
+ URL() string |
|
| 57 |
+ CtxDir() string |
|
| 58 |
+} |
|
| 59 |
+ |
|
| 60 |
+// New returns a static file server that will be use as build context. |
|
| 61 |
+func New(t testingT, dir string, modifiers ...func(*fakecontext.Fake) error) Fake {
|
|
| 62 |
+ ctx := fakecontext.New(t, dir, modifiers...) |
|
| 63 |
+ if testEnv.LocalDaemon() {
|
|
| 64 |
+ return newLocalFakeStorage(t, ctx) |
|
| 65 |
+ } |
|
| 66 |
+ return newRemoteFileServer(t, ctx) |
|
| 67 |
+} |
|
| 68 |
+ |
|
| 69 |
+// localFileStorage is a file storage on the running machine |
|
| 70 |
+type localFileStorage struct {
|
|
| 71 |
+ *fakecontext.Fake |
|
| 72 |
+ *httptest.Server |
|
| 73 |
+} |
|
| 74 |
+ |
|
| 75 |
+func (s *localFileStorage) URL() string {
|
|
| 76 |
+ return s.Server.URL |
|
| 77 |
+} |
|
| 78 |
+ |
|
| 79 |
+func (s *localFileStorage) CtxDir() string {
|
|
| 80 |
+ return s.Fake.Dir |
|
| 81 |
+} |
|
| 82 |
+ |
|
| 83 |
+func (s *localFileStorage) Close() error {
|
|
| 84 |
+ defer s.Server.Close() |
|
| 85 |
+ return s.Fake.Close() |
|
| 86 |
+} |
|
| 87 |
+ |
|
| 88 |
+func newLocalFakeStorage(t testingT, ctx *fakecontext.Fake) *localFileStorage {
|
|
| 89 |
+ handler := http.FileServer(http.Dir(ctx.Dir)) |
|
| 90 |
+ server := httptest.NewServer(handler) |
|
| 91 |
+ return &localFileStorage{
|
|
| 92 |
+ Fake: ctx, |
|
| 93 |
+ Server: server, |
|
| 94 |
+ } |
|
| 95 |
+} |
|
| 96 |
+ |
|
| 97 |
+// remoteFileServer is a containerized static file server started on the remote |
|
| 98 |
+// testing machine to be used in URL-accepting docker build functionality. |
|
| 99 |
+type remoteFileServer struct {
|
|
| 100 |
+ host string // hostname/port web server is listening to on docker host e.g. 0.0.0.0:43712 |
|
| 101 |
+ container string |
|
| 102 |
+ image string |
|
| 103 |
+ ctx *fakecontext.Fake |
|
| 104 |
+} |
|
| 105 |
+ |
|
| 106 |
+func (f *remoteFileServer) URL() string {
|
|
| 107 |
+ u := url.URL{
|
|
| 108 |
+ Scheme: "http", |
|
| 109 |
+ Host: f.host} |
|
| 110 |
+ return u.String() |
|
| 111 |
+} |
|
| 112 |
+ |
|
| 113 |
+func (f *remoteFileServer) CtxDir() string {
|
|
| 114 |
+ return f.ctx.Dir |
|
| 115 |
+} |
|
| 116 |
+ |
|
| 117 |
+func (f *remoteFileServer) Close() error {
|
|
| 118 |
+ defer func() {
|
|
| 119 |
+ if f.ctx != nil {
|
|
| 120 |
+ f.ctx.Close() |
|
| 121 |
+ } |
|
| 122 |
+ if f.image != "" {
|
|
| 123 |
+ if err := cli.Docker(cli.Args("rmi", "-f", f.image)).Error; err != nil {
|
|
| 124 |
+ fmt.Fprintf(os.Stderr, "Error closing remote file server : %v\n", err) |
|
| 125 |
+ } |
|
| 126 |
+ } |
|
| 127 |
+ }() |
|
| 128 |
+ if f.container == "" {
|
|
| 129 |
+ return nil |
|
| 130 |
+ } |
|
| 131 |
+ return cli.Docker(cli.Args("rm", "-fv", f.container)).Error
|
|
| 132 |
+} |
|
| 133 |
+ |
|
| 134 |
+func newRemoteFileServer(t testingT, ctx *fakecontext.Fake) *remoteFileServer {
|
|
| 135 |
+ var ( |
|
| 136 |
+ image = fmt.Sprintf("fileserver-img-%s", strings.ToLower(stringutils.GenerateRandomAlphaOnlyString(10)))
|
|
| 137 |
+ container = fmt.Sprintf("fileserver-cnt-%s", strings.ToLower(stringutils.GenerateRandomAlphaOnlyString(10)))
|
|
| 138 |
+ ) |
|
| 139 |
+ |
|
| 140 |
+ ensureHTTPServerImage(t) |
|
| 141 |
+ |
|
| 142 |
+ // Build the image |
|
| 143 |
+ if err := ctx.Add("Dockerfile", `FROM httpserver
|
|
| 144 |
+COPY . /static`); err != nil {
|
|
| 145 |
+ t.Fatal(err) |
|
| 146 |
+ } |
|
| 147 |
+ cli.BuildCmd(t, image, build.WithoutCache, build.WithExternalBuildContext(ctx)) |
|
| 148 |
+ |
|
| 149 |
+ // Start the container |
|
| 150 |
+ cli.DockerCmd(t, "run", "-d", "-P", "--name", container, image) |
|
| 151 |
+ |
|
| 152 |
+ // Find out the system assigned port |
|
| 153 |
+ out := cli.DockerCmd(t, "port", container, "80/tcp").Combined() |
|
| 154 |
+ fileserverHostPort := strings.Trim(out, "\n") |
|
| 155 |
+ _, port, err := net.SplitHostPort(fileserverHostPort) |
|
| 156 |
+ if err != nil {
|
|
| 157 |
+ t.Fatalf("unable to parse file server host:port: %v", err)
|
|
| 158 |
+ } |
|
| 159 |
+ |
|
| 160 |
+ dockerHostURL, err := url.Parse(request.DaemonHost()) |
|
| 161 |
+ if err != nil {
|
|
| 162 |
+ t.Fatalf("unable to parse daemon host URL: %v", err)
|
|
| 163 |
+ } |
|
| 164 |
+ |
|
| 165 |
+ host, _, err := net.SplitHostPort(dockerHostURL.Host) |
|
| 166 |
+ if err != nil {
|
|
| 167 |
+ t.Fatalf("unable to parse docker daemon host:port: %v", err)
|
|
| 168 |
+ } |
|
| 169 |
+ |
|
| 170 |
+ return &remoteFileServer{
|
|
| 171 |
+ container: container, |
|
| 172 |
+ image: image, |
|
| 173 |
+ host: fmt.Sprintf("%s:%s", host, port),
|
|
| 174 |
+ ctx: ctx} |
|
| 175 |
+} |
| ... | ... |
@@ -9,6 +9,8 @@ import ( |
| 9 | 9 |
"strings" |
| 10 | 10 |
|
| 11 | 11 |
"github.com/docker/docker/integration-cli/checker" |
| 12 |
+ "github.com/docker/docker/integration-cli/cli/build/fakecontext" |
|
| 13 |
+ "github.com/docker/docker/integration-cli/cli/build/fakestorage" |
|
| 12 | 14 |
"github.com/docker/docker/integration-cli/request" |
| 13 | 15 |
"github.com/docker/docker/pkg/testutil" |
| 14 | 16 |
"github.com/go-check/check" |
| ... | ... |
@@ -29,7 +31,7 @@ COPY * /tmp/ |
| 29 | 29 |
RUN find / -xdev -name ba* |
| 30 | 30 |
RUN find /tmp/` |
| 31 | 31 |
} |
| 32 |
- server := fakeStorage(c, map[string]string{"testD": testD})
|
|
| 32 |
+ server := fakestorage.New(c, "", fakecontext.WithFiles(map[string]string{"testD": testD}))
|
|
| 33 | 33 |
defer server.Close() |
| 34 | 34 |
|
| 35 | 35 |
res, body, err := request.Post("/build?dockerfile=baz&remote="+server.URL()+"/testD", request.JSON)
|
| ... | ... |
@@ -66,9 +68,9 @@ func (s *DockerSuite) TestBuildAPIRemoteTarballContext(c *check.C) {
|
| 66 | 66 |
// failed to close tar archive |
| 67 | 67 |
c.Assert(tw.Close(), checker.IsNil) |
| 68 | 68 |
|
| 69 |
- server := fakeBinaryStorage(c, map[string]*bytes.Buffer{
|
|
| 69 |
+ server := fakestorage.New(c, "", fakecontext.WithBinaryFiles(map[string]*bytes.Buffer{
|
|
| 70 | 70 |
"testT.tar": buffer, |
| 71 |
- }) |
|
| 71 |
+ })) |
|
| 72 | 72 |
defer server.Close() |
| 73 | 73 |
|
| 74 | 74 |
res, b, err := request.Post("/build?remote="+server.URL()+"/testT.tar", request.ContentType("application/tar"))
|
| ... | ... |
@@ -113,9 +115,9 @@ RUN echo 'right' |
| 113 | 113 |
// failed to close tar archive |
| 114 | 114 |
c.Assert(tw.Close(), checker.IsNil) |
| 115 | 115 |
|
| 116 |
- server := fakeBinaryStorage(c, map[string]*bytes.Buffer{
|
|
| 116 |
+ server := fakestorage.New(c, "", fakecontext.WithBinaryFiles(map[string]*bytes.Buffer{
|
|
| 117 | 117 |
"testT.tar": buffer, |
| 118 |
- }) |
|
| 118 |
+ })) |
|
| 119 | 119 |
defer server.Close() |
| 120 | 120 |
|
| 121 | 121 |
url := "/build?dockerfile=custom&remote=" + server.URL() + "/testT.tar" |
| ... | ... |
@@ -20,6 +20,8 @@ import ( |
| 20 | 20 |
"github.com/docker/docker/integration-cli/checker" |
| 21 | 21 |
"github.com/docker/docker/integration-cli/cli" |
| 22 | 22 |
"github.com/docker/docker/integration-cli/cli/build" |
| 23 |
+ "github.com/docker/docker/integration-cli/cli/build/fakecontext" |
|
| 24 |
+ "github.com/docker/docker/integration-cli/cli/build/fakestorage" |
|
| 23 | 25 |
"github.com/docker/docker/pkg/archive" |
| 24 | 26 |
"github.com/docker/docker/pkg/stringutils" |
| 25 | 27 |
"github.com/docker/docker/pkg/testutil" |
| ... | ... |
@@ -143,8 +145,8 @@ func (s *DockerSuite) TestBuildEnvironmentReplacementWorkdir(c *check.C) {
|
| 143 | 143 |
func (s *DockerSuite) TestBuildEnvironmentReplacementAddCopy(c *check.C) {
|
| 144 | 144 |
name := "testbuildenvironmentreplacement" |
| 145 | 145 |
|
| 146 |
- buildImageSuccessfully(c, name, withBuildContext(c, |
|
| 147 |
- withFile("Dockerfile", `
|
|
| 146 |
+ buildImageSuccessfully(c, name, build.WithBuildContext(c, |
|
| 147 |
+ build.WithFile("Dockerfile", `
|
|
| 148 | 148 |
FROM `+minimalBaseImage()+` |
| 149 | 149 |
ENV baz foo |
| 150 | 150 |
ENV quux bar |
| ... | ... |
@@ -157,10 +159,10 @@ func (s *DockerSuite) TestBuildEnvironmentReplacementAddCopy(c *check.C) {
|
| 157 | 157 |
ADD ${zzz:-${fee}} ${dot}
|
| 158 | 158 |
COPY ${zzz:-${gee}} ${dot}
|
| 159 | 159 |
`), |
| 160 |
- withFile("foo", "test1"),
|
|
| 161 |
- withFile("bar", "test2"),
|
|
| 162 |
- withFile("fff", "test3"),
|
|
| 163 |
- withFile("ggg", "test4"),
|
|
| 160 |
+ build.WithFile("foo", "test1"),
|
|
| 161 |
+ build.WithFile("bar", "test2"),
|
|
| 162 |
+ build.WithFile("fff", "test3"),
|
|
| 163 |
+ build.WithFile("ggg", "test4"),
|
|
| 164 | 164 |
)) |
| 165 | 165 |
} |
| 166 | 166 |
|
| ... | ... |
@@ -362,10 +364,10 @@ ONBUILD ENTRYPOINT ["echo"]`)) |
| 362 | 362 |
func (s *DockerSuite) TestBuildCacheAdd(c *check.C) {
|
| 363 | 363 |
testRequires(c, DaemonIsLinux) // Windows doesn't have httpserver image yet |
| 364 | 364 |
name := "testbuildtwoimageswithadd" |
| 365 |
- server := fakeStorage(c, map[string]string{
|
|
| 365 |
+ server := fakestorage.New(c, "", fakecontext.WithFiles(map[string]string{
|
|
| 366 | 366 |
"robots.txt": "hello", |
| 367 | 367 |
"index.html": "world", |
| 368 |
- }) |
|
| 368 |
+ })) |
|
| 369 | 369 |
defer server.Close() |
| 370 | 370 |
|
| 371 | 371 |
cli.BuildCmd(c, name, build.WithDockerfile(fmt.Sprintf(`FROM scratch |
| ... | ... |
@@ -386,9 +388,9 @@ func (s *DockerSuite) TestBuildLastModified(c *check.C) {
|
| 386 | 386 |
|
| 387 | 387 |
name := "testbuildlastmodified" |
| 388 | 388 |
|
| 389 |
- server := fakeStorage(c, map[string]string{
|
|
| 389 |
+ server := fakestorage.New(c, "", fakecontext.WithFiles(map[string]string{
|
|
| 390 | 390 |
"file": "hello", |
| 391 |
- }) |
|
| 391 |
+ })) |
|
| 392 | 392 |
defer server.Close() |
| 393 | 393 |
|
| 394 | 394 |
var out, out2 string |
| ... | ... |
@@ -397,15 +399,15 @@ func (s *DockerSuite) TestBuildLastModified(c *check.C) {
|
| 397 | 397 |
ADD %s/file /` |
| 398 | 398 |
dockerfile := fmt.Sprintf(dFmt, server.URL()) |
| 399 | 399 |
|
| 400 |
- buildImageSuccessfully(c, name, build.WithoutCache, build.WithDockerfile(dockerfile)) |
|
| 401 |
- out, _ = dockerCmd(c, "run", name, "ls", "-le", "/file") |
|
| 400 |
+ cli.BuildCmd(c, name, build.WithoutCache, build.WithDockerfile(dockerfile)) |
|
| 401 |
+ out = cli.DockerCmd(c, "run", name, "ls", "-le", "/file").Combined() |
|
| 402 | 402 |
|
| 403 | 403 |
// Build it again and make sure the mtime of the file didn't change. |
| 404 | 404 |
// Wait a few seconds to make sure the time changed enough to notice |
| 405 | 405 |
time.Sleep(2 * time.Second) |
| 406 | 406 |
|
| 407 |
- buildImageSuccessfully(c, name, build.WithoutCache, build.WithDockerfile(dockerfile)) |
|
| 408 |
- out2, _ = dockerCmd(c, "run", name, "ls", "-le", "/file") |
|
| 407 |
+ cli.BuildCmd(c, name, build.WithoutCache, build.WithDockerfile(dockerfile)) |
|
| 408 |
+ out2 = cli.DockerCmd(c, "run", name, "ls", "-le", "/file").Combined() |
|
| 409 | 409 |
|
| 410 | 410 |
if out != out2 {
|
| 411 | 411 |
c.Fatalf("MTime changed:\nOrigin:%s\nNew:%s", out, out2)
|
| ... | ... |
@@ -413,14 +415,14 @@ ADD %s/file /` |
| 413 | 413 |
|
| 414 | 414 |
// Now 'touch' the file and make sure the timestamp DID change this time |
| 415 | 415 |
// Create a new fakeStorage instead of just using Add() to help windows |
| 416 |
- server = fakeStorage(c, map[string]string{
|
|
| 416 |
+ server = fakestorage.New(c, "", fakecontext.WithFiles(map[string]string{
|
|
| 417 | 417 |
"file": "hello", |
| 418 |
- }) |
|
| 418 |
+ })) |
|
| 419 | 419 |
defer server.Close() |
| 420 | 420 |
|
| 421 | 421 |
dockerfile = fmt.Sprintf(dFmt, server.URL()) |
| 422 |
- buildImageSuccessfully(c, name, build.WithoutCache, build.WithDockerfile(dockerfile)) |
|
| 423 |
- out2, _ = dockerCmd(c, "run", name, "ls", "-le", "/file") |
|
| 422 |
+ cli.BuildCmd(c, name, build.WithoutCache, build.WithDockerfile(dockerfile)) |
|
| 423 |
+ out2 = cli.DockerCmd(c, "run", name, "ls", "-le", "/file").Combined() |
|
| 424 | 424 |
|
| 425 | 425 |
if out == out2 {
|
| 426 | 426 |
c.Fatalf("MTime didn't change:\nOrigin:%s\nNew:%s", out, out2)
|
| ... | ... |
@@ -434,20 +436,19 @@ ADD %s/file /` |
| 434 | 434 |
func (s *DockerSuite) TestBuildModifyFileInFolder(c *check.C) {
|
| 435 | 435 |
name := "testbuildmodifyfileinfolder" |
| 436 | 436 |
|
| 437 |
- ctx := fakeContext(c, `FROM busybox |
|
| 437 |
+ ctx := fakecontext.New(c, "", fakecontext.WithDockerfile(`FROM busybox |
|
| 438 | 438 |
RUN ["mkdir", "/test"] |
| 439 |
-ADD folder/file /test/changetarget`, |
|
| 440 |
- map[string]string{})
|
|
| 439 |
+ADD folder/file /test/changetarget`)) |
|
| 441 | 440 |
defer ctx.Close() |
| 442 | 441 |
if err := ctx.Add("folder/file", "first"); err != nil {
|
| 443 | 442 |
c.Fatal(err) |
| 444 | 443 |
} |
| 445 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 444 |
+ buildImageSuccessfully(c, name, build.WithExternalBuildContext(ctx)) |
|
| 446 | 445 |
id1 := getIDByName(c, name) |
| 447 | 446 |
if err := ctx.Add("folder/file", "second"); err != nil {
|
| 448 | 447 |
c.Fatal(err) |
| 449 | 448 |
} |
| 450 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 449 |
+ buildImageSuccessfully(c, name, build.WithExternalBuildContext(ctx)) |
|
| 451 | 450 |
id2 := getIDByName(c, name) |
| 452 | 451 |
if id1 == id2 {
|
| 453 | 452 |
c.Fatal("cache was used even though file contents in folder was changed")
|
| ... | ... |
@@ -456,8 +457,8 @@ ADD folder/file /test/changetarget`, |
| 456 | 456 |
|
| 457 | 457 |
func (s *DockerSuite) TestBuildAddSingleFileToRoot(c *check.C) {
|
| 458 | 458 |
testRequires(c, DaemonIsLinux) // Linux specific test |
| 459 |
- buildImageSuccessfully(c, "testaddimg", withBuildContext(c, |
|
| 460 |
- withFile("Dockerfile", fmt.Sprintf(`FROM busybox
|
|
| 459 |
+ buildImageSuccessfully(c, "testaddimg", build.WithBuildContext(c, |
|
| 460 |
+ build.WithFile("Dockerfile", fmt.Sprintf(`FROM busybox
|
|
| 461 | 461 |
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd |
| 462 | 462 |
RUN echo 'dockerio:x:1001:' >> /etc/group |
| 463 | 463 |
RUN touch /exists |
| ... | ... |
@@ -466,22 +467,23 @@ ADD test_file / |
| 466 | 466 |
RUN [ $(ls -l /test_file | awk '{print $3":"$4}') = 'root:root' ]
|
| 467 | 467 |
RUN [ $(ls -l /test_file | awk '{print $1}') = '%s' ]
|
| 468 | 468 |
RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`, expectedFileChmod)),
|
| 469 |
- withFile("test_file", "test1")))
|
|
| 469 |
+ build.WithFile("test_file", "test1")))
|
|
| 470 | 470 |
} |
| 471 | 471 |
|
| 472 | 472 |
// Issue #3960: "ADD src ." hangs |
| 473 | 473 |
func (s *DockerSuite) TestBuildAddSingleFileToWorkdir(c *check.C) {
|
| 474 | 474 |
name := "testaddsinglefiletoworkdir" |
| 475 |
- ctx := fakeContext(c, `FROM busybox |
|
| 476 |
-ADD test_file .`, |
|
| 477 |
- map[string]string{
|
|
| 475 |
+ ctx := fakecontext.New(c, "", fakecontext.WithDockerfile( |
|
| 476 |
+ `FROM busybox |
|
| 477 |
+ ADD test_file .`), |
|
| 478 |
+ fakecontext.WithFiles(map[string]string{
|
|
| 478 | 479 |
"test_file": "test1", |
| 479 |
- }) |
|
| 480 |
+ })) |
|
| 480 | 481 |
defer ctx.Close() |
| 481 | 482 |
|
| 482 | 483 |
errChan := make(chan error) |
| 483 | 484 |
go func() {
|
| 484 |
- errChan <- buildImage(name, withExternalBuildContext(ctx)).Error |
|
| 485 |
+ errChan <- buildImage(name, build.WithExternalBuildContext(ctx)).Error |
|
| 485 | 486 |
close(errChan) |
| 486 | 487 |
}() |
| 487 | 488 |
select {
|
| ... | ... |
@@ -494,8 +496,8 @@ ADD test_file .`, |
| 494 | 494 |
|
| 495 | 495 |
func (s *DockerSuite) TestBuildAddSingleFileToExistDir(c *check.C) {
|
| 496 | 496 |
testRequires(c, DaemonIsLinux) // Linux specific test |
| 497 |
- buildImageSuccessfully(c, "testaddsinglefiletoexistdir", withBuildContext(c, |
|
| 498 |
- withFile("Dockerfile", `FROM busybox
|
|
| 497 |
+ buildImageSuccessfully(c, "testaddsinglefiletoexistdir", build.WithBuildContext(c, |
|
| 498 |
+ build.WithFile("Dockerfile", `FROM busybox
|
|
| 499 | 499 |
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd |
| 500 | 500 |
RUN echo 'dockerio:x:1001:' >> /etc/group |
| 501 | 501 |
RUN mkdir /exists |
| ... | ... |
@@ -505,18 +507,18 @@ ADD test_file /exists/ |
| 505 | 505 |
RUN [ $(ls -l / | grep exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]
|
| 506 | 506 |
RUN [ $(ls -l /exists/test_file | awk '{print $3":"$4}') = 'root:root' ]
|
| 507 | 507 |
RUN [ $(ls -l /exists/exists_file | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`),
|
| 508 |
- withFile("test_file", "test1")))
|
|
| 508 |
+ build.WithFile("test_file", "test1")))
|
|
| 509 | 509 |
} |
| 510 | 510 |
|
| 511 | 511 |
func (s *DockerSuite) TestBuildCopyAddMultipleFiles(c *check.C) {
|
| 512 | 512 |
testRequires(c, DaemonIsLinux) // Linux specific test |
| 513 |
- server := fakeStorage(c, map[string]string{
|
|
| 513 |
+ server := fakestorage.New(c, "", fakecontext.WithFiles(map[string]string{
|
|
| 514 | 514 |
"robots.txt": "hello", |
| 515 |
- }) |
|
| 515 |
+ })) |
|
| 516 | 516 |
defer server.Close() |
| 517 | 517 |
|
| 518 |
- buildImageSuccessfully(c, "testcopymultiplefilestofile", withBuildContext(c, |
|
| 519 |
- withFile("Dockerfile", fmt.Sprintf(`FROM busybox
|
|
| 518 |
+ cli.BuildCmd(c, "testcopymultiplefilestofile", build.WithBuildContext(c, |
|
| 519 |
+ build.WithFile("Dockerfile", fmt.Sprintf(`FROM busybox
|
|
| 520 | 520 |
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd |
| 521 | 521 |
RUN echo 'dockerio:x:1001:' >> /etc/group |
| 522 | 522 |
RUN mkdir /exists |
| ... | ... |
@@ -532,11 +534,11 @@ RUN [ $(ls -l /exists/test_file4 | awk '{print $3":"$4}') = 'root:root' ]
|
| 532 | 532 |
RUN [ $(ls -l /exists/robots.txt | awk '{print $3":"$4}') = 'root:root' ]
|
| 533 | 533 |
RUN [ $(ls -l /exists/exists_file | awk '{print $3":"$4}') = 'dockerio:dockerio' ]
|
| 534 | 534 |
`, server.URL())), |
| 535 |
- withFile("test_file1", "test1"),
|
|
| 536 |
- withFile("test_file2", "test2"),
|
|
| 537 |
- withFile("test_file3", "test3"),
|
|
| 538 |
- withFile("test_file3", "test3"),
|
|
| 539 |
- withFile("test_file4", "test4")))
|
|
| 535 |
+ build.WithFile("test_file1", "test1"),
|
|
| 536 |
+ build.WithFile("test_file2", "test2"),
|
|
| 537 |
+ build.WithFile("test_file3", "test3"),
|
|
| 538 |
+ build.WithFile("test_file3", "test3"),
|
|
| 539 |
+ build.WithFile("test_file4", "test4")))
|
|
| 540 | 540 |
} |
| 541 | 541 |
|
| 542 | 542 |
// These tests are mainly for user namespaces to verify that new directories |
| ... | ... |
@@ -550,11 +552,11 @@ func (s *DockerSuite) TestBuildUsernamespaceValidateRemappedRoot(c *check.C) {
|
| 550 | 550 |
} |
| 551 | 551 |
name := "testbuildusernamespacevalidateremappedroot" |
| 552 | 552 |
for _, tc := range testCases {
|
| 553 |
- buildImageSuccessfully(c, name, withBuildContext(c, |
|
| 554 |
- withFile("Dockerfile", fmt.Sprintf(`FROM busybox
|
|
| 553 |
+ buildImageSuccessfully(c, name, build.WithBuildContext(c, |
|
| 554 |
+ build.WithFile("Dockerfile", fmt.Sprintf(`FROM busybox
|
|
| 555 | 555 |
%s |
| 556 | 556 |
RUN [ $(ls -l / | grep new_dir | awk '{print $3":"$4}') = 'root:root' ]`, tc)),
|
| 557 |
- withFile("test_dir/test_file", "test file")))
|
|
| 557 |
+ build.WithFile("test_dir/test_file", "test file")))
|
|
| 558 | 558 |
|
| 559 | 559 |
dockerCmd(c, "rmi", name) |
| 560 | 560 |
} |
| ... | ... |
@@ -565,8 +567,8 @@ func (s *DockerSuite) TestBuildAddAndCopyFileWithWhitespace(c *check.C) {
|
| 565 | 565 |
name := "testaddfilewithwhitespace" |
| 566 | 566 |
|
| 567 | 567 |
for _, command := range []string{"ADD", "COPY"} {
|
| 568 |
- buildImageSuccessfully(c, name, withBuildContext(c, |
|
| 569 |
- withFile("Dockerfile", fmt.Sprintf(`FROM busybox
|
|
| 568 |
+ buildImageSuccessfully(c, name, build.WithBuildContext(c, |
|
| 569 |
+ build.WithFile("Dockerfile", fmt.Sprintf(`FROM busybox
|
|
| 570 | 570 |
RUN mkdir "/test dir" |
| 571 | 571 |
RUN mkdir "/test_dir" |
| 572 | 572 |
%s [ "test file1", "/test_file1" ] |
| ... | ... |
@@ -581,12 +583,12 @@ RUN [ $(cat "/test file3") = 'test3' ] |
| 581 | 581 |
RUN [ $(cat "/test_dir/test_file4") = 'test4' ] |
| 582 | 582 |
RUN [ $(cat "/test dir/test_file5") = 'test5' ] |
| 583 | 583 |
RUN [ $(cat "/test dir/test_file6") = 'test6' ]`, command, command, command, command, command, command)), |
| 584 |
- withFile("test file1", "test1"),
|
|
| 585 |
- withFile("test_file2", "test2"),
|
|
| 586 |
- withFile("test file3", "test3"),
|
|
| 587 |
- withFile("test dir/test_file4", "test4"),
|
|
| 588 |
- withFile("test_dir/test_file5", "test5"),
|
|
| 589 |
- withFile("test dir/test_file6", "test6"),
|
|
| 584 |
+ build.WithFile("test file1", "test1"),
|
|
| 585 |
+ build.WithFile("test_file2", "test2"),
|
|
| 586 |
+ build.WithFile("test file3", "test3"),
|
|
| 587 |
+ build.WithFile("test dir/test_file4", "test4"),
|
|
| 588 |
+ build.WithFile("test_dir/test_file5", "test5"),
|
|
| 589 |
+ build.WithFile("test dir/test_file6", "test6"),
|
|
| 590 | 590 |
)) |
| 591 | 591 |
|
| 592 | 592 |
dockerCmd(c, "rmi", name) |
| ... | ... |
@@ -612,26 +614,26 @@ RUN find "test5" "C:/test dir/test_file5" |
| 612 | 612 |
RUN find "test6" "C:/test dir/test_file6"` |
| 613 | 613 |
|
| 614 | 614 |
name := "testcopyfilewithwhitespace" |
| 615 |
- buildImageSuccessfully(c, name, withBuildContext(c, |
|
| 616 |
- withFile("Dockerfile", dockerfile),
|
|
| 617 |
- withFile("test file1", "test1"),
|
|
| 618 |
- withFile("test_file2", "test2"),
|
|
| 619 |
- withFile("test file3", "test3"),
|
|
| 620 |
- withFile("test dir/test_file4", "test4"),
|
|
| 621 |
- withFile("test_dir/test_file5", "test5"),
|
|
| 622 |
- withFile("test dir/test_file6", "test6"),
|
|
| 615 |
+ buildImageSuccessfully(c, name, build.WithBuildContext(c, |
|
| 616 |
+ build.WithFile("Dockerfile", dockerfile),
|
|
| 617 |
+ build.WithFile("test file1", "test1"),
|
|
| 618 |
+ build.WithFile("test_file2", "test2"),
|
|
| 619 |
+ build.WithFile("test file3", "test3"),
|
|
| 620 |
+ build.WithFile("test dir/test_file4", "test4"),
|
|
| 621 |
+ build.WithFile("test_dir/test_file5", "test5"),
|
|
| 622 |
+ build.WithFile("test dir/test_file6", "test6"),
|
|
| 623 | 623 |
)) |
| 624 | 624 |
} |
| 625 | 625 |
|
| 626 | 626 |
func (s *DockerSuite) TestBuildCopyWildcard(c *check.C) {
|
| 627 | 627 |
name := "testcopywildcard" |
| 628 |
- server := fakeStorage(c, map[string]string{
|
|
| 628 |
+ server := fakestorage.New(c, "", fakecontext.WithFiles(map[string]string{
|
|
| 629 | 629 |
"robots.txt": "hello", |
| 630 | 630 |
"index.html": "world", |
| 631 |
- }) |
|
| 631 |
+ })) |
|
| 632 | 632 |
defer server.Close() |
| 633 | 633 |
|
| 634 |
- ctx := fakeContext(c, fmt.Sprintf(`FROM busybox |
|
| 634 |
+ ctx := fakecontext.New(c, "", fakecontext.WithDockerfile(fmt.Sprintf(`FROM busybox |
|
| 635 | 635 |
COPY file*.txt /tmp/ |
| 636 | 636 |
RUN ls /tmp/file1.txt /tmp/file2.txt |
| 637 | 637 |
RUN [ "mkdir", "/tmp1" ] |
| ... | ... |
@@ -640,21 +642,21 @@ func (s *DockerSuite) TestBuildCopyWildcard(c *check.C) {
|
| 640 | 640 |
RUN [ "mkdir", "/tmp2" ] |
| 641 | 641 |
ADD dir/*dir %s/robots.txt /tmp2/ |
| 642 | 642 |
RUN ls /tmp2/nest_nest_file /tmp2/robots.txt |
| 643 |
- `, server.URL()), |
|
| 644 |
- map[string]string{
|
|
| 643 |
+ `, server.URL())), |
|
| 644 |
+ fakecontext.WithFiles(map[string]string{
|
|
| 645 | 645 |
"file1.txt": "test1", |
| 646 | 646 |
"file2.txt": "test2", |
| 647 | 647 |
"dir/nested_file": "nested file", |
| 648 | 648 |
"dir/nested_dir/nest_nest_file": "2 times nested", |
| 649 | 649 |
"dirt": "dirty", |
| 650 |
- }) |
|
| 650 |
+ })) |
|
| 651 | 651 |
defer ctx.Close() |
| 652 | 652 |
|
| 653 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 653 |
+ cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) |
|
| 654 | 654 |
id1 := getIDByName(c, name) |
| 655 | 655 |
|
| 656 | 656 |
// Now make sure we use a cache the 2nd time |
| 657 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 657 |
+ cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) |
|
| 658 | 658 |
id2 := getIDByName(c, name) |
| 659 | 659 |
|
| 660 | 660 |
if id1 != id2 {
|
| ... | ... |
@@ -674,25 +676,25 @@ func (s *DockerSuite) TestBuildCopyWildcardInName(c *check.C) {
|
| 674 | 674 |
// say which OSs this works on or not. |
| 675 | 675 |
testRequires(c, DaemonIsLinux, UnixCli) |
| 676 | 676 |
|
| 677 |
- buildImageSuccessfully(c, "testcopywildcardinname", withBuildContext(c, |
|
| 678 |
- withFile("Dockerfile", `FROM busybox
|
|
| 677 |
+ buildImageSuccessfully(c, "testcopywildcardinname", build.WithBuildContext(c, |
|
| 678 |
+ build.WithFile("Dockerfile", `FROM busybox
|
|
| 679 | 679 |
COPY *.txt /tmp/ |
| 680 | 680 |
RUN [ "$(cat /tmp/\*.txt)" = 'hi there' ] |
| 681 | 681 |
`), |
| 682 |
- withFile("*.txt", "hi there"),
|
|
| 682 |
+ build.WithFile("*.txt", "hi there"),
|
|
| 683 | 683 |
)) |
| 684 | 684 |
} |
| 685 | 685 |
|
| 686 | 686 |
func (s *DockerSuite) TestBuildCopyWildcardCache(c *check.C) {
|
| 687 | 687 |
name := "testcopywildcardcache" |
| 688 |
- ctx := fakeContext(c, `FROM busybox |
|
| 689 |
- COPY file1.txt /tmp/`, |
|
| 690 |
- map[string]string{
|
|
| 688 |
+ ctx := fakecontext.New(c, "", fakecontext.WithDockerfile(`FROM busybox |
|
| 689 |
+ COPY file1.txt /tmp/`), |
|
| 690 |
+ fakecontext.WithFiles(map[string]string{
|
|
| 691 | 691 |
"file1.txt": "test1", |
| 692 |
- }) |
|
| 692 |
+ })) |
|
| 693 | 693 |
defer ctx.Close() |
| 694 | 694 |
|
| 695 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 695 |
+ buildImageSuccessfully(c, name, build.WithExternalBuildContext(ctx)) |
|
| 696 | 696 |
id1 := getIDByName(c, name) |
| 697 | 697 |
|
| 698 | 698 |
// Now make sure we use a cache the 2nd time even with wild cards. |
| ... | ... |
@@ -700,7 +702,7 @@ func (s *DockerSuite) TestBuildCopyWildcardCache(c *check.C) {
|
| 700 | 700 |
ctx.Add("Dockerfile", `FROM busybox
|
| 701 | 701 |
COPY file*.txt /tmp/`) |
| 702 | 702 |
|
| 703 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 703 |
+ buildImageSuccessfully(c, name, build.WithExternalBuildContext(ctx)) |
|
| 704 | 704 |
id2 := getIDByName(c, name) |
| 705 | 705 |
|
| 706 | 706 |
if id1 != id2 {
|
| ... | ... |
@@ -711,8 +713,8 @@ func (s *DockerSuite) TestBuildCopyWildcardCache(c *check.C) {
|
| 711 | 711 |
|
| 712 | 712 |
func (s *DockerSuite) TestBuildAddSingleFileToNonExistingDir(c *check.C) {
|
| 713 | 713 |
testRequires(c, DaemonIsLinux) // Linux specific test |
| 714 |
- buildImageSuccessfully(c, "testaddsinglefiletononexistingdir", withBuildContext(c, |
|
| 715 |
- withFile("Dockerfile", `FROM busybox
|
|
| 714 |
+ buildImageSuccessfully(c, "testaddsinglefiletononexistingdir", build.WithBuildContext(c, |
|
| 715 |
+ build.WithFile("Dockerfile", `FROM busybox
|
|
| 716 | 716 |
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd |
| 717 | 717 |
RUN echo 'dockerio:x:1001:' >> /etc/group |
| 718 | 718 |
RUN touch /exists |
| ... | ... |
@@ -721,13 +723,13 @@ ADD test_file /test_dir/ |
| 721 | 721 |
RUN [ $(ls -l / | grep test_dir | awk '{print $3":"$4}') = 'root:root' ]
|
| 722 | 722 |
RUN [ $(ls -l /test_dir/test_file | awk '{print $3":"$4}') = 'root:root' ]
|
| 723 | 723 |
RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`),
|
| 724 |
- withFile("test_file", "test1")))
|
|
| 724 |
+ build.WithFile("test_file", "test1")))
|
|
| 725 | 725 |
} |
| 726 | 726 |
|
| 727 | 727 |
func (s *DockerSuite) TestBuildAddDirContentToRoot(c *check.C) {
|
| 728 | 728 |
testRequires(c, DaemonIsLinux) // Linux specific test |
| 729 |
- buildImageSuccessfully(c, "testadddircontenttoroot", withBuildContext(c, |
|
| 730 |
- withFile("Dockerfile", `FROM busybox
|
|
| 729 |
+ buildImageSuccessfully(c, "testadddircontenttoroot", build.WithBuildContext(c, |
|
| 730 |
+ build.WithFile("Dockerfile", `FROM busybox
|
|
| 731 | 731 |
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd |
| 732 | 732 |
RUN echo 'dockerio:x:1001:' >> /etc/group |
| 733 | 733 |
RUN touch /exists |
| ... | ... |
@@ -735,13 +737,13 @@ RUN chown dockerio.dockerio exists |
| 735 | 735 |
ADD test_dir / |
| 736 | 736 |
RUN [ $(ls -l /test_file | awk '{print $3":"$4}') = 'root:root' ]
|
| 737 | 737 |
RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`),
|
| 738 |
- withFile("test_dir/test_file", "test1")))
|
|
| 738 |
+ build.WithFile("test_dir/test_file", "test1")))
|
|
| 739 | 739 |
} |
| 740 | 740 |
|
| 741 | 741 |
func (s *DockerSuite) TestBuildAddDirContentToExistingDir(c *check.C) {
|
| 742 | 742 |
testRequires(c, DaemonIsLinux) // Linux specific test |
| 743 |
- buildImageSuccessfully(c, "testadddircontenttoexistingdir", withBuildContext(c, |
|
| 744 |
- withFile("Dockerfile", `FROM busybox
|
|
| 743 |
+ buildImageSuccessfully(c, "testadddircontenttoexistingdir", build.WithBuildContext(c, |
|
| 744 |
+ build.WithFile("Dockerfile", `FROM busybox
|
|
| 745 | 745 |
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd |
| 746 | 746 |
RUN echo 'dockerio:x:1001:' >> /etc/group |
| 747 | 747 |
RUN mkdir /exists |
| ... | ... |
@@ -751,13 +753,13 @@ ADD test_dir/ /exists/ |
| 751 | 751 |
RUN [ $(ls -l / | grep exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]
|
| 752 | 752 |
RUN [ $(ls -l /exists/exists_file | awk '{print $3":"$4}') = 'dockerio:dockerio' ]
|
| 753 | 753 |
RUN [ $(ls -l /exists/test_file | awk '{print $3":"$4}') = 'root:root' ]`),
|
| 754 |
- withFile("test_dir/test_file", "test1")))
|
|
| 754 |
+ build.WithFile("test_dir/test_file", "test1")))
|
|
| 755 | 755 |
} |
| 756 | 756 |
|
| 757 | 757 |
func (s *DockerSuite) TestBuildAddWholeDirToRoot(c *check.C) {
|
| 758 | 758 |
testRequires(c, DaemonIsLinux) // Linux specific test |
| 759 |
- buildImageSuccessfully(c, "testaddwholedirtoroot", withBuildContext(c, |
|
| 760 |
- withFile("Dockerfile", fmt.Sprintf(`FROM busybox
|
|
| 759 |
+ buildImageSuccessfully(c, "testaddwholedirtoroot", build.WithBuildContext(c, |
|
| 760 |
+ build.WithFile("Dockerfile", fmt.Sprintf(`FROM busybox
|
|
| 761 | 761 |
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd |
| 762 | 762 |
RUN echo 'dockerio:x:1001:' >> /etc/group |
| 763 | 763 |
RUN touch /exists |
| ... | ... |
@@ -768,39 +770,39 @@ RUN [ $(ls -l / | grep test_dir | awk '{print $1}') = 'drwxr-xr-x' ]
|
| 768 | 768 |
RUN [ $(ls -l /test_dir/test_file | awk '{print $3":"$4}') = 'root:root' ]
|
| 769 | 769 |
RUN [ $(ls -l /test_dir/test_file | awk '{print $1}') = '%s' ]
|
| 770 | 770 |
RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`, expectedFileChmod)),
|
| 771 |
- withFile("test_dir/test_file", "test1")))
|
|
| 771 |
+ build.WithFile("test_dir/test_file", "test1")))
|
|
| 772 | 772 |
} |
| 773 | 773 |
|
| 774 | 774 |
// Testing #5941 : Having an etc directory in context conflicts with the /etc/mtab |
| 775 | 775 |
func (s *DockerSuite) TestBuildAddOrCopyEtcToRootShouldNotConflict(c *check.C) {
|
| 776 |
- buildImageSuccessfully(c, "testaddetctoroot", withBuildContext(c, |
|
| 777 |
- withFile("Dockerfile", `FROM `+minimalBaseImage()+`
|
|
| 776 |
+ buildImageSuccessfully(c, "testaddetctoroot", build.WithBuildContext(c, |
|
| 777 |
+ build.WithFile("Dockerfile", `FROM `+minimalBaseImage()+`
|
|
| 778 | 778 |
ADD . /`), |
| 779 |
- withFile("etc/test_file", "test1")))
|
|
| 780 |
- buildImageSuccessfully(c, "testcopyetctoroot", withBuildContext(c, |
|
| 781 |
- withFile("Dockerfile", `FROM `+minimalBaseImage()+`
|
|
| 779 |
+ build.WithFile("etc/test_file", "test1")))
|
|
| 780 |
+ buildImageSuccessfully(c, "testcopyetctoroot", build.WithBuildContext(c, |
|
| 781 |
+ build.WithFile("Dockerfile", `FROM `+minimalBaseImage()+`
|
|
| 782 | 782 |
COPY . /`), |
| 783 |
- withFile("etc/test_file", "test1")))
|
|
| 783 |
+ build.WithFile("etc/test_file", "test1")))
|
|
| 784 | 784 |
} |
| 785 | 785 |
|
| 786 | 786 |
// Testing #9401 : Losing setuid flag after a ADD |
| 787 | 787 |
func (s *DockerSuite) TestBuildAddPreservesFilesSpecialBits(c *check.C) {
|
| 788 | 788 |
testRequires(c, DaemonIsLinux) // Linux specific test |
| 789 |
- buildImageSuccessfully(c, "testaddetctoroot", withBuildContext(c, |
|
| 790 |
- withFile("Dockerfile", `FROM busybox
|
|
| 789 |
+ buildImageSuccessfully(c, "testaddetctoroot", build.WithBuildContext(c, |
|
| 790 |
+ build.WithFile("Dockerfile", `FROM busybox
|
|
| 791 | 791 |
ADD suidbin /usr/bin/suidbin |
| 792 | 792 |
RUN chmod 4755 /usr/bin/suidbin |
| 793 | 793 |
RUN [ $(ls -l /usr/bin/suidbin | awk '{print $1}') = '-rwsr-xr-x' ]
|
| 794 | 794 |
ADD ./data/ / |
| 795 | 795 |
RUN [ $(ls -l /usr/bin/suidbin | awk '{print $1}') = '-rwsr-xr-x' ]`),
|
| 796 |
- withFile("suidbin", "suidbin"),
|
|
| 797 |
- withFile("/data/usr/test_file", "test1")))
|
|
| 796 |
+ build.WithFile("suidbin", "suidbin"),
|
|
| 797 |
+ build.WithFile("/data/usr/test_file", "test1")))
|
|
| 798 | 798 |
} |
| 799 | 799 |
|
| 800 | 800 |
func (s *DockerSuite) TestBuildCopySingleFileToRoot(c *check.C) {
|
| 801 | 801 |
testRequires(c, DaemonIsLinux) // Linux specific test |
| 802 |
- buildImageSuccessfully(c, "testcopysinglefiletoroot", withBuildContext(c, |
|
| 803 |
- withFile("Dockerfile", fmt.Sprintf(`FROM busybox
|
|
| 802 |
+ buildImageSuccessfully(c, "testcopysinglefiletoroot", build.WithBuildContext(c, |
|
| 803 |
+ build.WithFile("Dockerfile", fmt.Sprintf(`FROM busybox
|
|
| 804 | 804 |
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd |
| 805 | 805 |
RUN echo 'dockerio:x:1001:' >> /etc/group |
| 806 | 806 |
RUN touch /exists |
| ... | ... |
@@ -809,22 +811,22 @@ COPY test_file / |
| 809 | 809 |
RUN [ $(ls -l /test_file | awk '{print $3":"$4}') = 'root:root' ]
|
| 810 | 810 |
RUN [ $(ls -l /test_file | awk '{print $1}') = '%s' ]
|
| 811 | 811 |
RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`, expectedFileChmod)),
|
| 812 |
- withFile("test_file", "test1")))
|
|
| 812 |
+ build.WithFile("test_file", "test1")))
|
|
| 813 | 813 |
} |
| 814 | 814 |
|
| 815 | 815 |
// Issue #3960: "ADD src ." hangs - adapted for COPY |
| 816 | 816 |
func (s *DockerSuite) TestBuildCopySingleFileToWorkdir(c *check.C) {
|
| 817 | 817 |
name := "testcopysinglefiletoworkdir" |
| 818 |
- ctx := fakeContext(c, `FROM busybox |
|
| 819 |
-COPY test_file .`, |
|
| 820 |
- map[string]string{
|
|
| 818 |
+ ctx := fakecontext.New(c, "", fakecontext.WithDockerfile(`FROM busybox |
|
| 819 |
+COPY test_file .`), |
|
| 820 |
+ fakecontext.WithFiles(map[string]string{
|
|
| 821 | 821 |
"test_file": "test1", |
| 822 |
- }) |
|
| 822 |
+ })) |
|
| 823 | 823 |
defer ctx.Close() |
| 824 | 824 |
|
| 825 | 825 |
errChan := make(chan error) |
| 826 | 826 |
go func() {
|
| 827 |
- errChan <- buildImage(name, withExternalBuildContext(ctx)).Error |
|
| 827 |
+ errChan <- buildImage(name, build.WithExternalBuildContext(ctx)).Error |
|
| 828 | 828 |
close(errChan) |
| 829 | 829 |
}() |
| 830 | 830 |
select {
|
| ... | ... |
@@ -837,8 +839,8 @@ COPY test_file .`, |
| 837 | 837 |
|
| 838 | 838 |
func (s *DockerSuite) TestBuildCopySingleFileToExistDir(c *check.C) {
|
| 839 | 839 |
testRequires(c, DaemonIsLinux) // Linux specific test |
| 840 |
- buildImageSuccessfully(c, "testcopysinglefiletoexistdir", withBuildContext(c, |
|
| 841 |
- withFile("Dockerfile", `FROM busybox
|
|
| 840 |
+ buildImageSuccessfully(c, "testcopysinglefiletoexistdir", build.WithBuildContext(c, |
|
| 841 |
+ build.WithFile("Dockerfile", `FROM busybox
|
|
| 842 | 842 |
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd |
| 843 | 843 |
RUN echo 'dockerio:x:1001:' >> /etc/group |
| 844 | 844 |
RUN mkdir /exists |
| ... | ... |
@@ -848,13 +850,13 @@ COPY test_file /exists/ |
| 848 | 848 |
RUN [ $(ls -l / | grep exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]
|
| 849 | 849 |
RUN [ $(ls -l /exists/test_file | awk '{print $3":"$4}') = 'root:root' ]
|
| 850 | 850 |
RUN [ $(ls -l /exists/exists_file | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`),
|
| 851 |
- withFile("test_file", "test1")))
|
|
| 851 |
+ build.WithFile("test_file", "test1")))
|
|
| 852 | 852 |
} |
| 853 | 853 |
|
| 854 | 854 |
func (s *DockerSuite) TestBuildCopySingleFileToNonExistDir(c *check.C) {
|
| 855 | 855 |
testRequires(c, DaemonIsLinux) // Linux specific |
| 856 |
- buildImageSuccessfully(c, "testcopysinglefiletononexistdir", withBuildContext(c, |
|
| 857 |
- withFile("Dockerfile", `FROM busybox
|
|
| 856 |
+ buildImageSuccessfully(c, "testcopysinglefiletononexistdir", build.WithBuildContext(c, |
|
| 857 |
+ build.WithFile("Dockerfile", `FROM busybox
|
|
| 858 | 858 |
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd |
| 859 | 859 |
RUN echo 'dockerio:x:1001:' >> /etc/group |
| 860 | 860 |
RUN touch /exists |
| ... | ... |
@@ -863,13 +865,13 @@ COPY test_file /test_dir/ |
| 863 | 863 |
RUN [ $(ls -l / | grep test_dir | awk '{print $3":"$4}') = 'root:root' ]
|
| 864 | 864 |
RUN [ $(ls -l /test_dir/test_file | awk '{print $3":"$4}') = 'root:root' ]
|
| 865 | 865 |
RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`),
|
| 866 |
- withFile("test_file", "test1")))
|
|
| 866 |
+ build.WithFile("test_file", "test1")))
|
|
| 867 | 867 |
} |
| 868 | 868 |
|
| 869 | 869 |
func (s *DockerSuite) TestBuildCopyDirContentToRoot(c *check.C) {
|
| 870 | 870 |
testRequires(c, DaemonIsLinux) // Linux specific test |
| 871 |
- buildImageSuccessfully(c, "testcopydircontenttoroot", withBuildContext(c, |
|
| 872 |
- withFile("Dockerfile", `FROM busybox
|
|
| 871 |
+ buildImageSuccessfully(c, "testcopydircontenttoroot", build.WithBuildContext(c, |
|
| 872 |
+ build.WithFile("Dockerfile", `FROM busybox
|
|
| 873 | 873 |
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd |
| 874 | 874 |
RUN echo 'dockerio:x:1001:' >> /etc/group |
| 875 | 875 |
RUN touch /exists |
| ... | ... |
@@ -877,13 +879,13 @@ RUN chown dockerio.dockerio exists |
| 877 | 877 |
COPY test_dir / |
| 878 | 878 |
RUN [ $(ls -l /test_file | awk '{print $3":"$4}') = 'root:root' ]
|
| 879 | 879 |
RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`),
|
| 880 |
- withFile("test_dir/test_file", "test1")))
|
|
| 880 |
+ build.WithFile("test_dir/test_file", "test1")))
|
|
| 881 | 881 |
} |
| 882 | 882 |
|
| 883 | 883 |
func (s *DockerSuite) TestBuildCopyDirContentToExistDir(c *check.C) {
|
| 884 | 884 |
testRequires(c, DaemonIsLinux) // Linux specific test |
| 885 |
- buildImageSuccessfully(c, "testcopydircontenttoexistdir", withBuildContext(c, |
|
| 886 |
- withFile("Dockerfile", `FROM busybox
|
|
| 885 |
+ buildImageSuccessfully(c, "testcopydircontenttoexistdir", build.WithBuildContext(c, |
|
| 886 |
+ build.WithFile("Dockerfile", `FROM busybox
|
|
| 887 | 887 |
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd |
| 888 | 888 |
RUN echo 'dockerio:x:1001:' >> /etc/group |
| 889 | 889 |
RUN mkdir /exists |
| ... | ... |
@@ -893,13 +895,13 @@ COPY test_dir/ /exists/ |
| 893 | 893 |
RUN [ $(ls -l / | grep exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]
|
| 894 | 894 |
RUN [ $(ls -l /exists/exists_file | awk '{print $3":"$4}') = 'dockerio:dockerio' ]
|
| 895 | 895 |
RUN [ $(ls -l /exists/test_file | awk '{print $3":"$4}') = 'root:root' ]`),
|
| 896 |
- withFile("test_dir/test_file", "test1")))
|
|
| 896 |
+ build.WithFile("test_dir/test_file", "test1")))
|
|
| 897 | 897 |
} |
| 898 | 898 |
|
| 899 | 899 |
func (s *DockerSuite) TestBuildCopyWholeDirToRoot(c *check.C) {
|
| 900 | 900 |
testRequires(c, DaemonIsLinux) // Linux specific test |
| 901 |
- buildImageSuccessfully(c, "testcopywholedirtoroot", withBuildContext(c, |
|
| 902 |
- withFile("Dockerfile", fmt.Sprintf(`FROM busybox
|
|
| 901 |
+ buildImageSuccessfully(c, "testcopywholedirtoroot", build.WithBuildContext(c, |
|
| 902 |
+ build.WithFile("Dockerfile", fmt.Sprintf(`FROM busybox
|
|
| 903 | 903 |
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd |
| 904 | 904 |
RUN echo 'dockerio:x:1001:' >> /etc/group |
| 905 | 905 |
RUN touch /exists |
| ... | ... |
@@ -910,7 +912,7 @@ RUN [ $(ls -l / | grep test_dir | awk '{print $1}') = 'drwxr-xr-x' ]
|
| 910 | 910 |
RUN [ $(ls -l /test_dir/test_file | awk '{print $3":"$4}') = 'root:root' ]
|
| 911 | 911 |
RUN [ $(ls -l /test_dir/test_file | awk '{print $1}') = '%s' ]
|
| 912 | 912 |
RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`, expectedFileChmod)),
|
| 913 |
- withFile("test_dir/test_file", "test1")))
|
|
| 913 |
+ build.WithFile("test_dir/test_file", "test1")))
|
|
| 914 | 914 |
} |
| 915 | 915 |
|
| 916 | 916 |
func (s *DockerSuite) TestBuildAddBadLinks(c *check.C) {
|
| ... | ... |
@@ -925,7 +927,7 @@ func (s *DockerSuite) TestBuildAddBadLinks(c *check.C) {
|
| 925 | 925 |
var ( |
| 926 | 926 |
name = "test-link-absolute" |
| 927 | 927 |
) |
| 928 |
- ctx := fakeContext(c, dockerfile, nil) |
|
| 928 |
+ ctx := fakecontext.New(c, "", fakecontext.WithDockerfile(dockerfile)) |
|
| 929 | 929 |
defer ctx.Close() |
| 930 | 930 |
|
| 931 | 931 |
tempDir, err := ioutil.TempDir("", "test-link-absolute-temp-")
|
| ... | ... |
@@ -986,7 +988,7 @@ func (s *DockerSuite) TestBuildAddBadLinks(c *check.C) {
|
| 986 | 986 |
c.Fatal(err) |
| 987 | 987 |
} |
| 988 | 988 |
|
| 989 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 989 |
+ buildImageSuccessfully(c, name, build.WithExternalBuildContext(ctx)) |
|
| 990 | 990 |
if _, err := os.Stat(nonExistingFile); err == nil || err != nil && !os.IsNotExist(err) {
|
| 991 | 991 |
c.Fatalf("%s shouldn't have been written and it shouldn't exist", nonExistingFile)
|
| 992 | 992 |
} |
| ... | ... |
@@ -1017,7 +1019,7 @@ func (s *DockerSuite) TestBuildAddBadLinksVolume(c *check.C) {
|
| 1017 | 1017 |
dockerfile = fmt.Sprintf(dockerfileTemplate, tempDir) |
| 1018 | 1018 |
nonExistingFile := filepath.Join(tempDir, targetFile) |
| 1019 | 1019 |
|
| 1020 |
- ctx := fakeContext(c, dockerfile, nil) |
|
| 1020 |
+ ctx := fakecontext.New(c, "", fakecontext.WithDockerfile(dockerfile)) |
|
| 1021 | 1021 |
defer ctx.Close() |
| 1022 | 1022 |
fooPath := filepath.Join(ctx.Dir, targetFile) |
| 1023 | 1023 |
|
| ... | ... |
@@ -1031,7 +1033,7 @@ func (s *DockerSuite) TestBuildAddBadLinksVolume(c *check.C) {
|
| 1031 | 1031 |
c.Fatal(err) |
| 1032 | 1032 |
} |
| 1033 | 1033 |
|
| 1034 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 1034 |
+ buildImageSuccessfully(c, name, build.WithExternalBuildContext(ctx)) |
|
| 1035 | 1035 |
if _, err := os.Stat(nonExistingFile); err == nil || err != nil && !os.IsNotExist(err) {
|
| 1036 | 1036 |
c.Fatalf("%s shouldn't have been written and it shouldn't exist", nonExistingFile)
|
| 1037 | 1037 |
} |
| ... | ... |
@@ -1045,7 +1047,10 @@ func (s *DockerSuite) TestBuildWithInaccessibleFilesInContext(c *check.C) {
|
| 1045 | 1045 |
|
| 1046 | 1046 |
{
|
| 1047 | 1047 |
name := "testbuildinaccessiblefiles" |
| 1048 |
- ctx := fakeContext(c, "FROM scratch\nADD . /foo/", map[string]string{"fileWithoutReadAccess": "foo"})
|
|
| 1048 |
+ ctx := fakecontext.New(c, "", |
|
| 1049 |
+ fakecontext.WithDockerfile("FROM scratch\nADD . /foo/"),
|
|
| 1050 |
+ fakecontext.WithFiles(map[string]string{"fileWithoutReadAccess": "foo"}),
|
|
| 1051 |
+ ) |
|
| 1049 | 1052 |
defer ctx.Close() |
| 1050 | 1053 |
// This is used to ensure we detect inaccessible files early during build in the cli client |
| 1051 | 1054 |
pathToFileWithoutReadAccess := filepath.Join(ctx.Dir, "fileWithoutReadAccess") |
| ... | ... |
@@ -1075,7 +1080,10 @@ func (s *DockerSuite) TestBuildWithInaccessibleFilesInContext(c *check.C) {
|
| 1075 | 1075 |
} |
| 1076 | 1076 |
{
|
| 1077 | 1077 |
name := "testbuildinaccessibledirectory" |
| 1078 |
- ctx := fakeContext(c, "FROM scratch\nADD . /foo/", map[string]string{"directoryWeCantStat/bar": "foo"})
|
|
| 1078 |
+ ctx := fakecontext.New(c, "", |
|
| 1079 |
+ fakecontext.WithDockerfile("FROM scratch\nADD . /foo/"),
|
|
| 1080 |
+ fakecontext.WithFiles(map[string]string{"directoryWeCantStat/bar": "foo"}),
|
|
| 1081 |
+ ) |
|
| 1079 | 1082 |
defer ctx.Close() |
| 1080 | 1083 |
// This is used to ensure we detect inaccessible directories early during build in the cli client |
| 1081 | 1084 |
pathToDirectoryWithoutReadAccess := filepath.Join(ctx.Dir, "directoryWeCantStat") |
| ... | ... |
@@ -1111,7 +1119,7 @@ func (s *DockerSuite) TestBuildWithInaccessibleFilesInContext(c *check.C) {
|
| 1111 | 1111 |
} |
| 1112 | 1112 |
{
|
| 1113 | 1113 |
name := "testlinksok" |
| 1114 |
- ctx := fakeContext(c, "FROM scratch\nADD . /foo/", nil) |
|
| 1114 |
+ ctx := fakecontext.New(c, "", fakecontext.WithDockerfile("FROM scratch\nADD . /foo/"))
|
|
| 1115 | 1115 |
defer ctx.Close() |
| 1116 | 1116 |
|
| 1117 | 1117 |
target := "../../../../../../../../../../../../../../../../../../../azA" |
| ... | ... |
@@ -1121,15 +1129,17 @@ func (s *DockerSuite) TestBuildWithInaccessibleFilesInContext(c *check.C) {
|
| 1121 | 1121 |
defer os.Remove(target) |
| 1122 | 1122 |
// This is used to ensure we don't follow links when checking if everything in the context is accessible |
| 1123 | 1123 |
// This test doesn't require that we run commands as an unprivileged user |
| 1124 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 1124 |
+ buildImageSuccessfully(c, name, build.WithExternalBuildContext(ctx)) |
|
| 1125 | 1125 |
} |
| 1126 | 1126 |
{
|
| 1127 | 1127 |
name := "testbuildignoredinaccessible" |
| 1128 |
- ctx := fakeContext(c, "FROM scratch\nADD . /foo/", |
|
| 1129 |
- map[string]string{
|
|
| 1128 |
+ ctx := fakecontext.New(c, "", |
|
| 1129 |
+ fakecontext.WithDockerfile("FROM scratch\nADD . /foo/"),
|
|
| 1130 |
+ fakecontext.WithFiles(map[string]string{
|
|
| 1130 | 1131 |
"directoryWeCantStat/bar": "foo", |
| 1131 | 1132 |
".dockerignore": "directoryWeCantStat", |
| 1132 |
- }) |
|
| 1133 |
+ }), |
|
| 1134 |
+ ) |
|
| 1133 | 1135 |
defer ctx.Close() |
| 1134 | 1136 |
// This is used to ensure we don't try to add inaccessible files when they are ignored by a .dockerignore pattern |
| 1135 | 1137 |
pathToDirectoryWithoutReadAccess := filepath.Join(ctx.Dir, "directoryWeCantStat") |
| ... | ... |
@@ -1157,8 +1167,8 @@ func (s *DockerSuite) TestBuildForceRm(c *check.C) {
|
| 1157 | 1157 |
containerCountBefore := getContainerCount(c) |
| 1158 | 1158 |
name := "testbuildforcerm" |
| 1159 | 1159 |
|
| 1160 |
- buildImage(name, cli.WithFlags("--force-rm"), withBuildContext(c,
|
|
| 1161 |
- withFile("Dockerfile", `FROM `+minimalBaseImage()+`
|
|
| 1160 |
+ buildImage(name, cli.WithFlags("--force-rm"), build.WithBuildContext(c,
|
|
| 1161 |
+ build.WithFile("Dockerfile", `FROM `+minimalBaseImage()+`
|
|
| 1162 | 1162 |
RUN true |
| 1163 | 1163 |
RUN thiswillfail`))).Assert(c, icmd.Expected{
|
| 1164 | 1164 |
ExitCode: 1, |
| ... | ... |
@@ -1335,8 +1345,8 @@ func (s *DockerSuite) TestBuildWindowsAddCopyPathProcessing(c *check.C) {
|
| 1335 | 1335 |
// support backslash such as .\\ being equivalent to ./ and c:\\ being |
| 1336 | 1336 |
// equivalent to c:/. This is not currently (nor ever has been) supported |
| 1337 | 1337 |
// by docker on the Windows platform. |
| 1338 |
- buildImageSuccessfully(c, "testbuildwindowsaddcopypathprocessing", withBuildContext(c, |
|
| 1339 |
- withFile("Dockerfile", `FROM busybox
|
|
| 1338 |
+ buildImageSuccessfully(c, "testbuildwindowsaddcopypathprocessing", build.WithBuildContext(c, |
|
| 1339 |
+ build.WithFile("Dockerfile", `FROM busybox
|
|
| 1340 | 1340 |
# No trailing slash on COPY/ADD |
| 1341 | 1341 |
# Results in dir being changed to a file |
| 1342 | 1342 |
WORKDIR /wc1 |
| ... | ... |
@@ -1355,10 +1365,10 @@ func (s *DockerSuite) TestBuildWindowsAddCopyPathProcessing(c *check.C) {
|
| 1355 | 1355 |
RUN sh -c "[ $(cat c:/wd1/wd1) = 'hellowd1' ]" |
| 1356 | 1356 |
RUN sh -c "[ $(cat c:/wd2/wd2) = 'worldwd2' ]" |
| 1357 | 1357 |
`), |
| 1358 |
- withFile("wc1", "hellowc1"),
|
|
| 1359 |
- withFile("wc2", "worldwc2"),
|
|
| 1360 |
- withFile("wd1", "hellowd1"),
|
|
| 1361 |
- withFile("wd2", "worldwd2"),
|
|
| 1358 |
+ build.WithFile("wc1", "hellowc1"),
|
|
| 1359 |
+ build.WithFile("wc2", "worldwc2"),
|
|
| 1360 |
+ build.WithFile("wd1", "hellowd1"),
|
|
| 1361 |
+ build.WithFile("wd2", "worldwd2"),
|
|
| 1362 | 1362 |
)) |
| 1363 | 1363 |
} |
| 1364 | 1364 |
|
| ... | ... |
@@ -1394,8 +1404,8 @@ func (s *DockerSuite) TestBuildRelativeCopy(c *check.C) {
|
| 1394 | 1394 |
expected = `/test1/test2` |
| 1395 | 1395 |
} |
| 1396 | 1396 |
|
| 1397 |
- buildImageSuccessfully(c, "testbuildrelativecopy", withBuildContext(c, |
|
| 1398 |
- withFile("Dockerfile", `FROM busybox
|
|
| 1397 |
+ buildImageSuccessfully(c, "testbuildrelativecopy", build.WithBuildContext(c, |
|
| 1398 |
+ build.WithFile("Dockerfile", `FROM busybox
|
|
| 1399 | 1399 |
WORKDIR /test1 |
| 1400 | 1400 |
WORKDIR test2 |
| 1401 | 1401 |
RUN sh -c "[ "$PWD" = '`+expected+`' ]" |
| ... | ... |
@@ -1417,7 +1427,7 @@ func (s *DockerSuite) TestBuildRelativeCopy(c *check.C) {
|
| 1417 | 1417 |
COPY foo ../ |
| 1418 | 1418 |
RUN sh -c "[ $(cat /test5/foo) = 'hello' ]" |
| 1419 | 1419 |
`), |
| 1420 |
- withFile("foo", "hello"),
|
|
| 1420 |
+ build.WithFile("foo", "hello"),
|
|
| 1421 | 1421 |
)) |
| 1422 | 1422 |
} |
| 1423 | 1423 |
|
| ... | ... |
@@ -1741,12 +1751,14 @@ func (s *DockerSuite) TestBuildConditionalCache(c *check.C) {
|
| 1741 | 1741 |
dockerfile := ` |
| 1742 | 1742 |
FROM busybox |
| 1743 | 1743 |
ADD foo /tmp/` |
| 1744 |
- ctx := fakeContext(c, dockerfile, map[string]string{
|
|
| 1745 |
- "foo": "hello", |
|
| 1746 |
- }) |
|
| 1744 |
+ ctx := fakecontext.New(c, "", |
|
| 1745 |
+ fakecontext.WithDockerfile(dockerfile), |
|
| 1746 |
+ fakecontext.WithFiles(map[string]string{
|
|
| 1747 |
+ "foo": "hello", |
|
| 1748 |
+ })) |
|
| 1747 | 1749 |
defer ctx.Close() |
| 1748 | 1750 |
|
| 1749 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 1751 |
+ cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) |
|
| 1750 | 1752 |
id1 := getIDByName(c, name) |
| 1751 | 1753 |
|
| 1752 | 1754 |
if err := ctx.Add("foo", "bye"); err != nil {
|
| ... | ... |
@@ -1754,13 +1766,13 @@ func (s *DockerSuite) TestBuildConditionalCache(c *check.C) {
|
| 1754 | 1754 |
} |
| 1755 | 1755 |
|
| 1756 | 1756 |
// Updating a file should invalidate the cache |
| 1757 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 1757 |
+ cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) |
|
| 1758 | 1758 |
id2 := getIDByName(c, name) |
| 1759 | 1759 |
if id2 == id1 {
|
| 1760 | 1760 |
c.Fatal("Should not have used the cache")
|
| 1761 | 1761 |
} |
| 1762 | 1762 |
|
| 1763 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 1763 |
+ cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) |
|
| 1764 | 1764 |
id3 := getIDByName(c, name) |
| 1765 | 1765 |
if id3 != id2 {
|
| 1766 | 1766 |
c.Fatal("Should have used the cache")
|
| ... | ... |
@@ -1775,15 +1787,15 @@ func (s *DockerSuite) TestBuildAddMultipleLocalFileWithAndWithoutCache(c *check. |
| 1775 | 1775 |
MAINTAINER dockerio |
| 1776 | 1776 |
ADD foo Dockerfile /usr/lib/bla/ |
| 1777 | 1777 |
RUN sh -c "[ $(cat /usr/lib/bla/foo) = "hello" ]"` |
| 1778 |
- ctx := fakeContext(c, dockerfile, map[string]string{
|
|
| 1778 |
+ ctx := fakecontext.New(c, "", fakecontext.WithDockerfile(dockerfile), fakecontext.WithFiles(map[string]string{
|
|
| 1779 | 1779 |
"foo": "hello", |
| 1780 |
- }) |
|
| 1780 |
+ })) |
|
| 1781 | 1781 |
defer ctx.Close() |
| 1782 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 1782 |
+ cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) |
|
| 1783 | 1783 |
id1 := getIDByName(c, name) |
| 1784 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 1784 |
+ cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) |
|
| 1785 | 1785 |
id2 := getIDByName(c, name) |
| 1786 |
- buildImageSuccessfully(c, name, build.WithoutCache, withExternalBuildContext(ctx)) |
|
| 1786 |
+ cli.BuildCmd(c, name, build.WithoutCache, build.WithExternalBuildContext(ctx)) |
|
| 1787 | 1787 |
id3 := getIDByName(c, name) |
| 1788 | 1788 |
if id1 != id2 {
|
| 1789 | 1789 |
c.Fatal("The cache should have been used but hasn't.")
|
| ... | ... |
@@ -1800,17 +1812,17 @@ func (s *DockerSuite) TestBuildCopyDirButNotFile(c *check.C) {
|
| 1800 | 1800 |
dockerfile := ` |
| 1801 | 1801 |
FROM ` + minimalBaseImage() + ` |
| 1802 | 1802 |
COPY dir /tmp/` |
| 1803 |
- ctx := fakeContext(c, dockerfile, map[string]string{
|
|
| 1803 |
+ ctx := fakecontext.New(c, "", fakecontext.WithDockerfile(dockerfile), fakecontext.WithFiles(map[string]string{
|
|
| 1804 | 1804 |
"dir/foo": "hello", |
| 1805 |
- }) |
|
| 1805 |
+ })) |
|
| 1806 | 1806 |
defer ctx.Close() |
| 1807 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 1807 |
+ cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) |
|
| 1808 | 1808 |
id1 := getIDByName(c, name) |
| 1809 | 1809 |
// Check that adding file with similar name doesn't mess with cache |
| 1810 | 1810 |
if err := ctx.Add("dir_file", "hello2"); err != nil {
|
| 1811 | 1811 |
c.Fatal(err) |
| 1812 | 1812 |
} |
| 1813 |
- buildImageSuccessfully(c, name2, withExternalBuildContext(ctx)) |
|
| 1813 |
+ cli.BuildCmd(c, name2, build.WithExternalBuildContext(ctx)) |
|
| 1814 | 1814 |
id2 := getIDByName(c, name2) |
| 1815 | 1815 |
if id1 != id2 {
|
| 1816 | 1816 |
c.Fatal("The cache should have been used but wasn't")
|
| ... | ... |
@@ -1826,17 +1838,17 @@ func (s *DockerSuite) TestBuildAddCurrentDirWithCache(c *check.C) {
|
| 1826 | 1826 |
FROM ` + minimalBaseImage() + ` |
| 1827 | 1827 |
MAINTAINER dockerio |
| 1828 | 1828 |
ADD . /usr/lib/bla` |
| 1829 |
- ctx := fakeContext(c, dockerfile, map[string]string{
|
|
| 1829 |
+ ctx := fakecontext.New(c, "", fakecontext.WithDockerfile(dockerfile), fakecontext.WithFiles(map[string]string{
|
|
| 1830 | 1830 |
"foo": "hello", |
| 1831 |
- }) |
|
| 1831 |
+ })) |
|
| 1832 | 1832 |
defer ctx.Close() |
| 1833 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 1833 |
+ buildImageSuccessfully(c, name, build.WithExternalBuildContext(ctx)) |
|
| 1834 | 1834 |
id1 := getIDByName(c, name) |
| 1835 | 1835 |
// Check that adding file invalidate cache of "ADD ." |
| 1836 | 1836 |
if err := ctx.Add("bar", "hello2"); err != nil {
|
| 1837 | 1837 |
c.Fatal(err) |
| 1838 | 1838 |
} |
| 1839 |
- buildImageSuccessfully(c, name2, withExternalBuildContext(ctx)) |
|
| 1839 |
+ buildImageSuccessfully(c, name2, build.WithExternalBuildContext(ctx)) |
|
| 1840 | 1840 |
id2 := getIDByName(c, name2) |
| 1841 | 1841 |
if id1 == id2 {
|
| 1842 | 1842 |
c.Fatal("The cache should have been invalided but hasn't.")
|
| ... | ... |
@@ -1845,7 +1857,7 @@ func (s *DockerSuite) TestBuildAddCurrentDirWithCache(c *check.C) {
|
| 1845 | 1845 |
if err := ctx.Add("foo", "hello1"); err != nil {
|
| 1846 | 1846 |
c.Fatal(err) |
| 1847 | 1847 |
} |
| 1848 |
- buildImageSuccessfully(c, name3, withExternalBuildContext(ctx)) |
|
| 1848 |
+ buildImageSuccessfully(c, name3, build.WithExternalBuildContext(ctx)) |
|
| 1849 | 1849 |
id3 := getIDByName(c, name3) |
| 1850 | 1850 |
if id2 == id3 {
|
| 1851 | 1851 |
c.Fatal("The cache should have been invalided but hasn't.")
|
| ... | ... |
@@ -1856,7 +1868,7 @@ func (s *DockerSuite) TestBuildAddCurrentDirWithCache(c *check.C) {
|
| 1856 | 1856 |
if err := ctx.Add("foo", "hello1"); err != nil {
|
| 1857 | 1857 |
c.Fatal(err) |
| 1858 | 1858 |
} |
| 1859 |
- buildImageSuccessfully(c, name4, withExternalBuildContext(ctx)) |
|
| 1859 |
+ buildImageSuccessfully(c, name4, build.WithExternalBuildContext(ctx)) |
|
| 1860 | 1860 |
id4 := getIDByName(c, name4) |
| 1861 | 1861 |
if id3 != id4 {
|
| 1862 | 1862 |
c.Fatal("The cache should have been used but hasn't.")
|
| ... | ... |
@@ -1870,13 +1882,13 @@ func (s *DockerSuite) TestBuildAddCurrentDirWithoutCache(c *check.C) {
|
| 1870 | 1870 |
FROM ` + minimalBaseImage() + ` |
| 1871 | 1871 |
MAINTAINER dockerio |
| 1872 | 1872 |
ADD . /usr/lib/bla` |
| 1873 |
- ctx := fakeContext(c, dockerfile, map[string]string{
|
|
| 1873 |
+ ctx := fakecontext.New(c, "", fakecontext.WithDockerfile(dockerfile), fakecontext.WithFiles(map[string]string{
|
|
| 1874 | 1874 |
"foo": "hello", |
| 1875 |
- }) |
|
| 1875 |
+ })) |
|
| 1876 | 1876 |
defer ctx.Close() |
| 1877 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 1877 |
+ buildImageSuccessfully(c, name, build.WithExternalBuildContext(ctx)) |
|
| 1878 | 1878 |
id1 := getIDByName(c, name) |
| 1879 |
- buildImageSuccessfully(c, name, build.WithoutCache, withExternalBuildContext(ctx)) |
|
| 1879 |
+ buildImageSuccessfully(c, name, build.WithoutCache, build.WithExternalBuildContext(ctx)) |
|
| 1880 | 1880 |
id2 := getIDByName(c, name) |
| 1881 | 1881 |
if id1 == id2 {
|
| 1882 | 1882 |
c.Fatal("The cache should have been invalided but hasn't.")
|
| ... | ... |
@@ -1885,19 +1897,19 @@ func (s *DockerSuite) TestBuildAddCurrentDirWithoutCache(c *check.C) {
|
| 1885 | 1885 |
|
| 1886 | 1886 |
func (s *DockerSuite) TestBuildAddRemoteFileWithAndWithoutCache(c *check.C) {
|
| 1887 | 1887 |
name := "testbuildaddremotefilewithcache" |
| 1888 |
- server := fakeStorage(c, map[string]string{
|
|
| 1888 |
+ server := fakestorage.New(c, "", fakecontext.WithFiles(map[string]string{
|
|
| 1889 | 1889 |
"baz": "hello", |
| 1890 |
- }) |
|
| 1890 |
+ })) |
|
| 1891 | 1891 |
defer server.Close() |
| 1892 | 1892 |
|
| 1893 | 1893 |
dockerfile := fmt.Sprintf(`FROM `+minimalBaseImage()+` |
| 1894 | 1894 |
MAINTAINER dockerio |
| 1895 | 1895 |
ADD %s/baz /usr/lib/baz/quux`, server.URL()) |
| 1896 |
- buildImageSuccessfully(c, name, build.WithDockerfile(dockerfile)) |
|
| 1896 |
+ cli.BuildCmd(c, name, build.WithDockerfile(dockerfile)) |
|
| 1897 | 1897 |
id1 := getIDByName(c, name) |
| 1898 |
- buildImageSuccessfully(c, name, build.WithDockerfile(dockerfile)) |
|
| 1898 |
+ cli.BuildCmd(c, name, build.WithDockerfile(dockerfile)) |
|
| 1899 | 1899 |
id2 := getIDByName(c, name) |
| 1900 |
- buildImageSuccessfully(c, name, build.WithoutCache, build.WithDockerfile(dockerfile)) |
|
| 1900 |
+ cli.BuildCmd(c, name, build.WithoutCache, build.WithDockerfile(dockerfile)) |
|
| 1901 | 1901 |
id3 := getIDByName(c, name) |
| 1902 | 1902 |
|
| 1903 | 1903 |
if id1 != id2 {
|
| ... | ... |
@@ -1914,17 +1926,17 @@ func (s *DockerSuite) TestBuildAddRemoteFileMTime(c *check.C) {
|
| 1914 | 1914 |
name3 := name + "3" |
| 1915 | 1915 |
|
| 1916 | 1916 |
files := map[string]string{"baz": "hello"}
|
| 1917 |
- server := fakeStorage(c, files) |
|
| 1917 |
+ server := fakestorage.New(c, "", fakecontext.WithFiles(files)) |
|
| 1918 | 1918 |
defer server.Close() |
| 1919 | 1919 |
|
| 1920 |
- ctx := fakeContext(c, fmt.Sprintf(`FROM `+minimalBaseImage()+` |
|
| 1920 |
+ ctx := fakecontext.New(c, "", fakecontext.WithDockerfile(fmt.Sprintf(`FROM `+minimalBaseImage()+` |
|
| 1921 | 1921 |
MAINTAINER dockerio |
| 1922 |
- ADD %s/baz /usr/lib/baz/quux`, server.URL()), nil) |
|
| 1922 |
+ ADD %s/baz /usr/lib/baz/quux`, server.URL()))) |
|
| 1923 | 1923 |
defer ctx.Close() |
| 1924 | 1924 |
|
| 1925 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 1925 |
+ cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) |
|
| 1926 | 1926 |
id1 := getIDByName(c, name) |
| 1927 |
- buildImageSuccessfully(c, name2, withExternalBuildContext(ctx)) |
|
| 1927 |
+ cli.BuildCmd(c, name2, build.WithExternalBuildContext(ctx)) |
|
| 1928 | 1928 |
id2 := getIDByName(c, name2) |
| 1929 | 1929 |
if id1 != id2 {
|
| 1930 | 1930 |
c.Fatal("The cache should have been used but wasn't - #1")
|
| ... | ... |
@@ -1936,14 +1948,14 @@ func (s *DockerSuite) TestBuildAddRemoteFileMTime(c *check.C) {
|
| 1936 | 1936 |
// allow some time for clock to pass as mtime precision is only 1s |
| 1937 | 1937 |
time.Sleep(2 * time.Second) |
| 1938 | 1938 |
|
| 1939 |
- server2 := fakeStorage(c, files) |
|
| 1939 |
+ server2 := fakestorage.New(c, "", fakecontext.WithFiles(files)) |
|
| 1940 | 1940 |
defer server2.Close() |
| 1941 | 1941 |
|
| 1942 |
- ctx2 := fakeContext(c, fmt.Sprintf(`FROM `+minimalBaseImage()+` |
|
| 1942 |
+ ctx2 := fakecontext.New(c, "", fakecontext.WithDockerfile(fmt.Sprintf(`FROM `+minimalBaseImage()+` |
|
| 1943 | 1943 |
MAINTAINER dockerio |
| 1944 |
- ADD %s/baz /usr/lib/baz/quux`, server2.URL()), nil) |
|
| 1944 |
+ ADD %s/baz /usr/lib/baz/quux`, server2.URL()))) |
|
| 1945 | 1945 |
defer ctx2.Close() |
| 1946 |
- buildImageSuccessfully(c, name3, withExternalBuildContext(ctx2)) |
|
| 1946 |
+ cli.BuildCmd(c, name3, build.WithExternalBuildContext(ctx2)) |
|
| 1947 | 1947 |
id3 := getIDByName(c, name3) |
| 1948 | 1948 |
if id1 != id3 {
|
| 1949 | 1949 |
c.Fatal("The cache should have been used but wasn't")
|
| ... | ... |
@@ -1953,24 +1965,24 @@ func (s *DockerSuite) TestBuildAddRemoteFileMTime(c *check.C) {
|
| 1953 | 1953 |
// FIXME(vdemeester) this really seems to test the same thing as before (combined) |
| 1954 | 1954 |
func (s *DockerSuite) TestBuildAddLocalAndRemoteFilesWithAndWithoutCache(c *check.C) {
|
| 1955 | 1955 |
name := "testbuildaddlocalandremotefilewithcache" |
| 1956 |
- server := fakeStorage(c, map[string]string{
|
|
| 1956 |
+ server := fakestorage.New(c, "", fakecontext.WithFiles(map[string]string{
|
|
| 1957 | 1957 |
"baz": "hello", |
| 1958 |
- }) |
|
| 1958 |
+ })) |
|
| 1959 | 1959 |
defer server.Close() |
| 1960 | 1960 |
|
| 1961 |
- ctx := fakeContext(c, fmt.Sprintf(`FROM `+minimalBaseImage()+` |
|
| 1961 |
+ ctx := fakecontext.New(c, "", fakecontext.WithDockerfile(fmt.Sprintf(`FROM `+minimalBaseImage()+` |
|
| 1962 | 1962 |
MAINTAINER dockerio |
| 1963 | 1963 |
ADD foo /usr/lib/bla/bar |
| 1964 |
- ADD %s/baz /usr/lib/baz/quux`, server.URL()), |
|
| 1965 |
- map[string]string{
|
|
| 1964 |
+ ADD %s/baz /usr/lib/baz/quux`, server.URL())), |
|
| 1965 |
+ fakecontext.WithFiles(map[string]string{
|
|
| 1966 | 1966 |
"foo": "hello world", |
| 1967 |
- }) |
|
| 1967 |
+ })) |
|
| 1968 | 1968 |
defer ctx.Close() |
| 1969 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 1969 |
+ buildImageSuccessfully(c, name, build.WithExternalBuildContext(ctx)) |
|
| 1970 | 1970 |
id1 := getIDByName(c, name) |
| 1971 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 1971 |
+ buildImageSuccessfully(c, name, build.WithExternalBuildContext(ctx)) |
|
| 1972 | 1972 |
id2 := getIDByName(c, name) |
| 1973 |
- buildImageSuccessfully(c, name, build.WithoutCache, withExternalBuildContext(ctx)) |
|
| 1973 |
+ buildImageSuccessfully(c, name, build.WithoutCache, build.WithExternalBuildContext(ctx)) |
|
| 1974 | 1974 |
id3 := getIDByName(c, name) |
| 1975 | 1975 |
if id1 != id2 {
|
| 1976 | 1976 |
c.Fatal("The cache should have been used but hasn't.")
|
| ... | ... |
@@ -1981,13 +1993,13 @@ func (s *DockerSuite) TestBuildAddLocalAndRemoteFilesWithAndWithoutCache(c *chec |
| 1981 | 1981 |
} |
| 1982 | 1982 |
|
| 1983 | 1983 |
func testContextTar(c *check.C, compression archive.Compression) {
|
| 1984 |
- ctx := fakeContext(c, |
|
| 1985 |
- `FROM busybox |
|
| 1984 |
+ ctx := fakecontext.New(c, "", |
|
| 1985 |
+ fakecontext.WithDockerfile(`FROM busybox |
|
| 1986 | 1986 |
ADD foo /foo |
| 1987 |
-CMD ["cat", "/foo"]`, |
|
| 1988 |
- map[string]string{
|
|
| 1987 |
+CMD ["cat", "/foo"]`), |
|
| 1988 |
+ fakecontext.WithFiles(map[string]string{
|
|
| 1989 | 1989 |
"foo": "bar", |
| 1990 |
- }, |
|
| 1990 |
+ }), |
|
| 1991 | 1991 |
) |
| 1992 | 1992 |
defer ctx.Close() |
| 1993 | 1993 |
context, err := archive.Tar(ctx.Dir, compression) |
| ... | ... |
@@ -1996,10 +2008,7 @@ CMD ["cat", "/foo"]`, |
| 1996 | 1996 |
} |
| 1997 | 1997 |
name := "contexttar" |
| 1998 | 1998 |
|
| 1999 |
- icmd.RunCmd(icmd.Cmd{
|
|
| 2000 |
- Command: []string{dockerBinary, "build", "-t", name, "-"},
|
|
| 2001 |
- Stdin: context, |
|
| 2002 |
- }).Assert(c, icmd.Success) |
|
| 1999 |
+ cli.BuildCmd(c, name, build.WithStdinContext(context)) |
|
| 2003 | 2000 |
} |
| 2004 | 2001 |
|
| 2005 | 2002 |
func (s *DockerSuite) TestBuildContextTarGzip(c *check.C) {
|
| ... | ... |
@@ -2130,12 +2139,12 @@ func (s *DockerSuite) TestBuildEntrypointRunCleanup(c *check.C) {
|
| 2130 | 2130 |
buildImageSuccessfully(c, name, build.WithDockerfile(`FROM busybox |
| 2131 | 2131 |
RUN echo "hello"`)) |
| 2132 | 2132 |
|
| 2133 |
- buildImageSuccessfully(c, name, withBuildContext(c, |
|
| 2134 |
- withFile("Dockerfile", `FROM busybox
|
|
| 2133 |
+ buildImageSuccessfully(c, name, build.WithBuildContext(c, |
|
| 2134 |
+ build.WithFile("Dockerfile", `FROM busybox
|
|
| 2135 | 2135 |
RUN echo "hello" |
| 2136 | 2136 |
ADD foo /foo |
| 2137 | 2137 |
ENTRYPOINT ["/bin/echo"]`), |
| 2138 |
- withFile("foo", "hello")))
|
|
| 2138 |
+ build.WithFile("foo", "hello")))
|
|
| 2139 | 2139 |
|
| 2140 | 2140 |
res := inspectField(c, name, "Config.Cmd") |
| 2141 | 2141 |
// Cmd must be cleaned up |
| ... | ... |
@@ -2152,10 +2161,10 @@ func (s *DockerSuite) TestBuildAddFileNotFound(c *check.C) {
|
| 2152 | 2152 |
expected = "foo: The system cannot find the file specified" |
| 2153 | 2153 |
} |
| 2154 | 2154 |
|
| 2155 |
- buildImage(name, withBuildContext(c, |
|
| 2156 |
- withFile("Dockerfile", `FROM `+minimalBaseImage()+`
|
|
| 2155 |
+ buildImage(name, build.WithBuildContext(c, |
|
| 2156 |
+ build.WithFile("Dockerfile", `FROM `+minimalBaseImage()+`
|
|
| 2157 | 2157 |
ADD foo /usr/local/bar`), |
| 2158 |
- withFile("bar", "hello"))).Assert(c, icmd.Expected{
|
|
| 2158 |
+ build.WithFile("bar", "hello"))).Assert(c, icmd.Expected{
|
|
| 2159 | 2159 |
ExitCode: 1, |
| 2160 | 2160 |
Err: expected, |
| 2161 | 2161 |
}) |
| ... | ... |
@@ -2206,15 +2215,15 @@ func (s *DockerSuite) TestBuildAddToSymlinkDest(c *check.C) {
|
| 2206 | 2206 |
makeLink = `mklink /D C:\bar C:\foo` |
| 2207 | 2207 |
} |
| 2208 | 2208 |
name := "testbuildaddtosymlinkdest" |
| 2209 |
- buildImageSuccessfully(c, name, withBuildContext(c, |
|
| 2210 |
- withFile("Dockerfile", `
|
|
| 2209 |
+ buildImageSuccessfully(c, name, build.WithBuildContext(c, |
|
| 2210 |
+ build.WithFile("Dockerfile", `
|
|
| 2211 | 2211 |
FROM busybox |
| 2212 | 2212 |
RUN sh -c "mkdir /foo" |
| 2213 | 2213 |
RUN `+makeLink+` |
| 2214 | 2214 |
ADD foo /bar/ |
| 2215 | 2215 |
RUN sh -c "[ -f /bar/foo ]" |
| 2216 | 2216 |
RUN sh -c "[ -f /foo/foo ]"`), |
| 2217 |
- withFile("foo", "hello"),
|
|
| 2217 |
+ build.WithFile("foo", "hello"),
|
|
| 2218 | 2218 |
)) |
| 2219 | 2219 |
} |
| 2220 | 2220 |
|
| ... | ... |
@@ -2253,8 +2262,8 @@ func (s *DockerSuite) TestBuildVerifyIntString(c *check.C) {
|
| 2253 | 2253 |
|
| 2254 | 2254 |
func (s *DockerSuite) TestBuildDockerignore(c *check.C) {
|
| 2255 | 2255 |
name := "testbuilddockerignore" |
| 2256 |
- buildImageSuccessfully(c, name, withBuildContext(c, |
|
| 2257 |
- withFile("Dockerfile", `
|
|
| 2256 |
+ buildImageSuccessfully(c, name, build.WithBuildContext(c, |
|
| 2257 |
+ build.WithFile("Dockerfile", `
|
|
| 2258 | 2258 |
FROM busybox |
| 2259 | 2259 |
ADD . /bla |
| 2260 | 2260 |
RUN sh -c "[[ -f /bla/src/x.go ]]" |
| ... | ... |
@@ -2268,17 +2277,17 @@ func (s *DockerSuite) TestBuildDockerignore(c *check.C) {
|
| 2268 | 2268 |
RUN sh -c "[[ ! -e v.cc ]]" |
| 2269 | 2269 |
RUN sh -c "[[ ! -e src/v.cc ]]" |
| 2270 | 2270 |
RUN sh -c "[[ ! -e src/_vendor/v.cc ]]"`), |
| 2271 |
- withFile("Makefile", "all:"),
|
|
| 2272 |
- withFile(".git/HEAD", "ref: foo"),
|
|
| 2273 |
- withFile("src/x.go", "package main"),
|
|
| 2274 |
- withFile("src/_vendor/v.go", "package main"),
|
|
| 2275 |
- withFile("src/_vendor/v.cc", "package main"),
|
|
| 2276 |
- withFile("src/v.cc", "package main"),
|
|
| 2277 |
- withFile("v.cc", "package main"),
|
|
| 2278 |
- withFile("dir/foo", ""),
|
|
| 2279 |
- withFile(".gitignore", ""),
|
|
| 2280 |
- withFile("README.md", "readme"),
|
|
| 2281 |
- withFile(".dockerignore", `
|
|
| 2271 |
+ build.WithFile("Makefile", "all:"),
|
|
| 2272 |
+ build.WithFile(".git/HEAD", "ref: foo"),
|
|
| 2273 |
+ build.WithFile("src/x.go", "package main"),
|
|
| 2274 |
+ build.WithFile("src/_vendor/v.go", "package main"),
|
|
| 2275 |
+ build.WithFile("src/_vendor/v.cc", "package main"),
|
|
| 2276 |
+ build.WithFile("src/v.cc", "package main"),
|
|
| 2277 |
+ build.WithFile("v.cc", "package main"),
|
|
| 2278 |
+ build.WithFile("dir/foo", ""),
|
|
| 2279 |
+ build.WithFile(".gitignore", ""),
|
|
| 2280 |
+ build.WithFile("README.md", "readme"),
|
|
| 2281 |
+ build.WithFile(".dockerignore", `
|
|
| 2282 | 2282 |
.git |
| 2283 | 2283 |
pkg |
| 2284 | 2284 |
.gitignore |
| ... | ... |
@@ -2291,22 +2300,22 @@ dir`), |
| 2291 | 2291 |
|
| 2292 | 2292 |
func (s *DockerSuite) TestBuildDockerignoreCleanPaths(c *check.C) {
|
| 2293 | 2293 |
name := "testbuilddockerignorecleanpaths" |
| 2294 |
- buildImageSuccessfully(c, name, withBuildContext(c, |
|
| 2295 |
- withFile("Dockerfile", `
|
|
| 2294 |
+ buildImageSuccessfully(c, name, build.WithBuildContext(c, |
|
| 2295 |
+ build.WithFile("Dockerfile", `
|
|
| 2296 | 2296 |
FROM busybox |
| 2297 | 2297 |
ADD . /tmp/ |
| 2298 | 2298 |
RUN sh -c "(! ls /tmp/foo) && (! ls /tmp/foo2) && (! ls /tmp/dir1/foo)"`), |
| 2299 |
- withFile("foo", "foo"),
|
|
| 2300 |
- withFile("foo2", "foo2"),
|
|
| 2301 |
- withFile("dir1/foo", "foo in dir1"),
|
|
| 2302 |
- withFile(".dockerignore", "./foo\ndir1//foo\n./dir1/../foo2"),
|
|
| 2299 |
+ build.WithFile("foo", "foo"),
|
|
| 2300 |
+ build.WithFile("foo2", "foo2"),
|
|
| 2301 |
+ build.WithFile("dir1/foo", "foo in dir1"),
|
|
| 2302 |
+ build.WithFile(".dockerignore", "./foo\ndir1//foo\n./dir1/../foo2"),
|
|
| 2303 | 2303 |
)) |
| 2304 | 2304 |
} |
| 2305 | 2305 |
|
| 2306 | 2306 |
func (s *DockerSuite) TestBuildDockerignoreExceptions(c *check.C) {
|
| 2307 | 2307 |
name := "testbuilddockerignoreexceptions" |
| 2308 |
- buildImageSuccessfully(c, name, withBuildContext(c, |
|
| 2309 |
- withFile("Dockerfile", `
|
|
| 2308 |
+ buildImageSuccessfully(c, name, build.WithBuildContext(c, |
|
| 2309 |
+ build.WithFile("Dockerfile", `
|
|
| 2310 | 2310 |
FROM busybox |
| 2311 | 2311 |
ADD . /bla |
| 2312 | 2312 |
RUN sh -c "[[ -f /bla/src/x.go ]]" |
| ... | ... |
@@ -2321,20 +2330,20 @@ func (s *DockerSuite) TestBuildDockerignoreExceptions(c *check.C) {
|
| 2321 | 2321 |
RUN sh -c "[[ ! -e /bla/foo ]]" |
| 2322 | 2322 |
RUN sh -c "[[ ! -e /bla/.git ]]" |
| 2323 | 2323 |
RUN sh -c "[[ -e /bla/dir/a.cc ]]"`), |
| 2324 |
- withFile("Makefile", "all:"),
|
|
| 2325 |
- withFile(".git/HEAD", "ref: foo"),
|
|
| 2326 |
- withFile("src/x.go", "package main"),
|
|
| 2327 |
- withFile("src/_vendor/v.go", "package main"),
|
|
| 2328 |
- withFile("dir/foo", ""),
|
|
| 2329 |
- withFile("dir/foo1", ""),
|
|
| 2330 |
- withFile("dir/dir/f1", ""),
|
|
| 2331 |
- withFile("dir/dir/foo", ""),
|
|
| 2332 |
- withFile("dir/e", ""),
|
|
| 2333 |
- withFile("dir/e-dir/foo", ""),
|
|
| 2334 |
- withFile(".gitignore", ""),
|
|
| 2335 |
- withFile("README.md", "readme"),
|
|
| 2336 |
- withFile("dir/a.cc", "hello"),
|
|
| 2337 |
- withFile(".dockerignore", `
|
|
| 2324 |
+ build.WithFile("Makefile", "all:"),
|
|
| 2325 |
+ build.WithFile(".git/HEAD", "ref: foo"),
|
|
| 2326 |
+ build.WithFile("src/x.go", "package main"),
|
|
| 2327 |
+ build.WithFile("src/_vendor/v.go", "package main"),
|
|
| 2328 |
+ build.WithFile("dir/foo", ""),
|
|
| 2329 |
+ build.WithFile("dir/foo1", ""),
|
|
| 2330 |
+ build.WithFile("dir/dir/f1", ""),
|
|
| 2331 |
+ build.WithFile("dir/dir/foo", ""),
|
|
| 2332 |
+ build.WithFile("dir/e", ""),
|
|
| 2333 |
+ build.WithFile("dir/e-dir/foo", ""),
|
|
| 2334 |
+ build.WithFile(".gitignore", ""),
|
|
| 2335 |
+ build.WithFile("README.md", "readme"),
|
|
| 2336 |
+ build.WithFile("dir/a.cc", "hello"),
|
|
| 2337 |
+ build.WithFile(".dockerignore", `
|
|
| 2338 | 2338 |
.git |
| 2339 | 2339 |
pkg |
| 2340 | 2340 |
.gitignore |
| ... | ... |
@@ -2355,13 +2364,13 @@ func (s *DockerSuite) TestBuildDockerignoringDockerfile(c *check.C) {
|
| 2355 | 2355 |
ADD . /tmp/ |
| 2356 | 2356 |
RUN sh -c "! ls /tmp/Dockerfile" |
| 2357 | 2357 |
RUN ls /tmp/.dockerignore` |
| 2358 |
- buildImageSuccessfully(c, name, withBuildContext(c, |
|
| 2359 |
- withFile("Dockerfile", dockerfile),
|
|
| 2360 |
- withFile(".dockerignore", "Dockerfile\n"),
|
|
| 2358 |
+ buildImageSuccessfully(c, name, build.WithBuildContext(c, |
|
| 2359 |
+ build.WithFile("Dockerfile", dockerfile),
|
|
| 2360 |
+ build.WithFile(".dockerignore", "Dockerfile\n"),
|
|
| 2361 | 2361 |
)) |
| 2362 |
- buildImageSuccessfully(c, name, withBuildContext(c, |
|
| 2363 |
- withFile("Dockerfile", dockerfile),
|
|
| 2364 |
- withFile(".dockerignore", "./Dockerfile\n"),
|
|
| 2362 |
+ buildImageSuccessfully(c, name, build.WithBuildContext(c, |
|
| 2363 |
+ build.WithFile("Dockerfile", dockerfile),
|
|
| 2364 |
+ build.WithFile(".dockerignore", "./Dockerfile\n"),
|
|
| 2365 | 2365 |
)) |
| 2366 | 2366 |
} |
| 2367 | 2367 |
|
| ... | ... |
@@ -2373,15 +2382,15 @@ func (s *DockerSuite) TestBuildDockerignoringRenamedDockerfile(c *check.C) {
|
| 2373 | 2373 |
RUN ls /tmp/Dockerfile |
| 2374 | 2374 |
RUN sh -c "! ls /tmp/MyDockerfile" |
| 2375 | 2375 |
RUN ls /tmp/.dockerignore` |
| 2376 |
- buildImageSuccessfully(c, name, cli.WithFlags("-f", "MyDockerfile"), withBuildContext(c,
|
|
| 2377 |
- withFile("Dockerfile", "Should not use me"),
|
|
| 2378 |
- withFile("MyDockerfile", dockerfile),
|
|
| 2379 |
- withFile(".dockerignore", "MyDockerfile\n"),
|
|
| 2376 |
+ buildImageSuccessfully(c, name, cli.WithFlags("-f", "MyDockerfile"), build.WithBuildContext(c,
|
|
| 2377 |
+ build.WithFile("Dockerfile", "Should not use me"),
|
|
| 2378 |
+ build.WithFile("MyDockerfile", dockerfile),
|
|
| 2379 |
+ build.WithFile(".dockerignore", "MyDockerfile\n"),
|
|
| 2380 | 2380 |
)) |
| 2381 |
- buildImageSuccessfully(c, name, cli.WithFlags("-f", "MyDockerfile"), withBuildContext(c,
|
|
| 2382 |
- withFile("Dockerfile", "Should not use me"),
|
|
| 2383 |
- withFile("MyDockerfile", dockerfile),
|
|
| 2384 |
- withFile(".dockerignore", "./MyDockerfile\n"),
|
|
| 2381 |
+ buildImageSuccessfully(c, name, cli.WithFlags("-f", "MyDockerfile"), build.WithBuildContext(c,
|
|
| 2382 |
+ build.WithFile("Dockerfile", "Should not use me"),
|
|
| 2383 |
+ build.WithFile("MyDockerfile", dockerfile),
|
|
| 2384 |
+ build.WithFile(".dockerignore", "./MyDockerfile\n"),
|
|
| 2385 | 2385 |
)) |
| 2386 | 2386 |
} |
| 2387 | 2387 |
|
| ... | ... |
@@ -2392,9 +2401,9 @@ func (s *DockerSuite) TestBuildDockerignoringDockerignore(c *check.C) {
|
| 2392 | 2392 |
ADD . /tmp/ |
| 2393 | 2393 |
RUN sh -c "! ls /tmp/.dockerignore" |
| 2394 | 2394 |
RUN ls /tmp/Dockerfile` |
| 2395 |
- buildImageSuccessfully(c, name, withBuildContext(c, |
|
| 2396 |
- withFile("Dockerfile", dockerfile),
|
|
| 2397 |
- withFile(".dockerignore", ".dockerignore\n"),
|
|
| 2395 |
+ buildImageSuccessfully(c, name, build.WithBuildContext(c, |
|
| 2396 |
+ build.WithFile("Dockerfile", dockerfile),
|
|
| 2397 |
+ build.WithFile(".dockerignore", ".dockerignore\n"),
|
|
| 2398 | 2398 |
)) |
| 2399 | 2399 |
} |
| 2400 | 2400 |
|
| ... | ... |
@@ -2403,16 +2412,17 @@ func (s *DockerSuite) TestBuildDockerignoreTouchDockerfile(c *check.C) {
|
| 2403 | 2403 |
dockerfile := ` |
| 2404 | 2404 |
FROM busybox |
| 2405 | 2405 |
ADD . /tmp/` |
| 2406 |
- ctx := fakeContext(c, dockerfile, map[string]string{
|
|
| 2407 |
- "Dockerfile": dockerfile, |
|
| 2408 |
- ".dockerignore": "Dockerfile\n", |
|
| 2409 |
- }) |
|
| 2406 |
+ ctx := fakecontext.New(c, "", |
|
| 2407 |
+ fakecontext.WithDockerfile(dockerfile), |
|
| 2408 |
+ fakecontext.WithFiles(map[string]string{
|
|
| 2409 |
+ ".dockerignore": "Dockerfile\n", |
|
| 2410 |
+ })) |
|
| 2410 | 2411 |
defer ctx.Close() |
| 2411 | 2412 |
|
| 2412 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 2413 |
+ cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) |
|
| 2413 | 2414 |
id1 := getIDByName(c, name) |
| 2414 | 2415 |
|
| 2415 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 2416 |
+ cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) |
|
| 2416 | 2417 |
id2 := getIDByName(c, name) |
| 2417 | 2418 |
if id1 != id2 {
|
| 2418 | 2419 |
c.Fatalf("Didn't use the cache - 1")
|
| ... | ... |
@@ -2422,7 +2432,7 @@ func (s *DockerSuite) TestBuildDockerignoreTouchDockerfile(c *check.C) {
|
| 2422 | 2422 |
if err := ctx.Add("Dockerfile", dockerfile+"\n# hi"); err != nil {
|
| 2423 | 2423 |
c.Fatalf("Didn't add Dockerfile: %s", err)
|
| 2424 | 2424 |
} |
| 2425 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 2425 |
+ cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) |
|
| 2426 | 2426 |
id2 = getIDByName(c, name) |
| 2427 | 2427 |
if id1 != id2 {
|
| 2428 | 2428 |
c.Fatalf("Didn't use the cache - 2")
|
| ... | ... |
@@ -2432,7 +2442,7 @@ func (s *DockerSuite) TestBuildDockerignoreTouchDockerfile(c *check.C) {
|
| 2432 | 2432 |
if err := ctx.Add("Dockerfile", dockerfile+"\n# hi"); err != nil {
|
| 2433 | 2433 |
c.Fatalf("Didn't add Dockerfile: %s", err)
|
| 2434 | 2434 |
} |
| 2435 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 2435 |
+ cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) |
|
| 2436 | 2436 |
id2 = getIDByName(c, name) |
| 2437 | 2437 |
if id1 != id2 {
|
| 2438 | 2438 |
c.Fatalf("Didn't use the cache - 3")
|
| ... | ... |
@@ -2448,11 +2458,11 @@ func (s *DockerSuite) TestBuildDockerignoringWholeDir(c *check.C) {
|
| 2448 | 2448 |
RUN sh -c "[[ ! -e /.gitignore ]]" |
| 2449 | 2449 |
RUN sh -c "[[ ! -e /Makefile ]]"` |
| 2450 | 2450 |
|
| 2451 |
- buildImageSuccessfully(c, name, withBuildContext(c, |
|
| 2452 |
- withFile("Dockerfile", dockerfile),
|
|
| 2453 |
- withFile(".dockerignore", "*\n"),
|
|
| 2454 |
- withFile("Makefile", "all:"),
|
|
| 2455 |
- withFile(".gitignore", ""),
|
|
| 2451 |
+ buildImageSuccessfully(c, name, build.WithBuildContext(c, |
|
| 2452 |
+ build.WithFile("Dockerfile", dockerfile),
|
|
| 2453 |
+ build.WithFile(".dockerignore", "*\n"),
|
|
| 2454 |
+ build.WithFile("Makefile", "all:"),
|
|
| 2455 |
+ build.WithFile(".gitignore", ""),
|
|
| 2456 | 2456 |
)) |
| 2457 | 2457 |
} |
| 2458 | 2458 |
|
| ... | ... |
@@ -2465,25 +2475,25 @@ func (s *DockerSuite) TestBuildDockerignoringOnlyDotfiles(c *check.C) {
|
| 2465 | 2465 |
RUN sh -c "[[ ! -e /.gitignore ]]" |
| 2466 | 2466 |
RUN sh -c "[[ -f /Makefile ]]"` |
| 2467 | 2467 |
|
| 2468 |
- buildImageSuccessfully(c, name, withBuildContext(c, |
|
| 2469 |
- withFile("Dockerfile", dockerfile),
|
|
| 2470 |
- withFile(".dockerignore", ".*"),
|
|
| 2471 |
- withFile("Makefile", "all:"),
|
|
| 2472 |
- withFile(".gitignore", ""),
|
|
| 2468 |
+ buildImageSuccessfully(c, name, build.WithBuildContext(c, |
|
| 2469 |
+ build.WithFile("Dockerfile", dockerfile),
|
|
| 2470 |
+ build.WithFile(".dockerignore", ".*"),
|
|
| 2471 |
+ build.WithFile("Makefile", "all:"),
|
|
| 2472 |
+ build.WithFile(".gitignore", ""),
|
|
| 2473 | 2473 |
)) |
| 2474 | 2474 |
} |
| 2475 | 2475 |
|
| 2476 | 2476 |
func (s *DockerSuite) TestBuildDockerignoringBadExclusion(c *check.C) {
|
| 2477 | 2477 |
name := "testbuilddockerignorebadexclusion" |
| 2478 |
- buildImage(name, withBuildContext(c, |
|
| 2479 |
- withFile("Dockerfile", `
|
|
| 2478 |
+ buildImage(name, build.WithBuildContext(c, |
|
| 2479 |
+ build.WithFile("Dockerfile", `
|
|
| 2480 | 2480 |
FROM busybox |
| 2481 | 2481 |
COPY . / |
| 2482 | 2482 |
RUN sh -c "[[ ! -e /.gitignore ]]" |
| 2483 | 2483 |
RUN sh -c "[[ -f /Makefile ]]"`), |
| 2484 |
- withFile("Makefile", "all:"),
|
|
| 2485 |
- withFile(".gitignore", ""),
|
|
| 2486 |
- withFile(".dockerignore", "!\n"),
|
|
| 2484 |
+ build.WithFile("Makefile", "all:"),
|
|
| 2485 |
+ build.WithFile(".gitignore", ""),
|
|
| 2486 |
+ build.WithFile(".dockerignore", "!\n"),
|
|
| 2487 | 2487 |
)).Assert(c, icmd.Expected{
|
| 2488 | 2488 |
ExitCode: 1, |
| 2489 | 2489 |
Err: "Error checking context: 'illegal exclusion pattern: \"!\"", |
| ... | ... |
@@ -2501,11 +2511,11 @@ func (s *DockerSuite) TestBuildDockerignoringWildTopDir(c *check.C) {
|
| 2501 | 2501 |
|
| 2502 | 2502 |
// All of these should result in ignoring all files |
| 2503 | 2503 |
for _, variant := range []string{"**", "**/", "**/**", "*"} {
|
| 2504 |
- buildImageSuccessfully(c, "noname", withBuildContext(c, |
|
| 2505 |
- withFile("Dockerfile", dockerfile),
|
|
| 2506 |
- withFile("file1", ""),
|
|
| 2507 |
- withFile("dir/file1", ""),
|
|
| 2508 |
- withFile(".dockerignore", variant),
|
|
| 2504 |
+ buildImageSuccessfully(c, "noname", build.WithBuildContext(c, |
|
| 2505 |
+ build.WithFile("Dockerfile", dockerfile),
|
|
| 2506 |
+ build.WithFile("file1", ""),
|
|
| 2507 |
+ build.WithFile("dir/file1", ""),
|
|
| 2508 |
+ build.WithFile(".dockerignore", variant),
|
|
| 2509 | 2509 |
)) |
| 2510 | 2510 |
|
| 2511 | 2511 |
dockerCmd(c, "rmi", "noname") |
| ... | ... |
@@ -2553,25 +2563,25 @@ dir1/dir3/** |
| 2553 | 2553 |
**/dir5/file. |
| 2554 | 2554 |
` |
| 2555 | 2555 |
|
| 2556 |
- buildImageSuccessfully(c, "noname", withBuildContext(c, |
|
| 2557 |
- withFile("Dockerfile", dockerfile),
|
|
| 2558 |
- withFile(".dockerignore", dockerignore),
|
|
| 2559 |
- withFile("dir1/file0", ""),
|
|
| 2560 |
- withFile("dir1/dir2/file0", ""),
|
|
| 2561 |
- withFile("file1", ""),
|
|
| 2562 |
- withFile("dir1/file1", ""),
|
|
| 2563 |
- withFile("dir1/dir2/file1", ""),
|
|
| 2564 |
- withFile("dir1/file2", ""),
|
|
| 2565 |
- withFile("dir1/dir2/file2", ""), // remains
|
|
| 2566 |
- withFile("dir1/dir2/file4", ""),
|
|
| 2567 |
- withFile("dir1/dir2/file5", ""),
|
|
| 2568 |
- withFile("dir1/dir2/file6", ""),
|
|
| 2569 |
- withFile("dir1/dir3/file7", ""),
|
|
| 2570 |
- withFile("dir1/dir3/file8", ""),
|
|
| 2571 |
- withFile("dir1/dir4/file9", ""),
|
|
| 2572 |
- withFile("dir1/dir5/fileAA", ""),
|
|
| 2573 |
- withFile("dir1/dir5/fileAB", ""),
|
|
| 2574 |
- withFile("dir1/dir5/fileB", ""),
|
|
| 2556 |
+ buildImageSuccessfully(c, "noname", build.WithBuildContext(c, |
|
| 2557 |
+ build.WithFile("Dockerfile", dockerfile),
|
|
| 2558 |
+ build.WithFile(".dockerignore", dockerignore),
|
|
| 2559 |
+ build.WithFile("dir1/file0", ""),
|
|
| 2560 |
+ build.WithFile("dir1/dir2/file0", ""),
|
|
| 2561 |
+ build.WithFile("file1", ""),
|
|
| 2562 |
+ build.WithFile("dir1/file1", ""),
|
|
| 2563 |
+ build.WithFile("dir1/dir2/file1", ""),
|
|
| 2564 |
+ build.WithFile("dir1/file2", ""),
|
|
| 2565 |
+ build.WithFile("dir1/dir2/file2", ""), // remains
|
|
| 2566 |
+ build.WithFile("dir1/dir2/file4", ""),
|
|
| 2567 |
+ build.WithFile("dir1/dir2/file5", ""),
|
|
| 2568 |
+ build.WithFile("dir1/dir2/file6", ""),
|
|
| 2569 |
+ build.WithFile("dir1/dir3/file7", ""),
|
|
| 2570 |
+ build.WithFile("dir1/dir3/file8", ""),
|
|
| 2571 |
+ build.WithFile("dir1/dir4/file9", ""),
|
|
| 2572 |
+ build.WithFile("dir1/dir5/fileAA", ""),
|
|
| 2573 |
+ build.WithFile("dir1/dir5/fileAB", ""),
|
|
| 2574 |
+ build.WithFile("dir1/dir5/fileB", ""),
|
|
| 2575 | 2575 |
)) |
| 2576 | 2576 |
} |
| 2577 | 2577 |
|
| ... | ... |
@@ -2691,9 +2701,9 @@ ENV abc=def |
| 2691 | 2691 |
ENV ghi=$abc |
| 2692 | 2692 |
RUN [ "$ghi" = "def" ] |
| 2693 | 2693 |
` |
| 2694 |
- buildImageSuccessfully(c, name, withBuildContext(c, |
|
| 2695 |
- withFile("Dockerfile", dockerfile),
|
|
| 2696 |
- withFile("hello/docker/world", "hello"),
|
|
| 2694 |
+ buildImageSuccessfully(c, name, build.WithBuildContext(c, |
|
| 2695 |
+ build.WithFile("Dockerfile", dockerfile),
|
|
| 2696 |
+ build.WithFile("hello/docker/world", "hello"),
|
|
| 2697 | 2697 |
)) |
| 2698 | 2698 |
} |
| 2699 | 2699 |
|
| ... | ... |
@@ -2761,9 +2771,9 @@ ENV eee4 'foo' |
| 2761 | 2761 |
RUN [ "$eee1,$eee2,$eee3,$eee4" = 'foo,foo,foo,foo' ] |
| 2762 | 2762 |
|
| 2763 | 2763 |
` |
| 2764 |
- buildImageSuccessfully(c, name, withBuildContext(c, |
|
| 2765 |
- withFile("Dockerfile", dockerfile),
|
|
| 2766 |
- withFile("hello/docker/world", "hello"),
|
|
| 2764 |
+ buildImageSuccessfully(c, name, build.WithBuildContext(c, |
|
| 2765 |
+ build.WithFile("Dockerfile", dockerfile),
|
|
| 2766 |
+ build.WithFile("hello/docker/world", "hello"),
|
|
| 2767 | 2767 |
)) |
| 2768 | 2768 |
} |
| 2769 | 2769 |
|
| ... | ... |
@@ -2777,9 +2787,9 @@ RUN ["chmod","+x","/test"] |
| 2777 | 2777 |
RUN ["/test"] |
| 2778 | 2778 |
RUN [ "$(cat /testfile)" = 'test!' ]` |
| 2779 | 2779 |
|
| 2780 |
- buildImageSuccessfully(c, name, withBuildContext(c, |
|
| 2781 |
- withFile("Dockerfile", dockerfile),
|
|
| 2782 |
- withFile("test", "#!/bin/sh\necho 'test!' > /testfile"),
|
|
| 2780 |
+ buildImageSuccessfully(c, name, build.WithBuildContext(c, |
|
| 2781 |
+ build.WithFile("Dockerfile", dockerfile),
|
|
| 2782 |
+ build.WithFile("test", "#!/bin/sh\necho 'test!' > /testfile"),
|
|
| 2783 | 2783 |
)) |
| 2784 | 2784 |
} |
| 2785 | 2785 |
|
| ... | ... |
@@ -2788,7 +2798,7 @@ func (s *DockerSuite) TestBuildAddTar(c *check.C) {
|
| 2788 | 2788 |
testRequires(c, NotUserNamespace) |
| 2789 | 2789 |
name := "testbuildaddtar" |
| 2790 | 2790 |
|
| 2791 |
- ctx := func() *FakeContext {
|
|
| 2791 |
+ ctx := func() *fakecontext.Fake {
|
|
| 2792 | 2792 |
dockerfile := ` |
| 2793 | 2793 |
FROM busybox |
| 2794 | 2794 |
ADD test.tar / |
| ... | ... |
@@ -2830,17 +2840,17 @@ RUN cat /existing-directory-trailing-slash/test/foo | grep Hi` |
| 2830 | 2830 |
if err := ioutil.WriteFile(filepath.Join(tmpDir, "Dockerfile"), []byte(dockerfile), 0644); err != nil {
|
| 2831 | 2831 |
c.Fatalf("failed to open destination dockerfile: %v", err)
|
| 2832 | 2832 |
} |
| 2833 |
- return fakeContextFromDir(tmpDir) |
|
| 2833 |
+ return fakecontext.New(c, tmpDir) |
|
| 2834 | 2834 |
}() |
| 2835 | 2835 |
defer ctx.Close() |
| 2836 | 2836 |
|
| 2837 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 2837 |
+ buildImageSuccessfully(c, name, build.WithExternalBuildContext(ctx)) |
|
| 2838 | 2838 |
} |
| 2839 | 2839 |
|
| 2840 | 2840 |
func (s *DockerSuite) TestBuildAddBrokenTar(c *check.C) {
|
| 2841 | 2841 |
name := "testbuildaddbrokentar" |
| 2842 | 2842 |
|
| 2843 |
- ctx := func() *FakeContext {
|
|
| 2843 |
+ ctx := func() *fakecontext.Fake {
|
|
| 2844 | 2844 |
dockerfile := ` |
| 2845 | 2845 |
FROM busybox |
| 2846 | 2846 |
ADD test.tar /` |
| ... | ... |
@@ -2879,11 +2889,11 @@ ADD test.tar /` |
| 2879 | 2879 |
if err := ioutil.WriteFile(filepath.Join(tmpDir, "Dockerfile"), []byte(dockerfile), 0644); err != nil {
|
| 2880 | 2880 |
c.Fatalf("failed to open destination dockerfile: %v", err)
|
| 2881 | 2881 |
} |
| 2882 |
- return fakeContextFromDir(tmpDir) |
|
| 2882 |
+ return fakecontext.New(c, tmpDir) |
|
| 2883 | 2883 |
}() |
| 2884 | 2884 |
defer ctx.Close() |
| 2885 | 2885 |
|
| 2886 |
- buildImage(name, withExternalBuildContext(ctx)).Assert(c, icmd.Expected{
|
|
| 2886 |
+ buildImage(name, build.WithExternalBuildContext(ctx)).Assert(c, icmd.Expected{
|
|
| 2887 | 2887 |
ExitCode: 1, |
| 2888 | 2888 |
}) |
| 2889 | 2889 |
} |
| ... | ... |
@@ -2892,12 +2902,12 @@ func (s *DockerSuite) TestBuildAddNonTar(c *check.C) {
|
| 2892 | 2892 |
name := "testbuildaddnontar" |
| 2893 | 2893 |
|
| 2894 | 2894 |
// Should not try to extract test.tar |
| 2895 |
- buildImageSuccessfully(c, name, withBuildContext(c, |
|
| 2896 |
- withFile("Dockerfile", `
|
|
| 2895 |
+ buildImageSuccessfully(c, name, build.WithBuildContext(c, |
|
| 2896 |
+ build.WithFile("Dockerfile", `
|
|
| 2897 | 2897 |
FROM busybox |
| 2898 | 2898 |
ADD test.tar / |
| 2899 | 2899 |
RUN test -f /test.tar`), |
| 2900 |
- withFile("test.tar", "not_a_tar_file"),
|
|
| 2900 |
+ build.WithFile("test.tar", "not_a_tar_file"),
|
|
| 2901 | 2901 |
)) |
| 2902 | 2902 |
} |
| 2903 | 2903 |
|
| ... | ... |
@@ -2907,7 +2917,7 @@ func (s *DockerSuite) TestBuildAddTarXz(c *check.C) {
|
| 2907 | 2907 |
testRequires(c, DaemonIsLinux) |
| 2908 | 2908 |
name := "testbuildaddtarxz" |
| 2909 | 2909 |
|
| 2910 |
- ctx := func() *FakeContext {
|
|
| 2910 |
+ ctx := func() *fakecontext.Fake {
|
|
| 2911 | 2911 |
dockerfile := ` |
| 2912 | 2912 |
FROM busybox |
| 2913 | 2913 |
ADD test.tar.xz / |
| ... | ... |
@@ -2942,19 +2952,19 @@ func (s *DockerSuite) TestBuildAddTarXz(c *check.C) {
|
| 2942 | 2942 |
if err := ioutil.WriteFile(filepath.Join(tmpDir, "Dockerfile"), []byte(dockerfile), 0644); err != nil {
|
| 2943 | 2943 |
c.Fatalf("failed to open destination dockerfile: %v", err)
|
| 2944 | 2944 |
} |
| 2945 |
- return fakeContextFromDir(tmpDir) |
|
| 2945 |
+ return fakecontext.New(c, tmpDir) |
|
| 2946 | 2946 |
}() |
| 2947 | 2947 |
|
| 2948 | 2948 |
defer ctx.Close() |
| 2949 | 2949 |
|
| 2950 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 2950 |
+ buildImageSuccessfully(c, name, build.WithExternalBuildContext(ctx)) |
|
| 2951 | 2951 |
} |
| 2952 | 2952 |
|
| 2953 | 2953 |
func (s *DockerSuite) TestBuildAddTarXzGz(c *check.C) {
|
| 2954 | 2954 |
testRequires(c, DaemonIsLinux) |
| 2955 | 2955 |
name := "testbuildaddtarxzgz" |
| 2956 | 2956 |
|
| 2957 |
- ctx := func() *FakeContext {
|
|
| 2957 |
+ ctx := func() *fakecontext.Fake {
|
|
| 2958 | 2958 |
dockerfile := ` |
| 2959 | 2959 |
FROM busybox |
| 2960 | 2960 |
ADD test.tar.xz.gz / |
| ... | ... |
@@ -2994,12 +3004,12 @@ func (s *DockerSuite) TestBuildAddTarXzGz(c *check.C) {
|
| 2994 | 2994 |
if err := ioutil.WriteFile(filepath.Join(tmpDir, "Dockerfile"), []byte(dockerfile), 0644); err != nil {
|
| 2995 | 2995 |
c.Fatalf("failed to open destination dockerfile: %v", err)
|
| 2996 | 2996 |
} |
| 2997 |
- return fakeContextFromDir(tmpDir) |
|
| 2997 |
+ return fakecontext.New(c, tmpDir) |
|
| 2998 | 2998 |
}() |
| 2999 | 2999 |
|
| 3000 | 3000 |
defer ctx.Close() |
| 3001 | 3001 |
|
| 3002 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 3002 |
+ buildImageSuccessfully(c, name, build.WithExternalBuildContext(ctx)) |
|
| 3003 | 3003 |
} |
| 3004 | 3004 |
|
| 3005 | 3005 |
func (s *DockerSuite) TestBuildFromGit(c *check.C) {
|
| ... | ... |
@@ -3075,12 +3085,12 @@ func (s *DockerSuite) TestBuildFromRemoteTarball(c *check.C) {
|
| 3075 | 3075 |
c.Fatalf("failed to close tar archive: %v", err)
|
| 3076 | 3076 |
} |
| 3077 | 3077 |
|
| 3078 |
- server := fakeBinaryStorage(c, map[string]*bytes.Buffer{
|
|
| 3078 |
+ server := fakestorage.New(c, "", fakecontext.WithBinaryFiles(map[string]*bytes.Buffer{
|
|
| 3079 | 3079 |
"testT.tar": buffer, |
| 3080 |
- }) |
|
| 3080 |
+ })) |
|
| 3081 | 3081 |
defer server.Close() |
| 3082 | 3082 |
|
| 3083 |
- buildImageSuccessfully(c, name, build.WithContextPath(server.URL()+"/testT.tar")) |
|
| 3083 |
+ cli.BuildCmd(c, name, build.WithContextPath(server.URL()+"/testT.tar")) |
|
| 3084 | 3084 |
|
| 3085 | 3085 |
res := inspectField(c, name, "Author") |
| 3086 | 3086 |
if res != "docker" {
|
| ... | ... |
@@ -3398,9 +3408,9 @@ func (s *DockerSuite) TestBuildNotVerboseSuccess(c *check.C) {
|
| 3398 | 3398 |
{
|
| 3399 | 3399 |
Name: "quiet_build_ctx_success", |
| 3400 | 3400 |
BuildFunc: func(name string) *icmd.Result {
|
| 3401 |
- return buildImage(name, buildFlags, withBuildContext(c, |
|
| 3402 |
- withFile("Dockerfile", "FROM busybox"),
|
|
| 3403 |
- withFile("quiet_build_success_fctx", "test"),
|
|
| 3401 |
+ return buildImage(name, buildFlags, build.WithBuildContext(c, |
|
| 3402 |
+ build.WithFile("Dockerfile", "FROM busybox"),
|
|
| 3403 |
+ build.WithFile("quiet_build_success_fctx", "test"),
|
|
| 3404 | 3404 |
)) |
| 3405 | 3405 |
}, |
| 3406 | 3406 |
}, |
| ... | ... |
@@ -3518,21 +3528,23 @@ func (s *DockerSuite) TestBuildChownSingleFile(c *check.C) {
|
| 3518 | 3518 |
|
| 3519 | 3519 |
name := "testbuildchownsinglefile" |
| 3520 | 3520 |
|
| 3521 |
- ctx := fakeContext(c, ` |
|
| 3521 |
+ ctx := fakecontext.New(c, "", |
|
| 3522 |
+ fakecontext.WithDockerfile(` |
|
| 3522 | 3523 |
FROM busybox |
| 3523 | 3524 |
COPY test / |
| 3524 | 3525 |
RUN ls -l /test |
| 3525 | 3526 |
RUN [ $(ls -l /test | awk '{print $3":"$4}') = 'root:root' ]
|
| 3526 |
-`, map[string]string{
|
|
| 3527 |
- "test": "test", |
|
| 3528 |
- }) |
|
| 3527 |
+`), |
|
| 3528 |
+ fakecontext.WithFiles(map[string]string{
|
|
| 3529 |
+ "test": "test", |
|
| 3530 |
+ })) |
|
| 3529 | 3531 |
defer ctx.Close() |
| 3530 | 3532 |
|
| 3531 | 3533 |
if err := os.Chown(filepath.Join(ctx.Dir, "test"), 4242, 4242); err != nil {
|
| 3532 | 3534 |
c.Fatal(err) |
| 3533 | 3535 |
} |
| 3534 | 3536 |
|
| 3535 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 3537 |
+ cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) |
|
| 3536 | 3538 |
} |
| 3537 | 3539 |
|
| 3538 | 3540 |
func (s *DockerSuite) TestBuildSymlinkBreakout(c *check.C) {
|
| ... | ... |
@@ -3577,7 +3589,7 @@ func (s *DockerSuite) TestBuildSymlinkBreakout(c *check.C) {
|
| 3577 | 3577 |
w.Close() |
| 3578 | 3578 |
f.Close() |
| 3579 | 3579 |
|
| 3580 |
- buildImageSuccessfully(c, name, build.WithoutCache, withExternalBuildContext(fakeContextFromDir(ctx))) |
|
| 3580 |
+ buildImageSuccessfully(c, name, build.WithoutCache, build.WithExternalBuildContext(fakecontext.New(c, ctx))) |
|
| 3581 | 3581 |
if _, err := os.Lstat(filepath.Join(tmpdir, "inject")); err == nil {
|
| 3582 | 3582 |
c.Fatal("symlink breakout - inject")
|
| 3583 | 3583 |
} else if !os.IsNotExist(err) {
|
| ... | ... |
@@ -3591,15 +3603,15 @@ func (s *DockerSuite) TestBuildXZHost(c *check.C) {
|
| 3591 | 3591 |
testRequires(c, DaemonIsLinux) |
| 3592 | 3592 |
name := "testbuildxzhost" |
| 3593 | 3593 |
|
| 3594 |
- buildImageSuccessfully(c, name, withBuildContext(c, |
|
| 3595 |
- withFile("Dockerfile", `
|
|
| 3594 |
+ buildImageSuccessfully(c, name, build.WithBuildContext(c, |
|
| 3595 |
+ build.WithFile("Dockerfile", `
|
|
| 3596 | 3596 |
FROM busybox |
| 3597 | 3597 |
ADD xz /usr/local/sbin/ |
| 3598 | 3598 |
RUN chmod 755 /usr/local/sbin/xz |
| 3599 | 3599 |
ADD test.xz / |
| 3600 | 3600 |
RUN [ ! -e /injected ]`), |
| 3601 |
- withFile("test.xz", "\xfd\x37\x7a\x58\x5a\x00\x00\x04\xe6\xd6\xb4\x46\x02\x00"+"\x21\x01\x16\x00\x00\x00\x74\x2f\xe5\xa3\x01\x00\x3f\xfd"+"\x37\x7a\x58\x5a\x00\x00\x04\xe6\xd6\xb4\x46\x02\x00\x21"),
|
|
| 3602 |
- withFile("xz", "#!/bin/sh\ntouch /injected"),
|
|
| 3601 |
+ build.WithFile("test.xz", "\xfd\x37\x7a\x58\x5a\x00\x00\x04\xe6\xd6\xb4\x46\x02\x00"+"\x21\x01\x16\x00\x00\x00\x74\x2f\xe5\xa3\x01\x00\x3f\xfd"+"\x37\x7a\x58\x5a\x00\x00\x04\xe6\xd6\xb4\x46\x02\x00\x21"),
|
|
| 3602 |
+ build.WithFile("xz", "#!/bin/sh\ntouch /injected"),
|
|
| 3603 | 3603 |
)) |
| 3604 | 3604 |
} |
| 3605 | 3605 |
|
| ... | ... |
@@ -3617,13 +3629,13 @@ func (s *DockerSuite) TestBuildVolumesRetainContents(c *check.C) {
|
| 3617 | 3617 |
volName = "C:/foo" |
| 3618 | 3618 |
} |
| 3619 | 3619 |
|
| 3620 |
- buildImageSuccessfully(c, name, withBuildContext(c, |
|
| 3621 |
- withFile("Dockerfile", `
|
|
| 3620 |
+ buildImageSuccessfully(c, name, build.WithBuildContext(c, |
|
| 3621 |
+ build.WithFile("Dockerfile", `
|
|
| 3622 | 3622 |
FROM busybox |
| 3623 | 3623 |
COPY content /foo/file |
| 3624 | 3624 |
VOLUME `+volName+` |
| 3625 | 3625 |
CMD cat /foo/file`), |
| 3626 |
- withFile("content", expected),
|
|
| 3626 |
+ build.WithFile("content", expected),
|
|
| 3627 | 3627 |
)) |
| 3628 | 3628 |
|
| 3629 | 3629 |
out, _ := dockerCmd(c, "run", "--rm", name) |
| ... | ... |
@@ -3635,15 +3647,13 @@ CMD cat /foo/file`), |
| 3635 | 3635 |
|
| 3636 | 3636 |
// FIXME(vdemeester) part of this should be unit test, other part should be clearer |
| 3637 | 3637 |
func (s *DockerSuite) TestBuildRenamedDockerfile(c *check.C) {
|
| 3638 |
- ctx := fakeContext(c, `FROM busybox |
|
| 3639 |
- RUN echo from Dockerfile`, |
|
| 3640 |
- map[string]string{
|
|
| 3641 |
- "Dockerfile": "FROM busybox\nRUN echo from Dockerfile", |
|
| 3642 |
- "files/Dockerfile": "FROM busybox\nRUN echo from files/Dockerfile", |
|
| 3643 |
- "files/dFile": "FROM busybox\nRUN echo from files/dFile", |
|
| 3644 |
- "dFile": "FROM busybox\nRUN echo from dFile", |
|
| 3645 |
- "files/dFile2": "FROM busybox\nRUN echo from files/dFile2", |
|
| 3646 |
- }) |
|
| 3638 |
+ ctx := fakecontext.New(c, "", fakecontext.WithFiles(map[string]string{
|
|
| 3639 |
+ "Dockerfile": "FROM busybox\nRUN echo from Dockerfile", |
|
| 3640 |
+ "files/Dockerfile": "FROM busybox\nRUN echo from files/Dockerfile", |
|
| 3641 |
+ "files/dFile": "FROM busybox\nRUN echo from files/dFile", |
|
| 3642 |
+ "dFile": "FROM busybox\nRUN echo from dFile", |
|
| 3643 |
+ "files/dFile2": "FROM busybox\nRUN echo from files/dFile2", |
|
| 3644 |
+ })) |
|
| 3647 | 3645 |
defer ctx.Close() |
| 3648 | 3646 |
|
| 3649 | 3647 |
cli.Docker(cli.Args("build", "-t", "test1", "."), cli.InDir(ctx.Dir)).Assert(c, icmd.Expected{
|
| ... | ... |
@@ -3701,18 +3711,18 @@ func (s *DockerSuite) TestBuildFromMixedcaseDockerfile(c *check.C) {
|
| 3701 | 3701 |
testRequires(c, DaemonIsLinux) |
| 3702 | 3702 |
|
| 3703 | 3703 |
// If Dockerfile is not present, use dockerfile |
| 3704 |
- buildImage("test1", withBuildContext(c,
|
|
| 3705 |
- withFile("dockerfile", `FROM busybox
|
|
| 3704 |
+ buildImage("test1", build.WithBuildContext(c,
|
|
| 3705 |
+ build.WithFile("dockerfile", `FROM busybox
|
|
| 3706 | 3706 |
RUN echo from dockerfile`), |
| 3707 | 3707 |
)).Assert(c, icmd.Expected{
|
| 3708 | 3708 |
Out: "from dockerfile", |
| 3709 | 3709 |
}) |
| 3710 | 3710 |
|
| 3711 | 3711 |
// Prefer Dockerfile in place of dockerfile |
| 3712 |
- buildImage("test1", withBuildContext(c,
|
|
| 3713 |
- withFile("dockerfile", `FROM busybox
|
|
| 3712 |
+ buildImage("test1", build.WithBuildContext(c,
|
|
| 3713 |
+ build.WithFile("dockerfile", `FROM busybox
|
|
| 3714 | 3714 |
RUN echo from dockerfile`), |
| 3715 |
- withFile("Dockerfile", `FROM busybox
|
|
| 3715 |
+ build.WithFile("Dockerfile", `FROM busybox
|
|
| 3716 | 3716 |
RUN echo from Dockerfile`), |
| 3717 | 3717 |
)).Assert(c, icmd.Expected{
|
| 3718 | 3718 |
Out: "from Dockerfile", |
| ... | ... |
@@ -3720,24 +3730,22 @@ func (s *DockerSuite) TestBuildFromMixedcaseDockerfile(c *check.C) {
|
| 3720 | 3720 |
} |
| 3721 | 3721 |
|
| 3722 | 3722 |
func (s *DockerSuite) TestBuildFromURLWithF(c *check.C) {
|
| 3723 |
- server := fakeStorage(c, map[string]string{"baz": `FROM busybox
|
|
| 3723 |
+ server := fakestorage.New(c, "", fakecontext.WithFiles(map[string]string{"baz": `FROM busybox
|
|
| 3724 | 3724 |
RUN echo from baz |
| 3725 | 3725 |
COPY * /tmp/ |
| 3726 |
-RUN find /tmp/`}) |
|
| 3726 |
+RUN find /tmp/`})) |
|
| 3727 | 3727 |
defer server.Close() |
| 3728 | 3728 |
|
| 3729 |
- ctx := fakeContext(c, `FROM busybox |
|
| 3730 |
-RUN echo from Dockerfile`, |
|
| 3731 |
- map[string]string{})
|
|
| 3729 |
+ ctx := fakecontext.New(c, "", fakecontext.WithDockerfile(`FROM busybox |
|
| 3730 |
+ RUN echo from Dockerfile`)) |
|
| 3732 | 3731 |
defer ctx.Close() |
| 3733 | 3732 |
|
| 3734 | 3733 |
// Make sure that -f is ignored and that we don't use the Dockerfile |
| 3735 | 3734 |
// that's in the current dir |
| 3736 |
- result := buildImage("test1", cli.WithFlags("-f", "baz", server.URL()+"/baz"), func(cmd *icmd.Cmd) func() {
|
|
| 3735 |
+ result := cli.BuildCmd(c, "test1", cli.WithFlags("-f", "baz", server.URL()+"/baz"), func(cmd *icmd.Cmd) func() {
|
|
| 3737 | 3736 |
cmd.Dir = ctx.Dir |
| 3738 | 3737 |
return nil |
| 3739 | 3738 |
}) |
| 3740 |
- result.Assert(c, icmd.Success) |
|
| 3741 | 3739 |
|
| 3742 | 3740 |
if !strings.Contains(result.Combined(), "from baz") || |
| 3743 | 3741 |
strings.Contains(result.Combined(), "/tmp/baz") || |
| ... | ... |
@@ -3749,14 +3757,13 @@ RUN echo from Dockerfile`, |
| 3749 | 3749 |
|
| 3750 | 3750 |
func (s *DockerSuite) TestBuildFromStdinWithF(c *check.C) {
|
| 3751 | 3751 |
testRequires(c, DaemonIsLinux) // TODO Windows: This test is flaky; no idea why |
| 3752 |
- ctx := fakeContext(c, `FROM busybox |
|
| 3753 |
-RUN echo "from Dockerfile"`, |
|
| 3754 |
- map[string]string{})
|
|
| 3752 |
+ ctx := fakecontext.New(c, "", fakecontext.WithDockerfile(`FROM busybox |
|
| 3753 |
+RUN echo "from Dockerfile"`)) |
|
| 3755 | 3754 |
defer ctx.Close() |
| 3756 | 3755 |
|
| 3757 | 3756 |
// Make sure that -f is ignored and that we don't use the Dockerfile |
| 3758 | 3757 |
// that's in the current dir |
| 3759 |
- result := buildImage("test1", cli.WithFlags("-f", "baz", "-"), func(cmd *icmd.Cmd) func() {
|
|
| 3758 |
+ result := cli.BuildCmd(c, "test1", cli.WithFlags("-f", "baz", "-"), func(cmd *icmd.Cmd) func() {
|
|
| 3760 | 3759 |
cmd.Dir = ctx.Dir |
| 3761 | 3760 |
cmd.Stdin = strings.NewReader(`FROM busybox |
| 3762 | 3761 |
RUN echo "from baz" |
| ... | ... |
@@ -3764,7 +3771,6 @@ COPY * /tmp/ |
| 3764 | 3764 |
RUN sh -c "find /tmp/" # sh -c is needed on Windows to use the correct find`) |
| 3765 | 3765 |
return nil |
| 3766 | 3766 |
}) |
| 3767 |
- result.Assert(c, icmd.Success) |
|
| 3768 | 3767 |
|
| 3769 | 3768 |
if !strings.Contains(result.Combined(), "from baz") || |
| 3770 | 3769 |
strings.Contains(result.Combined(), "/tmp/baz") || |
| ... | ... |
@@ -3851,19 +3857,16 @@ func (s *DockerSuite) TestBuildSpaces(c *check.C) {
|
| 3851 | 3851 |
// Test to make sure that leading/trailing spaces on a command |
| 3852 | 3852 |
// doesn't change the error msg we get |
| 3853 | 3853 |
name := "testspaces" |
| 3854 |
- ctx := fakeContext(c, "FROM busybox\nCOPY\n", |
|
| 3855 |
- map[string]string{
|
|
| 3856 |
- "Dockerfile": "FROM busybox\nCOPY\n", |
|
| 3857 |
- }) |
|
| 3854 |
+ ctx := fakecontext.New(c, "", fakecontext.WithDockerfile("FROM busybox\nCOPY\n"))
|
|
| 3858 | 3855 |
defer ctx.Close() |
| 3859 | 3856 |
|
| 3860 |
- result1 := buildImage(name, withExternalBuildContext(ctx)) |
|
| 3857 |
+ result1 := cli.Docker(cli.Build(name), build.WithExternalBuildContext(ctx)) |
|
| 3861 | 3858 |
result1.Assert(c, icmd.Expected{
|
| 3862 | 3859 |
ExitCode: 1, |
| 3863 | 3860 |
}) |
| 3864 | 3861 |
|
| 3865 | 3862 |
ctx.Add("Dockerfile", "FROM busybox\nCOPY ")
|
| 3866 |
- result2 := buildImage(name, withExternalBuildContext(ctx)) |
|
| 3863 |
+ result2 := cli.Docker(cli.Build(name), build.WithExternalBuildContext(ctx)) |
|
| 3867 | 3864 |
result2.Assert(c, icmd.Expected{
|
| 3868 | 3865 |
ExitCode: 1, |
| 3869 | 3866 |
}) |
| ... | ... |
@@ -3882,7 +3885,7 @@ func (s *DockerSuite) TestBuildSpaces(c *check.C) {
|
| 3882 | 3882 |
} |
| 3883 | 3883 |
|
| 3884 | 3884 |
ctx.Add("Dockerfile", "FROM busybox\n COPY")
|
| 3885 |
- result2 = buildImage(name, build.WithoutCache, withExternalBuildContext(ctx)) |
|
| 3885 |
+ result2 = cli.Docker(cli.Build(name), build.WithoutCache, build.WithExternalBuildContext(ctx)) |
|
| 3886 | 3886 |
result2.Assert(c, icmd.Expected{
|
| 3887 | 3887 |
ExitCode: 1, |
| 3888 | 3888 |
}) |
| ... | ... |
@@ -3897,7 +3900,7 @@ func (s *DockerSuite) TestBuildSpaces(c *check.C) {
|
| 3897 | 3897 |
} |
| 3898 | 3898 |
|
| 3899 | 3899 |
ctx.Add("Dockerfile", "FROM busybox\n COPY ")
|
| 3900 |
- result2 = buildImage(name, build.WithoutCache, withExternalBuildContext(ctx)) |
|
| 3900 |
+ result2 = cli.Docker(cli.Build(name), build.WithoutCache, build.WithExternalBuildContext(ctx)) |
|
| 3901 | 3901 |
result2.Assert(c, icmd.Expected{
|
| 3902 | 3902 |
ExitCode: 1, |
| 3903 | 3903 |
}) |
| ... | ... |
@@ -4000,9 +4003,9 @@ func (s *DockerSuite) TestBuildEmptyScratch(c *check.C) {
|
| 4000 | 4000 |
} |
| 4001 | 4001 |
|
| 4002 | 4002 |
func (s *DockerSuite) TestBuildDotDotFile(c *check.C) {
|
| 4003 |
- buildImageSuccessfully(c, "sc", withBuildContext(c, |
|
| 4004 |
- withFile("Dockerfile", "FROM busybox\n"),
|
|
| 4005 |
- withFile("..gitme", ""),
|
|
| 4003 |
+ buildImageSuccessfully(c, "sc", build.WithBuildContext(c, |
|
| 4004 |
+ build.WithFile("Dockerfile", "FROM busybox\n"),
|
|
| 4005 |
+ build.WithFile("..gitme", ""),
|
|
| 4006 | 4006 |
)) |
| 4007 | 4007 |
} |
| 4008 | 4008 |
|
| ... | ... |
@@ -4248,16 +4251,16 @@ func (s *DockerSuite) TestBuildNullStringInAddCopyVolume(c *check.C) {
|
| 4248 | 4248 |
volName = `C:\\nullvolume` |
| 4249 | 4249 |
} |
| 4250 | 4250 |
|
| 4251 |
- buildImageSuccessfully(c, name, withBuildContext(c, |
|
| 4252 |
- withFile("Dockerfile", `
|
|
| 4251 |
+ buildImageSuccessfully(c, name, build.WithBuildContext(c, |
|
| 4252 |
+ build.WithFile("Dockerfile", `
|
|
| 4253 | 4253 |
FROM busybox |
| 4254 | 4254 |
|
| 4255 | 4255 |
ADD null / |
| 4256 | 4256 |
COPY nullfile / |
| 4257 | 4257 |
VOLUME `+volName+` |
| 4258 | 4258 |
`), |
| 4259 |
- withFile("null", "test1"),
|
|
| 4260 |
- withFile("nullfile", "test2"),
|
|
| 4259 |
+ build.WithFile("null", "test1"),
|
|
| 4260 |
+ build.WithFile("nullfile", "test2"),
|
|
| 4261 | 4261 |
)) |
| 4262 | 4262 |
} |
| 4263 | 4263 |
|
| ... | ... |
@@ -4528,8 +4531,8 @@ func (s *DockerSuite) TestBuildBuildTimeArgExpansion(c *check.C) {
|
| 4528 | 4528 |
"--build-arg", fmt.Sprintf("%s=%s", userVar, userVal),
|
| 4529 | 4529 |
"--build-arg", fmt.Sprintf("%s=%s", volVar, volVal),
|
| 4530 | 4530 |
), |
| 4531 |
- withBuildContext(c, |
|
| 4532 |
- withFile("Dockerfile", fmt.Sprintf(`FROM busybox
|
|
| 4531 |
+ build.WithBuildContext(c, |
|
| 4532 |
+ build.WithFile("Dockerfile", fmt.Sprintf(`FROM busybox
|
|
| 4533 | 4533 |
ARG %s |
| 4534 | 4534 |
WORKDIR ${%s}
|
| 4535 | 4535 |
ARG %s |
| ... | ... |
@@ -4546,8 +4549,8 @@ func (s *DockerSuite) TestBuildBuildTimeArgExpansion(c *check.C) {
|
| 4546 | 4546 |
VOLUME ${%s}`,
|
| 4547 | 4547 |
wdVar, wdVar, addVar, addVar, copyVar, copyVar, envVar, envVar, |
| 4548 | 4548 |
envVar, exposeVar, exposeVar, userVar, userVar, volVar, volVar)), |
| 4549 |
- withFile(addVal, "some stuff"), |
|
| 4550 |
- withFile(copyVal, "some stuff"), |
|
| 4549 |
+ build.WithFile(addVal, "some stuff"), |
|
| 4550 |
+ build.WithFile(copyVal, "some stuff"), |
|
| 4551 | 4551 |
), |
| 4552 | 4552 |
) |
| 4553 | 4553 |
|
| ... | ... |
@@ -4745,8 +4748,8 @@ func (s *DockerSuite) TestBuildBuildTimeArgEnv(c *check.C) {
|
| 4745 | 4745 |
"FOO1=fromenv", |
| 4746 | 4746 |
"FOO2=fromenv", |
| 4747 | 4747 |
"FOO3=fromenv")...), |
| 4748 |
- withBuildContext(c, |
|
| 4749 |
- withFile("Dockerfile", dockerfile),
|
|
| 4748 |
+ build.WithBuildContext(c, |
|
| 4749 |
+ build.WithFile("Dockerfile", dockerfile),
|
|
| 4750 | 4750 |
), |
| 4751 | 4751 |
) |
| 4752 | 4752 |
result.Assert(c, icmd.Success) |
| ... | ... |
@@ -4941,26 +4944,26 @@ func (s *DockerSuite) TestBuildMultipleTags(c *check.C) {
|
| 4941 | 4941 |
// #17290 |
| 4942 | 4942 |
func (s *DockerSuite) TestBuildCacheBrokenSymlink(c *check.C) {
|
| 4943 | 4943 |
name := "testbuildbrokensymlink" |
| 4944 |
- ctx := fakeContext(c, ` |
|
| 4944 |
+ ctx := fakecontext.New(c, "", |
|
| 4945 |
+ fakecontext.WithDockerfile(` |
|
| 4945 | 4946 |
FROM busybox |
| 4946 |
- COPY . ./`, |
|
| 4947 |
- map[string]string{
|
|
| 4947 |
+ COPY . ./`), |
|
| 4948 |
+ fakecontext.WithFiles(map[string]string{
|
|
| 4948 | 4949 |
"foo": "bar", |
| 4949 |
- }) |
|
| 4950 |
+ })) |
|
| 4950 | 4951 |
defer ctx.Close() |
| 4951 | 4952 |
|
| 4952 | 4953 |
err := os.Symlink(filepath.Join(ctx.Dir, "nosuchfile"), filepath.Join(ctx.Dir, "asymlink")) |
| 4953 | 4954 |
c.Assert(err, checker.IsNil) |
| 4954 | 4955 |
|
| 4955 | 4956 |
// warm up cache |
| 4956 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 4957 |
+ cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) |
|
| 4957 | 4958 |
|
| 4958 | 4959 |
// add new file to context, should invalidate cache |
| 4959 | 4960 |
err = ioutil.WriteFile(filepath.Join(ctx.Dir, "newfile"), []byte("foo"), 0644)
|
| 4960 | 4961 |
c.Assert(err, checker.IsNil) |
| 4961 | 4962 |
|
| 4962 |
- result := buildImage(name, withExternalBuildContext(ctx)) |
|
| 4963 |
- result.Assert(c, icmd.Success) |
|
| 4963 |
+ result := cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) |
|
| 4964 | 4964 |
if strings.Contains(result.Combined(), "Using cache") {
|
| 4965 | 4965 |
c.Fatal("2nd build used cache on ADD, it shouldn't")
|
| 4966 | 4966 |
} |
| ... | ... |
@@ -4968,62 +4971,62 @@ func (s *DockerSuite) TestBuildCacheBrokenSymlink(c *check.C) {
|
| 4968 | 4968 |
|
| 4969 | 4969 |
func (s *DockerSuite) TestBuildFollowSymlinkToFile(c *check.C) {
|
| 4970 | 4970 |
name := "testbuildbrokensymlink" |
| 4971 |
- ctx := fakeContext(c, ` |
|
| 4971 |
+ ctx := fakecontext.New(c, "", |
|
| 4972 |
+ fakecontext.WithDockerfile(` |
|
| 4972 | 4973 |
FROM busybox |
| 4973 |
- COPY asymlink target`, |
|
| 4974 |
- map[string]string{
|
|
| 4974 |
+ COPY asymlink target`), |
|
| 4975 |
+ fakecontext.WithFiles(map[string]string{
|
|
| 4975 | 4976 |
"foo": "bar", |
| 4976 |
- }) |
|
| 4977 |
+ })) |
|
| 4977 | 4978 |
defer ctx.Close() |
| 4978 | 4979 |
|
| 4979 | 4980 |
err := os.Symlink("foo", filepath.Join(ctx.Dir, "asymlink"))
|
| 4980 | 4981 |
c.Assert(err, checker.IsNil) |
| 4981 | 4982 |
|
| 4982 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 4983 |
+ cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) |
|
| 4983 | 4984 |
|
| 4984 |
- out, _ := dockerCmd(c, "run", "--rm", name, "cat", "target") |
|
| 4985 |
+ out := cli.DockerCmd(c, "run", "--rm", name, "cat", "target").Combined() |
|
| 4985 | 4986 |
c.Assert(out, checker.Matches, "bar") |
| 4986 | 4987 |
|
| 4987 | 4988 |
// change target file should invalidate cache |
| 4988 | 4989 |
err = ioutil.WriteFile(filepath.Join(ctx.Dir, "foo"), []byte("baz"), 0644)
|
| 4989 | 4990 |
c.Assert(err, checker.IsNil) |
| 4990 | 4991 |
|
| 4991 |
- result := buildImage(name, withExternalBuildContext(ctx)) |
|
| 4992 |
- result.Assert(c, icmd.Success) |
|
| 4992 |
+ result := cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) |
|
| 4993 | 4993 |
c.Assert(result.Combined(), checker.Not(checker.Contains), "Using cache") |
| 4994 | 4994 |
|
| 4995 |
- out, _ = dockerCmd(c, "run", "--rm", name, "cat", "target") |
|
| 4995 |
+ out = cli.DockerCmd(c, "run", "--rm", name, "cat", "target").Combined() |
|
| 4996 | 4996 |
c.Assert(out, checker.Matches, "baz") |
| 4997 | 4997 |
} |
| 4998 | 4998 |
|
| 4999 | 4999 |
func (s *DockerSuite) TestBuildFollowSymlinkToDir(c *check.C) {
|
| 5000 | 5000 |
name := "testbuildbrokensymlink" |
| 5001 |
- ctx := fakeContext(c, ` |
|
| 5001 |
+ ctx := fakecontext.New(c, "", |
|
| 5002 |
+ fakecontext.WithDockerfile(` |
|
| 5002 | 5003 |
FROM busybox |
| 5003 |
- COPY asymlink /`, |
|
| 5004 |
- map[string]string{
|
|
| 5004 |
+ COPY asymlink /`), |
|
| 5005 |
+ fakecontext.WithFiles(map[string]string{
|
|
| 5005 | 5006 |
"foo/abc": "bar", |
| 5006 | 5007 |
"foo/def": "baz", |
| 5007 |
- }) |
|
| 5008 |
+ })) |
|
| 5008 | 5009 |
defer ctx.Close() |
| 5009 | 5010 |
|
| 5010 | 5011 |
err := os.Symlink("foo", filepath.Join(ctx.Dir, "asymlink"))
|
| 5011 | 5012 |
c.Assert(err, checker.IsNil) |
| 5012 | 5013 |
|
| 5013 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 5014 |
+ cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) |
|
| 5014 | 5015 |
|
| 5015 |
- out, _ := dockerCmd(c, "run", "--rm", name, "cat", "abc", "def") |
|
| 5016 |
+ out := cli.DockerCmd(c, "run", "--rm", name, "cat", "abc", "def").Combined() |
|
| 5016 | 5017 |
c.Assert(out, checker.Matches, "barbaz") |
| 5017 | 5018 |
|
| 5018 | 5019 |
// change target file should invalidate cache |
| 5019 | 5020 |
err = ioutil.WriteFile(filepath.Join(ctx.Dir, "foo/def"), []byte("bax"), 0644)
|
| 5020 | 5021 |
c.Assert(err, checker.IsNil) |
| 5021 | 5022 |
|
| 5022 |
- result := buildImage(name, withExternalBuildContext(ctx)) |
|
| 5023 |
- result.Assert(c, icmd.Success) |
|
| 5023 |
+ result := cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) |
|
| 5024 | 5024 |
c.Assert(result.Combined(), checker.Not(checker.Contains), "Using cache") |
| 5025 | 5025 |
|
| 5026 |
- out, _ = dockerCmd(c, "run", "--rm", name, "cat", "abc", "def") |
|
| 5026 |
+ out = cli.DockerCmd(c, "run", "--rm", name, "cat", "abc", "def").Combined() |
|
| 5027 | 5027 |
c.Assert(out, checker.Matches, "barbax") |
| 5028 | 5028 |
|
| 5029 | 5029 |
} |
| ... | ... |
@@ -5032,43 +5035,44 @@ func (s *DockerSuite) TestBuildFollowSymlinkToDir(c *check.C) {
|
| 5032 | 5032 |
// not from the target file. |
| 5033 | 5033 |
func (s *DockerSuite) TestBuildSymlinkBasename(c *check.C) {
|
| 5034 | 5034 |
name := "testbuildbrokensymlink" |
| 5035 |
- ctx := fakeContext(c, ` |
|
| 5035 |
+ ctx := fakecontext.New(c, "", |
|
| 5036 |
+ fakecontext.WithDockerfile(` |
|
| 5036 | 5037 |
FROM busybox |
| 5037 |
- COPY asymlink /`, |
|
| 5038 |
- map[string]string{
|
|
| 5038 |
+ COPY asymlink /`), |
|
| 5039 |
+ fakecontext.WithFiles(map[string]string{
|
|
| 5039 | 5040 |
"foo": "bar", |
| 5040 |
- }) |
|
| 5041 |
+ })) |
|
| 5041 | 5042 |
defer ctx.Close() |
| 5042 | 5043 |
|
| 5043 | 5044 |
err := os.Symlink("foo", filepath.Join(ctx.Dir, "asymlink"))
|
| 5044 | 5045 |
c.Assert(err, checker.IsNil) |
| 5045 | 5046 |
|
| 5046 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 5047 |
+ cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) |
|
| 5047 | 5048 |
|
| 5048 |
- out, _ := dockerCmd(c, "run", "--rm", name, "cat", "asymlink") |
|
| 5049 |
+ out := cli.DockerCmd(c, "run", "--rm", name, "cat", "asymlink").Combined() |
|
| 5049 | 5050 |
c.Assert(out, checker.Matches, "bar") |
| 5050 | 5051 |
} |
| 5051 | 5052 |
|
| 5052 | 5053 |
// #17827 |
| 5053 | 5054 |
func (s *DockerSuite) TestBuildCacheRootSource(c *check.C) {
|
| 5054 | 5055 |
name := "testbuildrootsource" |
| 5055 |
- ctx := fakeContext(c, ` |
|
| 5056 |
+ ctx := fakecontext.New(c, "", |
|
| 5057 |
+ fakecontext.WithDockerfile(` |
|
| 5056 | 5058 |
FROM busybox |
| 5057 |
- COPY / /data`, |
|
| 5058 |
- map[string]string{
|
|
| 5059 |
+ COPY / /data`), |
|
| 5060 |
+ fakecontext.WithFiles(map[string]string{
|
|
| 5059 | 5061 |
"foo": "bar", |
| 5060 |
- }) |
|
| 5062 |
+ })) |
|
| 5061 | 5063 |
defer ctx.Close() |
| 5062 | 5064 |
|
| 5063 | 5065 |
// warm up cache |
| 5064 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 5066 |
+ cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) |
|
| 5065 | 5067 |
|
| 5066 | 5068 |
// change file, should invalidate cache |
| 5067 | 5069 |
err := ioutil.WriteFile(filepath.Join(ctx.Dir, "foo"), []byte("baz"), 0644)
|
| 5068 | 5070 |
c.Assert(err, checker.IsNil) |
| 5069 | 5071 |
|
| 5070 |
- result := buildImage(name, withExternalBuildContext(ctx)) |
|
| 5071 |
- result.Assert(c, icmd.Success) |
|
| 5072 |
+ result := cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) |
|
| 5072 | 5073 |
|
| 5073 | 5074 |
c.Assert(result.Combined(), checker.Not(checker.Contains), "Using cache") |
| 5074 | 5075 |
} |
| ... | ... |
@@ -5340,14 +5344,14 @@ func (s *DockerSuite) TestBuildDockerignoreComment(c *check.C) {
|
| 5340 | 5340 |
RUN sh -c "(ls -la /tmp/#1)" |
| 5341 | 5341 |
RUN sh -c "(! ls -la /tmp/#2)" |
| 5342 | 5342 |
RUN sh -c "(! ls /tmp/foo) && (! ls /tmp/foo2) && (ls /tmp/dir1/foo)"` |
| 5343 |
- buildImageSuccessfully(c, name, withBuildContext(c, |
|
| 5344 |
- withFile("Dockerfile", dockerfile),
|
|
| 5345 |
- withFile("foo", "foo"),
|
|
| 5346 |
- withFile("foo2", "foo2"),
|
|
| 5347 |
- withFile("dir1/foo", "foo in dir1"),
|
|
| 5348 |
- withFile("#1", "# file 1"),
|
|
| 5349 |
- withFile("#2", "# file 2"),
|
|
| 5350 |
- withFile(".dockerignore", `# Visual C++ cache files
|
|
| 5343 |
+ buildImageSuccessfully(c, name, build.WithBuildContext(c, |
|
| 5344 |
+ build.WithFile("Dockerfile", dockerfile),
|
|
| 5345 |
+ build.WithFile("foo", "foo"),
|
|
| 5346 |
+ build.WithFile("foo2", "foo2"),
|
|
| 5347 |
+ build.WithFile("dir1/foo", "foo in dir1"),
|
|
| 5348 |
+ build.WithFile("#1", "# file 1"),
|
|
| 5349 |
+ build.WithFile("#2", "# file 2"),
|
|
| 5350 |
+ build.WithFile(".dockerignore", `# Visual C++ cache files
|
|
| 5351 | 5351 |
# because we have git ;-) |
| 5352 | 5352 |
# The above comment is from #20083 |
| 5353 | 5353 |
foo |
| ... | ... |
@@ -5365,8 +5369,8 @@ func (s *DockerSuite) TestBuildWithUTF8BOM(c *check.C) {
|
| 5365 | 5365 |
name := "test-with-utf8-bom" |
| 5366 | 5366 |
dockerfile := []byte(`FROM busybox`) |
| 5367 | 5367 |
bomDockerfile := append([]byte{0xEF, 0xBB, 0xBF}, dockerfile...)
|
| 5368 |
- buildImageSuccessfully(c, name, withBuildContext(c, |
|
| 5369 |
- withFile("Dockerfile", string(bomDockerfile)),
|
|
| 5368 |
+ buildImageSuccessfully(c, name, build.WithBuildContext(c, |
|
| 5369 |
+ build.WithFile("Dockerfile", string(bomDockerfile)),
|
|
| 5370 | 5370 |
)) |
| 5371 | 5371 |
} |
| 5372 | 5372 |
|
| ... | ... |
@@ -5381,9 +5385,9 @@ func (s *DockerSuite) TestBuildWithUTF8BOMDockerignore(c *check.C) {
|
| 5381 | 5381 |
RUN ls /tmp/.dockerignore` |
| 5382 | 5382 |
dockerignore := []byte("./Dockerfile\n")
|
| 5383 | 5383 |
bomDockerignore := append([]byte{0xEF, 0xBB, 0xBF}, dockerignore...)
|
| 5384 |
- buildImageSuccessfully(c, name, withBuildContext(c, |
|
| 5385 |
- withFile("Dockerfile", dockerfile),
|
|
| 5386 |
- withFile(".dockerignore", string(bomDockerignore)),
|
|
| 5384 |
+ buildImageSuccessfully(c, name, build.WithBuildContext(c, |
|
| 5385 |
+ build.WithFile("Dockerfile", dockerfile),
|
|
| 5386 |
+ build.WithFile(".dockerignore", string(bomDockerignore)),
|
|
| 5387 | 5387 |
)) |
| 5388 | 5388 |
} |
| 5389 | 5389 |
|
| ... | ... |
@@ -5571,17 +5575,18 @@ func (s *DockerSuite) TestBuildCacheFromEqualDiffIDsLength(c *check.C) {
|
| 5571 | 5571 |
FROM busybox |
| 5572 | 5572 |
RUN echo "test" |
| 5573 | 5573 |
ENTRYPOINT ["sh"]` |
| 5574 |
- ctx := fakeContext(c, dockerfile, map[string]string{
|
|
| 5575 |
- "Dockerfile": dockerfile, |
|
| 5576 |
- }) |
|
| 5574 |
+ ctx := fakecontext.New(c, "", |
|
| 5575 |
+ fakecontext.WithDockerfile(dockerfile), |
|
| 5576 |
+ fakecontext.WithFiles(map[string]string{
|
|
| 5577 |
+ "Dockerfile": dockerfile, |
|
| 5578 |
+ })) |
|
| 5577 | 5579 |
defer ctx.Close() |
| 5578 | 5580 |
|
| 5579 |
- buildImageSuccessfully(c, "build1", withExternalBuildContext(ctx)) |
|
| 5581 |
+ cli.BuildCmd(c, "build1", build.WithExternalBuildContext(ctx)) |
|
| 5580 | 5582 |
id1 := getIDByName(c, "build1") |
| 5581 | 5583 |
|
| 5582 | 5584 |
// rebuild with cache-from |
| 5583 |
- result := buildImage("build2", cli.WithFlags("--cache-from=build1"), withExternalBuildContext(ctx))
|
|
| 5584 |
- result.Assert(c, icmd.Success) |
|
| 5585 |
+ result := cli.BuildCmd(c, "build2", cli.WithFlags("--cache-from=build1"), build.WithExternalBuildContext(ctx))
|
|
| 5585 | 5586 |
id2 := getIDByName(c, "build2") |
| 5586 | 5587 |
c.Assert(id1, checker.Equals, id2) |
| 5587 | 5588 |
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 2) |
| ... | ... |
@@ -5594,30 +5599,30 @@ func (s *DockerSuite) TestBuildCacheFrom(c *check.C) {
|
| 5594 | 5594 |
ENV FOO=bar |
| 5595 | 5595 |
ADD baz / |
| 5596 | 5596 |
RUN touch bax` |
| 5597 |
- ctx := fakeContext(c, dockerfile, map[string]string{
|
|
| 5598 |
- "Dockerfile": dockerfile, |
|
| 5599 |
- "baz": "baz", |
|
| 5600 |
- }) |
|
| 5597 |
+ ctx := fakecontext.New(c, "", |
|
| 5598 |
+ fakecontext.WithDockerfile(dockerfile), |
|
| 5599 |
+ fakecontext.WithFiles(map[string]string{
|
|
| 5600 |
+ "Dockerfile": dockerfile, |
|
| 5601 |
+ "baz": "baz", |
|
| 5602 |
+ })) |
|
| 5601 | 5603 |
defer ctx.Close() |
| 5602 | 5604 |
|
| 5603 |
- buildImageSuccessfully(c, "build1", withExternalBuildContext(ctx)) |
|
| 5605 |
+ cli.BuildCmd(c, "build1", build.WithExternalBuildContext(ctx)) |
|
| 5604 | 5606 |
id1 := getIDByName(c, "build1") |
| 5605 | 5607 |
|
| 5606 | 5608 |
// rebuild with cache-from |
| 5607 |
- result := buildImage("build2", cli.WithFlags("--cache-from=build1"), withExternalBuildContext(ctx))
|
|
| 5608 |
- result.Assert(c, icmd.Success) |
|
| 5609 |
+ result := cli.BuildCmd(c, "build2", cli.WithFlags("--cache-from=build1"), build.WithExternalBuildContext(ctx))
|
|
| 5609 | 5610 |
id2 := getIDByName(c, "build2") |
| 5610 | 5611 |
c.Assert(id1, checker.Equals, id2) |
| 5611 | 5612 |
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 3) |
| 5612 |
- dockerCmd(c, "rmi", "build2") |
|
| 5613 |
+ cli.DockerCmd(c, "rmi", "build2") |
|
| 5613 | 5614 |
|
| 5614 | 5615 |
// no cache match with unknown source |
| 5615 |
- result = buildImage("build2", cli.WithFlags("--cache-from=nosuchtag"), withExternalBuildContext(ctx))
|
|
| 5616 |
- result.Assert(c, icmd.Success) |
|
| 5616 |
+ result = cli.BuildCmd(c, "build2", cli.WithFlags("--cache-from=nosuchtag"), build.WithExternalBuildContext(ctx))
|
|
| 5617 | 5617 |
id2 = getIDByName(c, "build2") |
| 5618 | 5618 |
c.Assert(id1, checker.Not(checker.Equals), id2) |
| 5619 | 5619 |
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 0) |
| 5620 |
- dockerCmd(c, "rmi", "build2") |
|
| 5620 |
+ cli.DockerCmd(c, "rmi", "build2") |
|
| 5621 | 5621 |
|
| 5622 | 5622 |
// clear parent images |
| 5623 | 5623 |
tempDir, err := ioutil.TempDir("", "test-build-cache-from-")
|
| ... | ... |
@@ -5626,33 +5631,31 @@ func (s *DockerSuite) TestBuildCacheFrom(c *check.C) {
|
| 5626 | 5626 |
} |
| 5627 | 5627 |
defer os.RemoveAll(tempDir) |
| 5628 | 5628 |
tempFile := filepath.Join(tempDir, "img.tar") |
| 5629 |
- dockerCmd(c, "save", "-o", tempFile, "build1") |
|
| 5630 |
- dockerCmd(c, "rmi", "build1") |
|
| 5631 |
- dockerCmd(c, "load", "-i", tempFile) |
|
| 5632 |
- parentID, _ := dockerCmd(c, "inspect", "-f", "{{.Parent}}", "build1")
|
|
| 5629 |
+ cli.DockerCmd(c, "save", "-o", tempFile, "build1") |
|
| 5630 |
+ cli.DockerCmd(c, "rmi", "build1") |
|
| 5631 |
+ cli.DockerCmd(c, "load", "-i", tempFile) |
|
| 5632 |
+ parentID := cli.DockerCmd(c, "inspect", "-f", "{{.Parent}}", "build1").Combined()
|
|
| 5633 | 5633 |
c.Assert(strings.TrimSpace(parentID), checker.Equals, "") |
| 5634 | 5634 |
|
| 5635 | 5635 |
// cache still applies without parents |
| 5636 |
- result = buildImage("build2", cli.WithFlags("--cache-from=build1"), withExternalBuildContext(ctx))
|
|
| 5637 |
- result.Assert(c, icmd.Success) |
|
| 5636 |
+ result = cli.BuildCmd(c, "build2", cli.WithFlags("--cache-from=build1"), build.WithExternalBuildContext(ctx))
|
|
| 5638 | 5637 |
id2 = getIDByName(c, "build2") |
| 5639 | 5638 |
c.Assert(id1, checker.Equals, id2) |
| 5640 | 5639 |
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 3) |
| 5641 |
- history1, _ := dockerCmd(c, "history", "-q", "build2") |
|
| 5640 |
+ history1 := cli.DockerCmd(c, "history", "-q", "build2").Combined() |
|
| 5642 | 5641 |
|
| 5643 | 5642 |
// Retry, no new intermediate images |
| 5644 |
- result = buildImage("build3", cli.WithFlags("--cache-from=build1"), withExternalBuildContext(ctx))
|
|
| 5645 |
- result.Assert(c, icmd.Success) |
|
| 5643 |
+ result = cli.BuildCmd(c, "build3", cli.WithFlags("--cache-from=build1"), build.WithExternalBuildContext(ctx))
|
|
| 5646 | 5644 |
id3 := getIDByName(c, "build3") |
| 5647 | 5645 |
c.Assert(id1, checker.Equals, id3) |
| 5648 | 5646 |
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 3) |
| 5649 |
- history2, _ := dockerCmd(c, "history", "-q", "build3") |
|
| 5647 |
+ history2 := cli.DockerCmd(c, "history", "-q", "build3").Combined() |
|
| 5650 | 5648 |
|
| 5651 | 5649 |
c.Assert(history1, checker.Equals, history2) |
| 5652 |
- dockerCmd(c, "rmi", "build2") |
|
| 5653 |
- dockerCmd(c, "rmi", "build3") |
|
| 5654 |
- dockerCmd(c, "rmi", "build1") |
|
| 5655 |
- dockerCmd(c, "load", "-i", tempFile) |
|
| 5650 |
+ cli.DockerCmd(c, "rmi", "build2") |
|
| 5651 |
+ cli.DockerCmd(c, "rmi", "build3") |
|
| 5652 |
+ cli.DockerCmd(c, "rmi", "build1") |
|
| 5653 |
+ cli.DockerCmd(c, "load", "-i", tempFile) |
|
| 5656 | 5654 |
|
| 5657 | 5655 |
// Modify file, everything up to last command and layers are reused |
| 5658 | 5656 |
dockerfile = ` |
| ... | ... |
@@ -5663,14 +5666,13 @@ func (s *DockerSuite) TestBuildCacheFrom(c *check.C) {
|
| 5663 | 5663 |
err = ioutil.WriteFile(filepath.Join(ctx.Dir, "Dockerfile"), []byte(dockerfile), 0644) |
| 5664 | 5664 |
c.Assert(err, checker.IsNil) |
| 5665 | 5665 |
|
| 5666 |
- result = buildImage("build2", cli.WithFlags("--cache-from=build1"), withExternalBuildContext(ctx))
|
|
| 5667 |
- result.Assert(c, icmd.Success) |
|
| 5666 |
+ result = cli.BuildCmd(c, "build2", cli.WithFlags("--cache-from=build1"), build.WithExternalBuildContext(ctx))
|
|
| 5668 | 5667 |
id2 = getIDByName(c, "build2") |
| 5669 | 5668 |
c.Assert(id1, checker.Not(checker.Equals), id2) |
| 5670 | 5669 |
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 2) |
| 5671 | 5670 |
|
| 5672 |
- layers1Str, _ := dockerCmd(c, "inspect", "-f", "{{json .RootFS.Layers}}", "build1")
|
|
| 5673 |
- layers2Str, _ := dockerCmd(c, "inspect", "-f", "{{json .RootFS.Layers}}", "build2")
|
|
| 5671 |
+ layers1Str := cli.DockerCmd(c, "inspect", "-f", "{{json .RootFS.Layers}}", "build1").Combined()
|
|
| 5672 |
+ layers2Str := cli.DockerCmd(c, "inspect", "-f", "{{json .RootFS.Layers}}", "build2").Combined()
|
|
| 5674 | 5673 |
|
| 5675 | 5674 |
var layers1 []string |
| 5676 | 5675 |
var layers2 []string |
| ... | ... |
@@ -5691,19 +5693,19 @@ func (s *DockerSuite) TestBuildCacheMultipleFrom(c *check.C) {
|
| 5691 | 5691 |
ADD baz / |
| 5692 | 5692 |
FROM busybox |
| 5693 | 5693 |
ADD baz /` |
| 5694 |
- ctx := fakeContext(c, dockerfile, map[string]string{
|
|
| 5695 |
- "Dockerfile": dockerfile, |
|
| 5696 |
- "baz": "baz", |
|
| 5697 |
- }) |
|
| 5694 |
+ ctx := fakecontext.New(c, "", |
|
| 5695 |
+ fakecontext.WithDockerfile(dockerfile), |
|
| 5696 |
+ fakecontext.WithFiles(map[string]string{
|
|
| 5697 |
+ "Dockerfile": dockerfile, |
|
| 5698 |
+ "baz": "baz", |
|
| 5699 |
+ })) |
|
| 5698 | 5700 |
defer ctx.Close() |
| 5699 | 5701 |
|
| 5700 |
- result := buildImage("build1", withExternalBuildContext(ctx))
|
|
| 5701 |
- result.Assert(c, icmd.Success) |
|
| 5702 |
+ result := cli.BuildCmd(c, "build1", build.WithExternalBuildContext(ctx)) |
|
| 5702 | 5703 |
// second part of dockerfile was a repeat of first so should be cached |
| 5703 | 5704 |
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 1) |
| 5704 | 5705 |
|
| 5705 |
- result = buildImage("build2", cli.WithFlags("--cache-from=build1"), withExternalBuildContext(ctx))
|
|
| 5706 |
- result.Assert(c, icmd.Success) |
|
| 5706 |
+ result = cli.BuildCmd(c, "build2", cli.WithFlags("--cache-from=build1"), build.WithExternalBuildContext(ctx))
|
|
| 5707 | 5707 |
// now both parts of dockerfile should be cached |
| 5708 | 5708 |
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 2) |
| 5709 | 5709 |
} |
| ... | ... |
@@ -5859,31 +5861,30 @@ func (s *DockerSuite) TestBuildCopyFromPreviousRootFS(c *check.C) {
|
| 5859 | 5859 |
COPY --from=0 bar baz |
| 5860 | 5860 |
COPY --from=first bar bay` |
| 5861 | 5861 |
|
| 5862 |
- ctx := fakeContext(c, fmt.Sprintf(dockerfile, ""), map[string]string{
|
|
| 5863 |
- "Dockerfile": dockerfile, |
|
| 5864 |
- "foo": "abc", |
|
| 5865 |
- "bar": "def", |
|
| 5866 |
- "baz/aa": "ghi", |
|
| 5867 |
- "baz/bb": "jkl", |
|
| 5868 |
- }) |
|
| 5862 |
+ ctx := fakecontext.New(c, "", |
|
| 5863 |
+ fakecontext.WithDockerfile(fmt.Sprintf(dockerfile, "")), |
|
| 5864 |
+ fakecontext.WithFiles(map[string]string{
|
|
| 5865 |
+ "foo": "abc", |
|
| 5866 |
+ "bar": "def", |
|
| 5867 |
+ "baz/aa": "ghi", |
|
| 5868 |
+ "baz/bb": "jkl", |
|
| 5869 |
+ })) |
|
| 5869 | 5870 |
defer ctx.Close() |
| 5870 | 5871 |
|
| 5871 |
- result := buildImage("build1", withExternalBuildContext(ctx))
|
|
| 5872 |
- result.Assert(c, icmd.Success) |
|
| 5872 |
+ cli.BuildCmd(c, "build1", build.WithExternalBuildContext(ctx)) |
|
| 5873 | 5873 |
|
| 5874 |
- out, _ := dockerCmd(c, "run", "build1", "cat", "bar") |
|
| 5874 |
+ out := cli.DockerCmd(c, "run", "build1", "cat", "bar").Combined() |
|
| 5875 | 5875 |
c.Assert(strings.TrimSpace(out), check.Equals, "def") |
| 5876 |
- out, _ = dockerCmd(c, "run", "build1", "cat", "sub/aa") |
|
| 5876 |
+ out = cli.DockerCmd(c, "run", "build1", "cat", "sub/aa").Combined() |
|
| 5877 | 5877 |
c.Assert(strings.TrimSpace(out), check.Equals, "ghi") |
| 5878 |
- out, _ = dockerCmd(c, "run", "build1", "cat", "sub/cc") |
|
| 5878 |
+ out = cli.DockerCmd(c, "run", "build1", "cat", "sub/cc").Combined() |
|
| 5879 | 5879 |
c.Assert(strings.TrimSpace(out), check.Equals, "mno") |
| 5880 |
- out, _ = dockerCmd(c, "run", "build1", "cat", "baz") |
|
| 5880 |
+ out = cli.DockerCmd(c, "run", "build1", "cat", "baz").Combined() |
|
| 5881 | 5881 |
c.Assert(strings.TrimSpace(out), check.Equals, "abc") |
| 5882 |
- out, _ = dockerCmd(c, "run", "build1", "cat", "bay") |
|
| 5882 |
+ out = cli.DockerCmd(c, "run", "build1", "cat", "bay").Combined() |
|
| 5883 | 5883 |
c.Assert(strings.TrimSpace(out), check.Equals, "abc") |
| 5884 | 5884 |
|
| 5885 |
- result = buildImage("build2", withExternalBuildContext(ctx))
|
|
| 5886 |
- result.Assert(c, icmd.Success) |
|
| 5885 |
+ result := cli.BuildCmd(c, "build2", build.WithExternalBuildContext(ctx)) |
|
| 5887 | 5886 |
|
| 5888 | 5887 |
// all commands should be cached |
| 5889 | 5888 |
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 7) |
| ... | ... |
@@ -5892,8 +5893,7 @@ func (s *DockerSuite) TestBuildCopyFromPreviousRootFS(c *check.C) {
|
| 5892 | 5892 |
c.Assert(err, checker.IsNil) |
| 5893 | 5893 |
|
| 5894 | 5894 |
// changing file in parent block should not affect last block |
| 5895 |
- result = buildImage("build3", withExternalBuildContext(ctx))
|
|
| 5896 |
- result.Assert(c, icmd.Success) |
|
| 5895 |
+ result = cli.BuildCmd(c, "build3", build.WithExternalBuildContext(ctx)) |
|
| 5897 | 5896 |
|
| 5898 | 5897 |
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 5) |
| 5899 | 5898 |
|
| ... | ... |
@@ -5903,108 +5903,92 @@ func (s *DockerSuite) TestBuildCopyFromPreviousRootFS(c *check.C) {
|
| 5903 | 5903 |
c.Assert(err, checker.IsNil) |
| 5904 | 5904 |
|
| 5905 | 5905 |
// changing file in parent block should affect both first and last block |
| 5906 |
- result = buildImage("build4", withExternalBuildContext(ctx))
|
|
| 5907 |
- result.Assert(c, icmd.Success) |
|
| 5906 |
+ result = cli.BuildCmd(c, "build4", build.WithExternalBuildContext(ctx)) |
|
| 5908 | 5907 |
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 5) |
| 5909 | 5908 |
|
| 5910 |
- out, _ = dockerCmd(c, "run", "build4", "cat", "bay") |
|
| 5909 |
+ out = cli.DockerCmd(c, "run", "build4", "cat", "bay").Combined() |
|
| 5911 | 5910 |
c.Assert(strings.TrimSpace(out), check.Equals, "pqr") |
| 5912 |
- out, _ = dockerCmd(c, "run", "build4", "cat", "baz") |
|
| 5911 |
+ out = cli.DockerCmd(c, "run", "build4", "cat", "baz").Combined() |
|
| 5913 | 5912 |
c.Assert(strings.TrimSpace(out), check.Equals, "pqr") |
| 5914 | 5913 |
} |
| 5915 | 5914 |
|
| 5916 | 5915 |
func (s *DockerSuite) TestBuildCopyFromPreviousRootFSErrors(c *check.C) {
|
| 5917 |
- dockerfile := ` |
|
| 5916 |
+ testCases := []struct {
|
|
| 5917 |
+ dockerfile string |
|
| 5918 |
+ expectedError string |
|
| 5919 |
+ }{
|
|
| 5920 |
+ {
|
|
| 5921 |
+ dockerfile: ` |
|
| 5918 | 5922 |
FROM busybox |
| 5919 |
- COPY --from=foo foo bar` |
|
| 5920 |
- |
|
| 5921 |
- ctx := fakeContext(c, dockerfile, map[string]string{
|
|
| 5922 |
- "Dockerfile": dockerfile, |
|
| 5923 |
- "foo": "abc", |
|
| 5924 |
- }) |
|
| 5925 |
- defer ctx.Close() |
|
| 5926 |
- |
|
| 5927 |
- buildImage("build1", withExternalBuildContext(ctx)).Assert(c, icmd.Expected{
|
|
| 5928 |
- ExitCode: 1, |
|
| 5929 |
- Err: "invalid from flag value foo", |
|
| 5930 |
- }) |
|
| 5931 |
- |
|
| 5932 |
- dockerfile = ` |
|
| 5923 |
+ COPY --from=foo foo bar`, |
|
| 5924 |
+ expectedError: "invalid from flag value foo", |
|
| 5925 |
+ }, |
|
| 5926 |
+ {
|
|
| 5927 |
+ dockerfile: ` |
|
| 5933 | 5928 |
FROM busybox |
| 5934 |
- COPY --from=0 foo bar` |
|
| 5935 |
- |
|
| 5936 |
- ctx = fakeContext(c, dockerfile, map[string]string{
|
|
| 5937 |
- "Dockerfile": dockerfile, |
|
| 5938 |
- "foo": "abc", |
|
| 5939 |
- }) |
|
| 5940 |
- defer ctx.Close() |
|
| 5941 |
- |
|
| 5942 |
- buildImage("build1", withExternalBuildContext(ctx)).Assert(c, icmd.Expected{
|
|
| 5943 |
- ExitCode: 1, |
|
| 5944 |
- Err: "invalid from flag value 0 refers current build block", |
|
| 5945 |
- }) |
|
| 5946 |
- |
|
| 5947 |
- dockerfile = ` |
|
| 5929 |
+ COPY --from=0 foo bar`, |
|
| 5930 |
+ expectedError: "invalid from flag value 0 refers current build block", |
|
| 5931 |
+ }, |
|
| 5932 |
+ {
|
|
| 5933 |
+ dockerfile: ` |
|
| 5948 | 5934 |
FROM busybox AS foo |
| 5949 |
- COPY --from=bar foo bar` |
|
| 5950 |
- |
|
| 5951 |
- ctx = fakeContext(c, dockerfile, map[string]string{
|
|
| 5952 |
- "Dockerfile": dockerfile, |
|
| 5953 |
- "foo": "abc", |
|
| 5954 |
- }) |
|
| 5955 |
- defer ctx.Close() |
|
| 5956 |
- |
|
| 5957 |
- buildImage("build1", withExternalBuildContext(ctx)).Assert(c, icmd.Expected{
|
|
| 5958 |
- ExitCode: 1, |
|
| 5959 |
- Err: "invalid from flag value bar", |
|
| 5960 |
- }) |
|
| 5961 |
- |
|
| 5962 |
- dockerfile = ` |
|
| 5935 |
+ COPY --from=bar foo bar`, |
|
| 5936 |
+ expectedError: "invalid from flag value bar", |
|
| 5937 |
+ }, |
|
| 5938 |
+ {
|
|
| 5939 |
+ dockerfile: ` |
|
| 5963 | 5940 |
FROM busybox AS 1 |
| 5964 |
- COPY --from=1 foo bar` |
|
| 5941 |
+ COPY --from=1 foo bar`, |
|
| 5942 |
+ expectedError: "invalid name for build stage", |
|
| 5943 |
+ }, |
|
| 5944 |
+ } |
|
| 5965 | 5945 |
|
| 5966 |
- ctx = fakeContext(c, dockerfile, map[string]string{
|
|
| 5967 |
- "Dockerfile": dockerfile, |
|
| 5968 |
- "foo": "abc", |
|
| 5969 |
- }) |
|
| 5970 |
- defer ctx.Close() |
|
| 5946 |
+ for _, tc := range testCases {
|
|
| 5947 |
+ ctx := fakecontext.New(c, "", |
|
| 5948 |
+ fakecontext.WithDockerfile(tc.dockerfile), |
|
| 5949 |
+ fakecontext.WithFiles(map[string]string{
|
|
| 5950 |
+ "foo": "abc", |
|
| 5951 |
+ })) |
|
| 5971 | 5952 |
|
| 5972 |
- buildImage("build1", withExternalBuildContext(ctx)).Assert(c, icmd.Expected{
|
|
| 5973 |
- ExitCode: 1, |
|
| 5974 |
- Err: "invalid name for build stage", |
|
| 5975 |
- }) |
|
| 5953 |
+ cli.Docker(cli.Build("build1"), build.WithExternalBuildContext(ctx)).Assert(c, icmd.Expected{
|
|
| 5954 |
+ ExitCode: 1, |
|
| 5955 |
+ Err: tc.expectedError, |
|
| 5956 |
+ }) |
|
| 5957 |
+ |
|
| 5958 |
+ ctx.Close() |
|
| 5959 |
+ } |
|
| 5976 | 5960 |
} |
| 5977 | 5961 |
|
| 5978 | 5962 |
func (s *DockerSuite) TestBuildCopyFromPreviousFrom(c *check.C) {
|
| 5979 | 5963 |
dockerfile := ` |
| 5980 | 5964 |
FROM busybox |
| 5981 | 5965 |
COPY foo bar` |
| 5982 |
- ctx := fakeContext(c, dockerfile, map[string]string{
|
|
| 5983 |
- "Dockerfile": dockerfile, |
|
| 5984 |
- "foo": "abc", |
|
| 5985 |
- }) |
|
| 5966 |
+ ctx := fakecontext.New(c, "", |
|
| 5967 |
+ fakecontext.WithDockerfile(dockerfile), |
|
| 5968 |
+ fakecontext.WithFiles(map[string]string{
|
|
| 5969 |
+ "foo": "abc", |
|
| 5970 |
+ })) |
|
| 5986 | 5971 |
defer ctx.Close() |
| 5987 | 5972 |
|
| 5988 |
- result := buildImage("build1", withExternalBuildContext(ctx))
|
|
| 5989 |
- result.Assert(c, icmd.Success) |
|
| 5973 |
+ cli.BuildCmd(c, "build1", build.WithExternalBuildContext(ctx)) |
|
| 5990 | 5974 |
|
| 5991 | 5975 |
dockerfile = ` |
| 5992 | 5976 |
FROM build1:latest AS foo |
| 5993 | 5977 |
FROM busybox |
| 5994 | 5978 |
COPY --from=foo bar / |
| 5995 | 5979 |
COPY foo /` |
| 5996 |
- ctx = fakeContext(c, dockerfile, map[string]string{
|
|
| 5997 |
- "Dockerfile": dockerfile, |
|
| 5998 |
- "foo": "def", |
|
| 5999 |
- }) |
|
| 5980 |
+ ctx = fakecontext.New(c, "", |
|
| 5981 |
+ fakecontext.WithDockerfile(dockerfile), |
|
| 5982 |
+ fakecontext.WithFiles(map[string]string{
|
|
| 5983 |
+ "foo": "def", |
|
| 5984 |
+ })) |
|
| 6000 | 5985 |
defer ctx.Close() |
| 6001 | 5986 |
|
| 6002 |
- result = buildImage("build2", withExternalBuildContext(ctx))
|
|
| 6003 |
- result.Assert(c, icmd.Success) |
|
| 5987 |
+ cli.BuildCmd(c, "build2", build.WithExternalBuildContext(ctx)) |
|
| 6004 | 5988 |
|
| 6005 |
- out, _ := dockerCmd(c, "run", "build2", "cat", "bar") |
|
| 5989 |
+ out := cli.DockerCmd(c, "run", "build2", "cat", "bar").Combined() |
|
| 6006 | 5990 |
c.Assert(strings.TrimSpace(out), check.Equals, "abc") |
| 6007 |
- out, _ = dockerCmd(c, "run", "build2", "cat", "foo") |
|
| 5991 |
+ out = cli.DockerCmd(c, "run", "build2", "cat", "foo").Combined() |
|
| 6008 | 5992 |
c.Assert(strings.TrimSpace(out), check.Equals, "def") |
| 6009 | 5993 |
} |
| 6010 | 5994 |
|
| ... | ... |
@@ -6020,18 +6004,17 @@ func (s *DockerSuite) TestBuildCopyFromImplicitFrom(c *check.C) {
|
| 6020 | 6020 |
COPY --from=busybox License.txt foo` |
| 6021 | 6021 |
} |
| 6022 | 6022 |
|
| 6023 |
- ctx := fakeContext(c, dockerfile, map[string]string{
|
|
| 6024 |
- "Dockerfile": dockerfile, |
|
| 6025 |
- }) |
|
| 6023 |
+ ctx := fakecontext.New(c, "", |
|
| 6024 |
+ fakecontext.WithDockerfile(dockerfile), |
|
| 6025 |
+ ) |
|
| 6026 | 6026 |
defer ctx.Close() |
| 6027 | 6027 |
|
| 6028 |
- result := buildImage("build1", withExternalBuildContext(ctx))
|
|
| 6029 |
- result.Assert(c, icmd.Success) |
|
| 6028 |
+ cli.BuildCmd(c, "build1", build.WithExternalBuildContext(ctx)) |
|
| 6030 | 6029 |
|
| 6031 | 6030 |
if DaemonIsWindows() {
|
| 6032 |
- out, _ := dockerCmd(c, "run", "build1", "cat", "License.txt") |
|
| 6031 |
+ out := cli.DockerCmd(c, "run", "build1", "cat", "License.txt").Combined() |
|
| 6033 | 6032 |
c.Assert(len(out), checker.GreaterThan, 10) |
| 6034 |
- out2, _ := dockerCmd(c, "run", "build1", "cat", "foo") |
|
| 6033 |
+ out2 := cli.DockerCmd(c, "run", "build1", "cat", "foo").Combined() |
|
| 6035 | 6034 |
c.Assert(out, check.Equals, out2) |
| 6036 | 6035 |
} |
| 6037 | 6036 |
} |
| ... | ... |
@@ -6042,31 +6025,28 @@ func (s *DockerRegistrySuite) TestBuildCopyFromImplicitPullingFrom(c *check.C) {
|
| 6042 | 6042 |
dockerfile := ` |
| 6043 | 6043 |
FROM busybox |
| 6044 | 6044 |
COPY foo bar` |
| 6045 |
- ctx := fakeContext(c, dockerfile, map[string]string{
|
|
| 6046 |
- "Dockerfile": dockerfile, |
|
| 6047 |
- "foo": "abc", |
|
| 6048 |
- }) |
|
| 6045 |
+ ctx := fakecontext.New(c, "", |
|
| 6046 |
+ fakecontext.WithDockerfile(dockerfile), |
|
| 6047 |
+ fakecontext.WithFiles(map[string]string{
|
|
| 6048 |
+ "foo": "abc", |
|
| 6049 |
+ })) |
|
| 6049 | 6050 |
defer ctx.Close() |
| 6050 | 6051 |
|
| 6051 |
- result := buildImage(repoName, withExternalBuildContext(ctx)) |
|
| 6052 |
- result.Assert(c, icmd.Success) |
|
| 6052 |
+ cli.BuildCmd(c, repoName, build.WithExternalBuildContext(ctx)) |
|
| 6053 | 6053 |
|
| 6054 |
- dockerCmd(c, "push", repoName) |
|
| 6055 |
- dockerCmd(c, "rmi", repoName) |
|
| 6054 |
+ cli.DockerCmd(c, "push", repoName) |
|
| 6055 |
+ cli.DockerCmd(c, "rmi", repoName) |
|
| 6056 | 6056 |
|
| 6057 | 6057 |
dockerfile = ` |
| 6058 | 6058 |
FROM busybox |
| 6059 | 6059 |
COPY --from=%s bar baz` |
| 6060 | 6060 |
|
| 6061 |
- ctx = fakeContext(c, fmt.Sprintf(dockerfile, repoName), map[string]string{
|
|
| 6062 |
- "Dockerfile": dockerfile, |
|
| 6063 |
- }) |
|
| 6061 |
+ ctx = fakecontext.New(c, "", fakecontext.WithDockerfile(fmt.Sprintf(dockerfile, repoName))) |
|
| 6064 | 6062 |
defer ctx.Close() |
| 6065 | 6063 |
|
| 6066 |
- result = buildImage("build1", withExternalBuildContext(ctx))
|
|
| 6067 |
- result.Assert(c, icmd.Success) |
|
| 6064 |
+ cli.BuildCmd(c, "build1", build.WithExternalBuildContext(ctx)) |
|
| 6068 | 6065 |
|
| 6069 |
- dockerCmdWithResult("run", "build1", "cat", "baz").Assert(c, icmd.Expected{Out: "abc"})
|
|
| 6066 |
+ cli.Docker(cli.Args("run", "build1", "cat", "baz")).Assert(c, icmd.Expected{Out: "abc"})
|
|
| 6070 | 6067 |
} |
| 6071 | 6068 |
|
| 6072 | 6069 |
func (s *DockerSuite) TestBuildFromPreviousBlock(c *check.C) {
|
| ... | ... |
@@ -6081,20 +6061,17 @@ func (s *DockerSuite) TestBuildFromPreviousBlock(c *check.C) {
|
| 6081 | 6081 |
COPY --from=foo1 foo f1 |
| 6082 | 6082 |
COPY --from=FOo2 foo f2 |
| 6083 | 6083 |
` // foo2 case also tests that names are canse insensitive |
| 6084 |
- ctx := fakeContext(c, dockerfile, map[string]string{
|
|
| 6085 |
- "Dockerfile": dockerfile, |
|
| 6086 |
- "foo": "bar", |
|
| 6087 |
- }) |
|
| 6084 |
+ ctx := fakecontext.New(c, "", |
|
| 6085 |
+ fakecontext.WithDockerfile(dockerfile), |
|
| 6086 |
+ fakecontext.WithFiles(map[string]string{
|
|
| 6087 |
+ "foo": "bar", |
|
| 6088 |
+ })) |
|
| 6088 | 6089 |
defer ctx.Close() |
| 6089 | 6090 |
|
| 6090 |
- result := buildImage("build1", withExternalBuildContext(ctx))
|
|
| 6091 |
- result.Assert(c, icmd.Success) |
|
| 6092 |
- |
|
| 6093 |
- dockerCmdWithResult("run", "build1", "cat", "foo").Assert(c, icmd.Expected{Out: "bar"})
|
|
| 6094 |
- |
|
| 6095 |
- dockerCmdWithResult("run", "build1", "cat", "f1").Assert(c, icmd.Expected{Out: "bar1"})
|
|
| 6096 |
- |
|
| 6097 |
- dockerCmdWithResult("run", "build1", "cat", "f2").Assert(c, icmd.Expected{Out: "bar2"})
|
|
| 6091 |
+ cli.BuildCmd(c, "build1", build.WithExternalBuildContext(ctx)) |
|
| 6092 |
+ cli.Docker(cli.Args("run", "build1", "cat", "foo")).Assert(c, icmd.Expected{Out: "bar"})
|
|
| 6093 |
+ cli.Docker(cli.Args("run", "build1", "cat", "f1")).Assert(c, icmd.Expected{Out: "bar1"})
|
|
| 6094 |
+ cli.Docker(cli.Args("run", "build1", "cat", "f2")).Assert(c, icmd.Expected{Out: "bar2"})
|
|
| 6098 | 6095 |
} |
| 6099 | 6096 |
|
| 6100 | 6097 |
func (s *DockerTrustSuite) TestCopyFromTrustedBuild(c *check.C) {
|
| ... | ... |
@@ -6124,32 +6101,32 @@ func (s *DockerSuite) TestBuildCopyFromPreviousFromWindows(c *check.C) {
|
| 6124 | 6124 |
dockerfile := ` |
| 6125 | 6125 |
FROM ` + testEnv.MinimalBaseImage() + ` |
| 6126 | 6126 |
COPY foo c:\\bar` |
| 6127 |
- ctx := fakeContext(c, dockerfile, map[string]string{
|
|
| 6128 |
- "Dockerfile": dockerfile, |
|
| 6129 |
- "foo": "abc", |
|
| 6130 |
- }) |
|
| 6127 |
+ ctx := fakecontext.New(c, "", |
|
| 6128 |
+ fakecontext.WithDockerfile(dockerfile), |
|
| 6129 |
+ fakecontext.WithFiles(map[string]string{
|
|
| 6130 |
+ "foo": "abc", |
|
| 6131 |
+ })) |
|
| 6131 | 6132 |
defer ctx.Close() |
| 6132 | 6133 |
|
| 6133 |
- result := buildImage("build1", withExternalBuildContext(ctx))
|
|
| 6134 |
- result.Assert(c, icmd.Success) |
|
| 6134 |
+ cli.BuildCmd(c, "build1", build.WithExternalBuildContext(ctx)) |
|
| 6135 | 6135 |
|
| 6136 | 6136 |
dockerfile = ` |
| 6137 | 6137 |
FROM build1:latest |
| 6138 | 6138 |
FROM ` + testEnv.MinimalBaseImage() + ` |
| 6139 | 6139 |
COPY --from=0 c:\\bar / |
| 6140 | 6140 |
COPY foo /` |
| 6141 |
- ctx = fakeContext(c, dockerfile, map[string]string{
|
|
| 6142 |
- "Dockerfile": dockerfile, |
|
| 6143 |
- "foo": "def", |
|
| 6144 |
- }) |
|
| 6141 |
+ ctx = fakecontext.New(c, "", |
|
| 6142 |
+ fakecontext.WithDockerfile(dockerfile), |
|
| 6143 |
+ fakecontext.WithFiles(map[string]string{
|
|
| 6144 |
+ "foo": "def", |
|
| 6145 |
+ })) |
|
| 6145 | 6146 |
defer ctx.Close() |
| 6146 | 6147 |
|
| 6147 |
- result = buildImage("build2", withExternalBuildContext(ctx))
|
|
| 6148 |
- result.Assert(c, icmd.Success) |
|
| 6148 |
+ cli.BuildCmd(c, "build2", build.WithExternalBuildContext(ctx)) |
|
| 6149 | 6149 |
|
| 6150 |
- out, _ := dockerCmd(c, "run", "build2", "cmd.exe", "/s", "/c", "type", "c:\\bar") |
|
| 6150 |
+ out := cli.DockerCmd(c, "run", "build2", "cmd.exe", "/s", "/c", "type", "c:\\bar").Combined() |
|
| 6151 | 6151 |
c.Assert(strings.TrimSpace(out), check.Equals, "abc") |
| 6152 |
- out, _ = dockerCmd(c, "run", "build2", "cmd.exe", "/s", "/c", "type", "c:\\foo") |
|
| 6152 |
+ out = cli.DockerCmd(c, "run", "build2", "cmd.exe", "/s", "/c", "type", "c:\\foo").Combined() |
|
| 6153 | 6153 |
c.Assert(strings.TrimSpace(out), check.Equals, "def") |
| 6154 | 6154 |
} |
| 6155 | 6155 |
|
| ... | ... |
@@ -6197,17 +6174,13 @@ func (s *DockerSuite) TestBuildCopyFromWindowsIsCaseInsensitive(c *check.C) {
|
| 6197 | 6197 |
COPY --from=0 c:\\fOo c:\\copied |
| 6198 | 6198 |
RUN type c:\\copied |
| 6199 | 6199 |
` |
| 6200 |
- ctx := fakeContext(c, dockerfile, map[string]string{
|
|
| 6201 |
- "Dockerfile": dockerfile, |
|
| 6202 |
- "foo": "hello world", |
|
| 6203 |
- }) |
|
| 6204 |
- defer ctx.Close() |
|
| 6205 |
- exp := icmd.Expected{
|
|
| 6200 |
+ cli.Docker(cli.Build("copyfrom-windows-insensitive"), build.WithBuildContext(c,
|
|
| 6201 |
+ build.WithFile("Dockerfile", dockerfile),
|
|
| 6202 |
+ build.WithFile("foo", "hello world"),
|
|
| 6203 |
+ )).Assert(c, icmd.Expected{
|
|
| 6206 | 6204 |
ExitCode: 0, |
| 6207 | 6205 |
Out: "hello world", |
| 6208 |
- } |
|
| 6209 |
- result := buildImage("copyfrom-windows-insensitive", withExternalBuildContext(ctx))
|
|
| 6210 |
- result.Assert(c, exp) |
|
| 6206 |
+ }) |
|
| 6211 | 6207 |
} |
| 6212 | 6208 |
|
| 6213 | 6209 |
func (s *DockerSuite) TestBuildIntermediateTarget(c *check.C) {
|
| ... | ... |
@@ -6217,19 +6190,17 @@ func (s *DockerSuite) TestBuildIntermediateTarget(c *check.C) {
|
| 6217 | 6217 |
FROM busybox |
| 6218 | 6218 |
CMD ["/dist"] |
| 6219 | 6219 |
` |
| 6220 |
- ctx := fakeContext(c, dockerfile, map[string]string{
|
|
| 6221 |
- "Dockerfile": dockerfile, |
|
| 6222 |
- }) |
|
| 6220 |
+ ctx := fakecontext.New(c, "", fakecontext.WithDockerfile(dockerfile)) |
|
| 6223 | 6221 |
defer ctx.Close() |
| 6224 | 6222 |
|
| 6225 |
- result := buildImage("build1", withExternalBuildContext(ctx),
|
|
| 6223 |
+ cli.BuildCmd(c, "build1", build.WithExternalBuildContext(ctx), |
|
| 6226 | 6224 |
cli.WithFlags("--target", "build-env"))
|
| 6227 |
- result.Assert(c, icmd.Success) |
|
| 6228 | 6225 |
|
| 6229 |
- res := inspectFieldJSON(c, "build1", "Config.Cmd") |
|
| 6230 |
- c.Assert(res, checker.Equals, `["/dev"]`) |
|
| 6226 |
+ //res := inspectFieldJSON(c, "build1", "Config.Cmd") |
|
| 6227 |
+ res := cli.InspectCmd(c, "build1", cli.Format("json .Config.Cmd")).Combined()
|
|
| 6228 |
+ c.Assert(strings.TrimSpace(res), checker.Equals, `["/dev"]`) |
|
| 6231 | 6229 |
|
| 6232 |
- result = buildImage("build1", withExternalBuildContext(ctx),
|
|
| 6230 |
+ result := cli.Docker(cli.Build("build1"), build.WithExternalBuildContext(ctx),
|
|
| 6233 | 6231 |
cli.WithFlags("--target", "nosuchtarget"))
|
| 6234 | 6232 |
result.Assert(c, icmd.Expected{
|
| 6235 | 6233 |
ExitCode: 1, |
| ... | ... |
@@ -6274,13 +6245,13 @@ func (s *DockerSuite) TestBuildWindowsUser(c *check.C) {
|
| 6274 | 6274 |
// Note 27545 was reverted in 28505, but a new fix was added subsequently in 28514. |
| 6275 | 6275 |
func (s *DockerSuite) TestBuildCopyFileDotWithWorkdir(c *check.C) {
|
| 6276 | 6276 |
name := "testbuildcopyfiledotwithworkdir" |
| 6277 |
- buildImageSuccessfully(c, name, withBuildContext(c, |
|
| 6278 |
- withFile("Dockerfile", `FROM busybox
|
|
| 6277 |
+ buildImageSuccessfully(c, name, build.WithBuildContext(c, |
|
| 6278 |
+ build.WithFile("Dockerfile", `FROM busybox
|
|
| 6279 | 6279 |
WORKDIR /foo |
| 6280 | 6280 |
COPY file . |
| 6281 | 6281 |
RUN ["cat", "/foo/file"] |
| 6282 | 6282 |
`), |
| 6283 |
- withFile("file", "content"),
|
|
| 6283 |
+ build.WithFile("file", "content"),
|
|
| 6284 | 6284 |
)) |
| 6285 | 6285 |
} |
| 6286 | 6286 |
|
| ... | ... |
@@ -16,6 +16,8 @@ import ( |
| 16 | 16 |
|
| 17 | 17 |
"github.com/docker/docker/integration-cli/checker" |
| 18 | 18 |
"github.com/docker/docker/integration-cli/cli" |
| 19 |
+ "github.com/docker/docker/integration-cli/cli/build" |
|
| 20 |
+ "github.com/docker/docker/integration-cli/cli/build/fakecontext" |
|
| 19 | 21 |
"github.com/docker/docker/pkg/testutil" |
| 20 | 22 |
icmd "github.com/docker/docker/pkg/testutil/cmd" |
| 21 | 23 |
"github.com/docker/go-units" |
| ... | ... |
@@ -26,10 +28,10 @@ func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) {
|
| 26 | 26 |
testRequires(c, cpuCfsQuota) |
| 27 | 27 |
name := "testbuildresourceconstraints" |
| 28 | 28 |
|
| 29 |
- ctx := fakeContext(c, ` |
|
| 29 |
+ ctx := fakecontext.New(c, "", fakecontext.WithDockerfile(` |
|
| 30 | 30 |
FROM hello-world:frozen |
| 31 | 31 |
RUN ["/hello"] |
| 32 |
- `, map[string]string{})
|
|
| 32 |
+ `)) |
|
| 33 | 33 |
cli.Docker( |
| 34 | 34 |
cli.Args("build", "--no-cache", "--rm=false", "--memory=64m", "--memory-swap=-1", "--cpuset-cpus=0", "--cpuset-mems=0", "--cpu-shares=100", "--cpu-quota=8000", "--ulimit", "nofile=42", "-t", name, "."),
|
| 35 | 35 |
cli.InDir(ctx.Dir), |
| ... | ... |
@@ -85,7 +87,7 @@ func (s *DockerSuite) TestBuildAddChangeOwnership(c *check.C) {
|
| 85 | 85 |
testRequires(c, DaemonIsLinux) |
| 86 | 86 |
name := "testbuildaddown" |
| 87 | 87 |
|
| 88 |
- ctx := func() *FakeContext {
|
|
| 88 |
+ ctx := func() *fakecontext.Fake {
|
|
| 89 | 89 |
dockerfile := ` |
| 90 | 90 |
FROM busybox |
| 91 | 91 |
ADD foo /bar/ |
| ... | ... |
@@ -108,12 +110,12 @@ func (s *DockerSuite) TestBuildAddChangeOwnership(c *check.C) {
|
| 108 | 108 |
if err := ioutil.WriteFile(filepath.Join(tmpDir, "Dockerfile"), []byte(dockerfile), 0644); err != nil {
|
| 109 | 109 |
c.Fatalf("failed to open destination dockerfile: %v", err)
|
| 110 | 110 |
} |
| 111 |
- return fakeContextFromDir(tmpDir) |
|
| 111 |
+ return fakecontext.New(c, tmpDir) |
|
| 112 | 112 |
}() |
| 113 | 113 |
|
| 114 | 114 |
defer ctx.Close() |
| 115 | 115 |
|
| 116 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 116 |
+ buildImageSuccessfully(c, name, build.WithExternalBuildContext(ctx)) |
|
| 117 | 117 |
} |
| 118 | 118 |
|
| 119 | 119 |
// Test that an infinite sleep during a build is killed if the client disconnects. |
| ... | ... |
@@ -134,7 +136,7 @@ func (s *DockerSuite) TestBuildCancellationKillsSleep(c *check.C) {
|
| 134 | 134 |
defer observer.Stop() |
| 135 | 135 |
|
| 136 | 136 |
// (Note: one year, will never finish) |
| 137 |
- ctx := fakeContext(c, "FROM busybox\nRUN sleep 31536000", nil) |
|
| 137 |
+ ctx := fakecontext.New(c, "", fakecontext.WithDockerfile("FROM busybox\nRUN sleep 31536000"))
|
|
| 138 | 138 |
defer ctx.Close() |
| 139 | 139 |
|
| 140 | 140 |
buildCmd := exec.Command(dockerBinary, "build", "-t", name, ".") |
| ... | ... |
@@ -10,7 +10,9 @@ import ( |
| 10 | 10 |
"time" |
| 11 | 11 |
|
| 12 | 12 |
"github.com/docker/docker/integration-cli/checker" |
| 13 |
+ "github.com/docker/docker/integration-cli/cli" |
|
| 13 | 14 |
"github.com/docker/docker/integration-cli/cli/build" |
| 15 |
+ "github.com/docker/docker/integration-cli/cli/build/fakecontext" |
|
| 14 | 16 |
"github.com/docker/docker/pkg/stringid" |
| 15 | 17 |
"github.com/docker/docker/pkg/testutil" |
| 16 | 18 |
icmd "github.com/docker/docker/pkg/testutil/cmd" |
| ... | ... |
@@ -438,19 +440,21 @@ RUN chmod 755 /entrypoint.sh |
| 438 | 438 |
ENTRYPOINT ["/entrypoint.sh"] |
| 439 | 439 |
CMD echo foobar` |
| 440 | 440 |
|
| 441 |
- ctx := fakeContext(c, dockerfile, map[string]string{
|
|
| 442 |
- "entrypoint.sh": `#!/bin/sh |
|
| 441 |
+ ctx := fakecontext.New(c, "", |
|
| 442 |
+ fakecontext.WithDockerfile(dockerfile), |
|
| 443 |
+ fakecontext.WithFiles(map[string]string{
|
|
| 444 |
+ "entrypoint.sh": `#!/bin/sh |
|
| 443 | 445 |
echo "I am an entrypoint" |
| 444 | 446 |
exec "$@"`, |
| 445 |
- }) |
|
| 447 |
+ })) |
|
| 446 | 448 |
defer ctx.Close() |
| 447 | 449 |
|
| 448 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 450 |
+ cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) |
|
| 449 | 451 |
|
| 450 |
- out, _ := dockerCmd(c, "create", "--entrypoint=", name, "echo", "foo") |
|
| 452 |
+ out := cli.DockerCmd(c, "create", "--entrypoint=", name, "echo", "foo").Combined() |
|
| 451 | 453 |
id := strings.TrimSpace(out) |
| 452 | 454 |
c.Assert(id, check.Not(check.Equals), "") |
| 453 |
- out, _ = dockerCmd(c, "start", "-a", id) |
|
| 455 |
+ out = cli.DockerCmd(c, "start", "-a", id).Combined() |
|
| 454 | 456 |
c.Assert(strings.TrimSpace(out), check.Equals, "foo") |
| 455 | 457 |
} |
| 456 | 458 |
|
| ... | ... |
@@ -24,6 +24,7 @@ import ( |
| 24 | 24 |
"github.com/docker/docker/integration-cli/checker" |
| 25 | 25 |
"github.com/docker/docker/integration-cli/cli" |
| 26 | 26 |
"github.com/docker/docker/integration-cli/cli/build" |
| 27 |
+ "github.com/docker/docker/integration-cli/cli/build/fakecontext" |
|
| 27 | 28 |
"github.com/docker/docker/pkg/mount" |
| 28 | 29 |
"github.com/docker/docker/pkg/stringid" |
| 29 | 30 |
"github.com/docker/docker/pkg/stringutils" |
| ... | ... |
@@ -4174,22 +4175,25 @@ RUN chmod 755 /entrypoint.sh |
| 4174 | 4174 |
ENTRYPOINT ["/entrypoint.sh"] |
| 4175 | 4175 |
CMD echo foobar` |
| 4176 | 4176 |
|
| 4177 |
- ctx := fakeContext(c, dockerfile, map[string]string{
|
|
| 4178 |
- "entrypoint.sh": `#!/bin/sh |
|
| 4177 |
+ ctx := fakecontext.New(c, "", |
|
| 4178 |
+ fakecontext.WithDockerfile(dockerfile), |
|
| 4179 |
+ fakecontext.WithFiles(map[string]string{
|
|
| 4180 |
+ "entrypoint.sh": `#!/bin/sh |
|
| 4179 | 4181 |
echo "I am an entrypoint" |
| 4180 | 4182 |
exec "$@"`, |
| 4181 |
- }) |
|
| 4183 |
+ })) |
|
| 4182 | 4184 |
defer ctx.Close() |
| 4183 | 4185 |
|
| 4184 |
- buildImageSuccessfully(c, name, withExternalBuildContext(ctx)) |
|
| 4186 |
+ cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx)) |
|
| 4185 | 4187 |
|
| 4186 |
- out, _ := dockerCmd(c, "run", "--entrypoint=", "-t", name, "echo", "foo") |
|
| 4188 |
+ out := cli.DockerCmd(c, "run", "--entrypoint=", "-t", name, "echo", "foo").Combined() |
|
| 4187 | 4189 |
c.Assert(strings.TrimSpace(out), check.Equals, "foo") |
| 4188 | 4190 |
|
| 4189 | 4191 |
// CMD will be reset as well (the same as setting a custom entrypoint) |
| 4190 |
- _, _, err := dockerCmdWithError("run", "--entrypoint=", "-t", name)
|
|
| 4191 |
- c.Assert(err, check.NotNil) |
|
| 4192 |
- c.Assert(err.Error(), checker.Contains, "No command specified") |
|
| 4192 |
+ cli.Docker(cli.Args("run", "--entrypoint=", "-t", name)).Assert(c, icmd.Expected{
|
|
| 4193 |
+ ExitCode: 125, |
|
| 4194 |
+ Err: "No command specified", |
|
| 4195 |
+ }) |
|
| 4193 | 4196 |
} |
| 4194 | 4197 |
|
| 4195 | 4198 |
func (s *DockerDaemonSuite) TestRunWithUlimitAndDaemonDefault(c *check.C) {
|
| ... | ... |
@@ -1,16 +1,13 @@ |
| 1 | 1 |
package main |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "bytes" |
|
| 5 | 4 |
"encoding/json" |
| 6 | 5 |
"errors" |
| 7 | 6 |
"fmt" |
| 8 | 7 |
"io" |
| 9 | 8 |
"io/ioutil" |
| 10 |
- "net" |
|
| 11 | 9 |
"net/http" |
| 12 | 10 |
"net/http/httptest" |
| 13 |
- "net/url" |
|
| 14 | 11 |
"os" |
| 15 | 12 |
"os/exec" |
| 16 | 13 |
"path" |
| ... | ... |
@@ -22,11 +19,11 @@ import ( |
| 22 | 22 |
"github.com/docker/docker/api/types" |
| 23 | 23 |
"github.com/docker/docker/integration-cli/checker" |
| 24 | 24 |
"github.com/docker/docker/integration-cli/cli" |
| 25 |
- "github.com/docker/docker/integration-cli/cli/build" |
|
| 25 |
+ "github.com/docker/docker/integration-cli/cli/build/fakecontext" |
|
| 26 |
+ "github.com/docker/docker/integration-cli/cli/build/fakestorage" |
|
| 26 | 27 |
"github.com/docker/docker/integration-cli/daemon" |
| 27 | 28 |
"github.com/docker/docker/integration-cli/registry" |
| 28 | 29 |
"github.com/docker/docker/integration-cli/request" |
| 29 |
- "github.com/docker/docker/pkg/stringutils" |
|
| 30 | 30 |
icmd "github.com/docker/docker/pkg/testutil/cmd" |
| 31 | 31 |
"github.com/go-check/check" |
| 32 | 32 |
) |
| ... | ... |
@@ -124,212 +121,6 @@ func getContainerCount(c *check.C) int {
|
| 124 | 124 |
return 0 |
| 125 | 125 |
} |
| 126 | 126 |
|
| 127 |
-// FakeContext creates directories that can be used as a build context |
|
| 128 |
-type FakeContext struct {
|
|
| 129 |
- Dir string |
|
| 130 |
-} |
|
| 131 |
- |
|
| 132 |
-// Add a file at a path, creating directories where necessary |
|
| 133 |
-func (f *FakeContext) Add(file, content string) error {
|
|
| 134 |
- return f.addFile(file, []byte(content)) |
|
| 135 |
-} |
|
| 136 |
- |
|
| 137 |
-func (f *FakeContext) addFile(file string, content []byte) error {
|
|
| 138 |
- fp := filepath.Join(f.Dir, filepath.FromSlash(file)) |
|
| 139 |
- dirpath := filepath.Dir(fp) |
|
| 140 |
- if dirpath != "." {
|
|
| 141 |
- if err := os.MkdirAll(dirpath, 0755); err != nil {
|
|
| 142 |
- return err |
|
| 143 |
- } |
|
| 144 |
- } |
|
| 145 |
- return ioutil.WriteFile(fp, content, 0644) |
|
| 146 |
- |
|
| 147 |
-} |
|
| 148 |
- |
|
| 149 |
-// Delete a file at a path |
|
| 150 |
-func (f *FakeContext) Delete(file string) error {
|
|
| 151 |
- fp := filepath.Join(f.Dir, filepath.FromSlash(file)) |
|
| 152 |
- return os.RemoveAll(fp) |
|
| 153 |
-} |
|
| 154 |
- |
|
| 155 |
-// Close deletes the context |
|
| 156 |
-func (f *FakeContext) Close() error {
|
|
| 157 |
- return os.RemoveAll(f.Dir) |
|
| 158 |
-} |
|
| 159 |
- |
|
| 160 |
-func fakeContextFromNewTempDir(c *check.C) *FakeContext {
|
|
| 161 |
- tmp, err := ioutil.TempDir("", "fake-context")
|
|
| 162 |
- c.Assert(err, checker.IsNil) |
|
| 163 |
- if err := os.Chmod(tmp, 0755); err != nil {
|
|
| 164 |
- c.Fatal(err) |
|
| 165 |
- } |
|
| 166 |
- return fakeContextFromDir(tmp) |
|
| 167 |
-} |
|
| 168 |
- |
|
| 169 |
-func fakeContextFromDir(dir string) *FakeContext {
|
|
| 170 |
- return &FakeContext{dir}
|
|
| 171 |
-} |
|
| 172 |
- |
|
| 173 |
-func fakeContextWithFiles(c *check.C, files map[string]string) *FakeContext {
|
|
| 174 |
- ctx := fakeContextFromNewTempDir(c) |
|
| 175 |
- for file, content := range files {
|
|
| 176 |
- if err := ctx.Add(file, content); err != nil {
|
|
| 177 |
- ctx.Close() |
|
| 178 |
- c.Fatal(err) |
|
| 179 |
- } |
|
| 180 |
- } |
|
| 181 |
- return ctx |
|
| 182 |
-} |
|
| 183 |
- |
|
| 184 |
-func fakeContextAddDockerfile(c *check.C, ctx *FakeContext, dockerfile string) {
|
|
| 185 |
- if err := ctx.Add("Dockerfile", dockerfile); err != nil {
|
|
| 186 |
- ctx.Close() |
|
| 187 |
- c.Fatal(err) |
|
| 188 |
- } |
|
| 189 |
-} |
|
| 190 |
- |
|
| 191 |
-func fakeContext(c *check.C, dockerfile string, files map[string]string) *FakeContext {
|
|
| 192 |
- ctx := fakeContextWithFiles(c, files) |
|
| 193 |
- fakeContextAddDockerfile(c, ctx, dockerfile) |
|
| 194 |
- return ctx |
|
| 195 |
-} |
|
| 196 |
- |
|
| 197 |
-// FakeStorage is a static file server. It might be running locally or remotely |
|
| 198 |
-// on test host. |
|
| 199 |
-type FakeStorage interface {
|
|
| 200 |
- Close() error |
|
| 201 |
- URL() string |
|
| 202 |
- CtxDir() string |
|
| 203 |
-} |
|
| 204 |
- |
|
| 205 |
-func fakeBinaryStorage(c *check.C, archives map[string]*bytes.Buffer) FakeStorage {
|
|
| 206 |
- ctx := fakeContextFromNewTempDir(c) |
|
| 207 |
- for name, content := range archives {
|
|
| 208 |
- if err := ctx.addFile(name, content.Bytes()); err != nil {
|
|
| 209 |
- c.Fatal(err) |
|
| 210 |
- } |
|
| 211 |
- } |
|
| 212 |
- return fakeStorageWithContext(c, ctx) |
|
| 213 |
-} |
|
| 214 |
- |
|
| 215 |
-// fakeStorage returns either a local or remote (at daemon machine) file server |
|
| 216 |
-func fakeStorage(c *check.C, files map[string]string) FakeStorage {
|
|
| 217 |
- ctx := fakeContextWithFiles(c, files) |
|
| 218 |
- return fakeStorageWithContext(c, ctx) |
|
| 219 |
-} |
|
| 220 |
- |
|
| 221 |
-// fakeStorageWithContext returns either a local or remote (at daemon machine) file server |
|
| 222 |
-func fakeStorageWithContext(c *check.C, ctx *FakeContext) FakeStorage {
|
|
| 223 |
- if testEnv.LocalDaemon() {
|
|
| 224 |
- return newLocalFakeStorage(c, ctx) |
|
| 225 |
- } |
|
| 226 |
- return newRemoteFileServer(c, ctx) |
|
| 227 |
-} |
|
| 228 |
- |
|
| 229 |
-// localFileStorage is a file storage on the running machine |
|
| 230 |
-type localFileStorage struct {
|
|
| 231 |
- *FakeContext |
|
| 232 |
- *httptest.Server |
|
| 233 |
-} |
|
| 234 |
- |
|
| 235 |
-func (s *localFileStorage) URL() string {
|
|
| 236 |
- return s.Server.URL |
|
| 237 |
-} |
|
| 238 |
- |
|
| 239 |
-func (s *localFileStorage) CtxDir() string {
|
|
| 240 |
- return s.FakeContext.Dir |
|
| 241 |
-} |
|
| 242 |
- |
|
| 243 |
-func (s *localFileStorage) Close() error {
|
|
| 244 |
- defer s.Server.Close() |
|
| 245 |
- return s.FakeContext.Close() |
|
| 246 |
-} |
|
| 247 |
- |
|
| 248 |
-func newLocalFakeStorage(c *check.C, ctx *FakeContext) *localFileStorage {
|
|
| 249 |
- handler := http.FileServer(http.Dir(ctx.Dir)) |
|
| 250 |
- server := httptest.NewServer(handler) |
|
| 251 |
- return &localFileStorage{
|
|
| 252 |
- FakeContext: ctx, |
|
| 253 |
- Server: server, |
|
| 254 |
- } |
|
| 255 |
-} |
|
| 256 |
- |
|
| 257 |
-// remoteFileServer is a containerized static file server started on the remote |
|
| 258 |
-// testing machine to be used in URL-accepting docker build functionality. |
|
| 259 |
-type remoteFileServer struct {
|
|
| 260 |
- host string // hostname/port web server is listening to on docker host e.g. 0.0.0.0:43712 |
|
| 261 |
- container string |
|
| 262 |
- image string |
|
| 263 |
- ctx *FakeContext |
|
| 264 |
-} |
|
| 265 |
- |
|
| 266 |
-func (f *remoteFileServer) URL() string {
|
|
| 267 |
- u := url.URL{
|
|
| 268 |
- Scheme: "http", |
|
| 269 |
- Host: f.host} |
|
| 270 |
- return u.String() |
|
| 271 |
-} |
|
| 272 |
- |
|
| 273 |
-func (f *remoteFileServer) CtxDir() string {
|
|
| 274 |
- return f.ctx.Dir |
|
| 275 |
-} |
|
| 276 |
- |
|
| 277 |
-func (f *remoteFileServer) Close() error {
|
|
| 278 |
- defer func() {
|
|
| 279 |
- if f.ctx != nil {
|
|
| 280 |
- f.ctx.Close() |
|
| 281 |
- } |
|
| 282 |
- if f.image != "" {
|
|
| 283 |
- deleteImages(f.image) |
|
| 284 |
- } |
|
| 285 |
- }() |
|
| 286 |
- if f.container == "" {
|
|
| 287 |
- return nil |
|
| 288 |
- } |
|
| 289 |
- return deleteContainer(f.container) |
|
| 290 |
-} |
|
| 291 |
- |
|
| 292 |
-func newRemoteFileServer(c *check.C, ctx *FakeContext) *remoteFileServer {
|
|
| 293 |
- var ( |
|
| 294 |
- image = fmt.Sprintf("fileserver-img-%s", strings.ToLower(stringutils.GenerateRandomAlphaOnlyString(10)))
|
|
| 295 |
- container = fmt.Sprintf("fileserver-cnt-%s", strings.ToLower(stringutils.GenerateRandomAlphaOnlyString(10)))
|
|
| 296 |
- ) |
|
| 297 |
- |
|
| 298 |
- ensureHTTPServerImage(c) |
|
| 299 |
- |
|
| 300 |
- // Build the image |
|
| 301 |
- fakeContextAddDockerfile(c, ctx, `FROM httpserver |
|
| 302 |
-COPY . /static`) |
|
| 303 |
- buildImageSuccessfully(c, image, build.WithoutCache, withExternalBuildContext(ctx)) |
|
| 304 |
- |
|
| 305 |
- // Start the container |
|
| 306 |
- dockerCmd(c, "run", "-d", "-P", "--name", container, image) |
|
| 307 |
- |
|
| 308 |
- // Find out the system assigned port |
|
| 309 |
- out, _ := dockerCmd(c, "port", container, "80/tcp") |
|
| 310 |
- fileserverHostPort := strings.Trim(out, "\n") |
|
| 311 |
- _, port, err := net.SplitHostPort(fileserverHostPort) |
|
| 312 |
- if err != nil {
|
|
| 313 |
- c.Fatalf("unable to parse file server host:port: %v", err)
|
|
| 314 |
- } |
|
| 315 |
- |
|
| 316 |
- dockerHostURL, err := url.Parse(daemonHost()) |
|
| 317 |
- if err != nil {
|
|
| 318 |
- c.Fatalf("unable to parse daemon host URL: %v", err)
|
|
| 319 |
- } |
|
| 320 |
- |
|
| 321 |
- host, _, err := net.SplitHostPort(dockerHostURL.Host) |
|
| 322 |
- if err != nil {
|
|
| 323 |
- c.Fatalf("unable to parse docker daemon host:port: %v", err)
|
|
| 324 |
- } |
|
| 325 |
- |
|
| 326 |
- return &remoteFileServer{
|
|
| 327 |
- container: container, |
|
| 328 |
- image: image, |
|
| 329 |
- host: fmt.Sprintf("%s:%s", host, port),
|
|
| 330 |
- ctx: ctx} |
|
| 331 |
-} |
|
| 332 |
- |
|
| 333 | 127 |
func inspectFieldAndUnmarshall(c *check.C, name, field string, output interface{}) {
|
| 334 | 128 |
str := inspectFieldJSON(c, name, field) |
| 335 | 129 |
err := json.Unmarshal([]byte(str), output) |
| ... | ... |
@@ -452,42 +243,7 @@ func buildImage(name string, cmdOperators ...cli.CmdOperator) *icmd.Result {
|
| 452 | 452 |
return cli.Docker(cli.Build(name), cmdOperators...) |
| 453 | 453 |
} |
| 454 | 454 |
|
| 455 |
-func withExternalBuildContext(ctx *FakeContext) func(*icmd.Cmd) func() {
|
|
| 456 |
- return func(cmd *icmd.Cmd) func() {
|
|
| 457 |
- cmd.Dir = ctx.Dir |
|
| 458 |
- cmd.Command = append(cmd.Command, ".") |
|
| 459 |
- return nil |
|
| 460 |
- } |
|
| 461 |
-} |
|
| 462 |
- |
|
| 463 |
-func withBuildContext(c *check.C, contextOperators ...func(*FakeContext) error) func(*icmd.Cmd) func() {
|
|
| 464 |
- ctx := fakeContextFromNewTempDir(c) |
|
| 465 |
- for _, op := range contextOperators {
|
|
| 466 |
- if err := op(ctx); err != nil {
|
|
| 467 |
- c.Fatal(err) |
|
| 468 |
- } |
|
| 469 |
- } |
|
| 470 |
- return func(cmd *icmd.Cmd) func() {
|
|
| 471 |
- cmd.Dir = ctx.Dir |
|
| 472 |
- cmd.Command = append(cmd.Command, ".") |
|
| 473 |
- return closeBuildContext(c, ctx) |
|
| 474 |
- } |
|
| 475 |
-} |
|
| 476 |
- |
|
| 477 |
-func withFile(name, content string) func(*FakeContext) error {
|
|
| 478 |
- return func(ctx *FakeContext) error {
|
|
| 479 |
- return ctx.Add(name, content) |
|
| 480 |
- } |
|
| 481 |
-} |
|
| 482 |
- |
|
| 483 |
-func closeBuildContext(c *check.C, ctx *FakeContext) func() {
|
|
| 484 |
- return func() {
|
|
| 485 |
- if err := ctx.Close(); err != nil {
|
|
| 486 |
- c.Fatal(err) |
|
| 487 |
- } |
|
| 488 |
- } |
|
| 489 |
-} |
|
| 490 |
- |
|
| 455 |
+// Deprecated: use trustedcmd |
|
| 491 | 456 |
func trustedBuild(cmd *icmd.Cmd) func() {
|
| 492 | 457 |
trustedCmd(cmd) |
| 493 | 458 |
return nil |
| ... | ... |
@@ -523,7 +279,7 @@ func (g *fakeGit) Close() {
|
| 523 | 523 |
} |
| 524 | 524 |
|
| 525 | 525 |
func newFakeGit(c *check.C, name string, files map[string]string, enforceLocalServer bool) *fakeGit {
|
| 526 |
- ctx := fakeContextWithFiles(c, files) |
|
| 526 |
+ ctx := fakecontext.New(c, "", fakecontext.WithFiles(files)) |
|
| 527 | 527 |
defer ctx.Close() |
| 528 | 528 |
curdir, err := os.Getwd() |
| 529 | 529 |
if err != nil {
|
| ... | ... |
@@ -578,7 +334,7 @@ func newFakeGit(c *check.C, name string, files map[string]string, enforceLocalSe |
| 578 | 578 |
var server gitServer |
| 579 | 579 |
if !enforceLocalServer {
|
| 580 | 580 |
// use fakeStorage server, which might be local or remote (at test daemon) |
| 581 |
- server = fakeStorageWithContext(c, fakeContextFromDir(root)) |
|
| 581 |
+ server = fakestorage.New(c, root) |
|
| 582 | 582 |
} else {
|
| 583 | 583 |
// always start a local http server on CLI test machine |
| 584 | 584 |
httpServer := httptest.NewServer(http.FileServer(http.Dir(root))) |
| 585 | 585 |
deleted file mode 100644 |
| ... | ... |
@@ -1,67 +0,0 @@ |
| 1 |
-package main |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "io/ioutil" |
|
| 5 |
- "os" |
|
| 6 |
- "os/exec" |
|
| 7 |
- "path/filepath" |
|
| 8 |
- "sync" |
|
| 9 |
-) |
|
| 10 |
- |
|
| 11 |
-var ensureHTTPServerOnce sync.Once |
|
| 12 |
- |
|
| 13 |
-func ensureHTTPServerImage(t testingT) {
|
|
| 14 |
- var doIt bool |
|
| 15 |
- ensureHTTPServerOnce.Do(func() {
|
|
| 16 |
- doIt = true |
|
| 17 |
- }) |
|
| 18 |
- |
|
| 19 |
- if !doIt {
|
|
| 20 |
- return |
|
| 21 |
- } |
|
| 22 |
- |
|
| 23 |
- defer testEnv.ProtectImage(t, "httpserver:latest") |
|
| 24 |
- |
|
| 25 |
- tmp, err := ioutil.TempDir("", "docker-http-server-test")
|
|
| 26 |
- if err != nil {
|
|
| 27 |
- t.Fatalf("could not build http server: %v", err)
|
|
| 28 |
- } |
|
| 29 |
- defer os.RemoveAll(tmp) |
|
| 30 |
- |
|
| 31 |
- goos := testEnv.DaemonPlatform() |
|
| 32 |
- if goos == "" {
|
|
| 33 |
- goos = "linux" |
|
| 34 |
- } |
|
| 35 |
- goarch := os.Getenv("DOCKER_ENGINE_GOARCH")
|
|
| 36 |
- if goarch == "" {
|
|
| 37 |
- goarch = "amd64" |
|
| 38 |
- } |
|
| 39 |
- |
|
| 40 |
- goCmd, lookErr := exec.LookPath("go")
|
|
| 41 |
- if lookErr != nil {
|
|
| 42 |
- t.Fatalf("could not build http server: %v", lookErr)
|
|
| 43 |
- } |
|
| 44 |
- |
|
| 45 |
- cmd := exec.Command(goCmd, "build", "-o", filepath.Join(tmp, "httpserver"), "github.com/docker/docker/contrib/httpserver") |
|
| 46 |
- cmd.Env = append(os.Environ(), []string{
|
|
| 47 |
- "CGO_ENABLED=0", |
|
| 48 |
- "GOOS=" + goos, |
|
| 49 |
- "GOARCH=" + goarch, |
|
| 50 |
- }...) |
|
| 51 |
- var out []byte |
|
| 52 |
- if out, err = cmd.CombinedOutput(); err != nil {
|
|
| 53 |
- t.Fatalf("could not build http server: %s", string(out))
|
|
| 54 |
- } |
|
| 55 |
- |
|
| 56 |
- cpCmd, lookErr := exec.LookPath("cp")
|
|
| 57 |
- if lookErr != nil {
|
|
| 58 |
- t.Fatalf("could not build http server: %v", lookErr)
|
|
| 59 |
- } |
|
| 60 |
- if out, err = exec.Command(cpCmd, "../contrib/httpserver/Dockerfile", filepath.Join(tmp, "Dockerfile")).CombinedOutput(); err != nil {
|
|
| 61 |
- t.Fatalf("could not build http server: %v", string(out))
|
|
| 62 |
- } |
|
| 63 |
- |
|
| 64 |
- if out, err = exec.Command(dockerBinary, "build", "-q", "-t", "httpserver", tmp).CombinedOutput(); err != nil {
|
|
| 65 |
- t.Fatalf("could not build http server: %v", string(out))
|
|
| 66 |
- } |
|
| 67 |
-} |
| ... | ... |
@@ -190,12 +190,6 @@ func (t *testNotary) Close() {
|
| 190 | 190 |
os.RemoveAll(t.dir) |
| 191 | 191 |
} |
| 192 | 192 |
|
| 193 |
-// Deprecated: used trustedCmd instead |
|
| 194 |
-func trustedExecCmd(cmd *exec.Cmd) {
|
|
| 195 |
- pwd := "12345678" |
|
| 196 |
- cmd.Env = append(cmd.Env, trustEnv(notaryURL, pwd, pwd)...) |
|
| 197 |
-} |
|
| 198 |
- |
|
| 199 | 193 |
func trustedCmd(cmd *icmd.Cmd) {
|
| 200 | 194 |
pwd := "12345678" |
| 201 | 195 |
cmd.Env = append(cmd.Env, trustEnv(notaryURL, pwd, pwd)...) |