1
0
mirror of https://github.com/moby/moby.git synced 2025-07-30 18:23:29 +03:00

Support dockerfile and Dockerfile

Closes #10807

Adds support for `dockerfile` ONLY when `Dockerfile` can't be found.
If we're building from a Dockerfile via stdin/URL then always download
it a `Dockerfile` and ignore the -f flag.

Signed-off-by: Doug Davis <dug@us.ibm.com>
This commit is contained in:
Doug Davis
2015-02-17 10:25:36 -08:00
parent a61716e5d9
commit 15924f2385
7 changed files with 282 additions and 25 deletions

View File

@ -353,6 +353,106 @@ func TestBuildApiDockerfilePath(t *testing.T) {
logDone("container REST API - check build w/bad Dockerfile path")
}
func TestBuildApiDockerFileRemote(t *testing.T) {
server, err := fakeStorage(map[string]string{
"testD": `FROM busybox
COPY * /tmp/
RUN find /tmp/`,
})
if err != nil {
t.Fatal(err)
}
defer server.Close()
buf, err := sockRequestRaw("POST", "/build?dockerfile=baz&remote="+server.URL+"/testD", nil, "application/json")
if err != nil {
t.Fatalf("Build failed: %s", err)
}
out := string(buf)
if !strings.Contains(out, "/tmp/Dockerfile") ||
strings.Contains(out, "/tmp/baz") {
t.Fatalf("Incorrect output: %s", out)
}
logDone("container REST API - check build with -f from remote")
}
func TestBuildApiLowerDockerfile(t *testing.T) {
git, err := fakeGIT("repo", map[string]string{
"dockerfile": `FROM busybox
RUN echo from dockerfile`,
})
if err != nil {
t.Fatal(err)
}
defer git.Close()
buf, err := sockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json")
if err != nil {
t.Fatalf("Build failed: %s\n%q", err, buf)
}
out := string(buf)
if !strings.Contains(out, "from dockerfile") {
t.Fatalf("Incorrect output: %s", out)
}
logDone("container REST API - check build with lower dockerfile")
}
func TestBuildApiBuildGitWithF(t *testing.T) {
git, err := fakeGIT("repo", map[string]string{
"baz": `FROM busybox
RUN echo from baz`,
"Dockerfile": `FROM busybox
RUN echo from Dockerfile`,
})
if err != nil {
t.Fatal(err)
}
defer git.Close()
// Make sure it tries to 'dockerfile' query param value
buf, err := sockRequestRaw("POST", "/build?dockerfile=baz&remote="+git.RepoURL, nil, "application/json")
if err != nil {
t.Fatalf("Build failed: %s\n%q", err, buf)
}
out := string(buf)
if !strings.Contains(out, "from baz") {
t.Fatalf("Incorrect output: %s", out)
}
logDone("container REST API - check build from git w/F")
}
func TestBuildApiDoubleDockerfile(t *testing.T) {
git, err := fakeGIT("repo", map[string]string{
"Dockerfile": `FROM busybox
RUN echo from Dockerfile`,
"dockerfile": `FROM busybox
RUN echo from dockerfile`,
})
if err != nil {
t.Fatal(err)
}
defer git.Close()
// Make sure it tries to 'dockerfile' query param value
buf, err := sockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json")
if err != nil {
t.Fatalf("Build failed: %s", err)
}
out := string(buf)
if !strings.Contains(out, "from Dockerfile") {
t.Fatalf("Incorrect output: %s", out)
}
logDone("container REST API - check build with two dockerfiles")
}
func TestBuildApiDockerfileSymlink(t *testing.T) {
// Test to make sure we stop people from trying to leave the
// build context when specifying a symlink as the path to the dockerfile