mirror of
https://github.com/docker/docs.git
synced 2026-04-12 14:25:46 +07:00
Merge pull request #10858 from duglin/10807-MixedcaseDockerfile
Support dockerfile and Dockerfile
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -4699,6 +4699,125 @@ func TestBuildRenamedDockerfile(t *testing.T) {
|
||||
logDone("build - rename dockerfile")
|
||||
}
|
||||
|
||||
func TestBuildFromMixedcaseDockerfile(t *testing.T) {
|
||||
defer deleteImages("test1")
|
||||
|
||||
ctx, err := fakeContext(`FROM busybox
|
||||
RUN echo from dockerfile`,
|
||||
map[string]string{
|
||||
"dockerfile": "FROM busybox\nRUN echo from dockerfile",
|
||||
})
|
||||
defer ctx.Close()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
out, _, err := dockerCmdInDir(t, ctx.Dir, "build", "-t", "test1", ".")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to build: %s\n%s", out, err)
|
||||
}
|
||||
|
||||
if !strings.Contains(out, "from dockerfile") {
|
||||
t.Fatalf("Missing proper output: %s", out)
|
||||
}
|
||||
|
||||
logDone("build - mixedcase Dockerfile")
|
||||
}
|
||||
|
||||
func TestBuildWithTwoDockerfiles(t *testing.T) {
|
||||
defer deleteImages("test1")
|
||||
|
||||
ctx, err := fakeContext(`FROM busybox
|
||||
RUN echo from Dockerfile`,
|
||||
map[string]string{
|
||||
"dockerfile": "FROM busybox\nRUN echo from dockerfile",
|
||||
})
|
||||
defer ctx.Close()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
out, _, err := dockerCmdInDir(t, ctx.Dir, "build", "-t", "test1", ".")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to build: %s\n%s", out, err)
|
||||
}
|
||||
|
||||
if !strings.Contains(out, "from Dockerfile") {
|
||||
t.Fatalf("Missing proper output: %s", out)
|
||||
}
|
||||
|
||||
logDone("build - two Dockerfiles")
|
||||
}
|
||||
|
||||
func TestBuildFromURLWithF(t *testing.T) {
|
||||
defer deleteImages("test1")
|
||||
|
||||
server, err := fakeStorage(map[string]string{"baz": `FROM busybox
|
||||
RUN echo from baz
|
||||
COPY * /tmp/
|
||||
RUN find /tmp/`})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer server.Close()
|
||||
|
||||
ctx, err := fakeContext(`FROM busybox
|
||||
RUN echo from Dockerfile`,
|
||||
map[string]string{})
|
||||
defer ctx.Close()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Make sure that -f is ignored and that we don't use the Dockerfile
|
||||
// that's in the current dir
|
||||
out, _, err := dockerCmdInDir(t, ctx.Dir, "build", "-f", "baz", "-t", "test1", server.URL+"/baz")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to build: %s\n%s", out, err)
|
||||
}
|
||||
|
||||
if !strings.Contains(out, "from baz") ||
|
||||
strings.Contains(out, "/tmp/baz") ||
|
||||
!strings.Contains(out, "/tmp/Dockerfile") {
|
||||
t.Fatalf("Missing proper output: %s", out)
|
||||
}
|
||||
|
||||
logDone("build - from URL with -f")
|
||||
}
|
||||
|
||||
func TestBuildFromStdinWithF(t *testing.T) {
|
||||
defer deleteImages("test1")
|
||||
|
||||
ctx, err := fakeContext(`FROM busybox
|
||||
RUN echo from Dockerfile`,
|
||||
map[string]string{})
|
||||
defer ctx.Close()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Make sure that -f is ignored and that we don't use the Dockerfile
|
||||
// that's in the current dir
|
||||
dockerCommand := exec.Command(dockerBinary, "build", "-f", "baz", "-t", "test1", "-")
|
||||
dockerCommand.Dir = ctx.Dir
|
||||
dockerCommand.Stdin = strings.NewReader(`FROM busybox
|
||||
RUN echo from baz
|
||||
COPY * /tmp/
|
||||
RUN find /tmp/`)
|
||||
out, status, err := runCommandWithOutput(dockerCommand)
|
||||
if err != nil || status != 0 {
|
||||
t.Fatalf("Error building: %s", err)
|
||||
}
|
||||
|
||||
if !strings.Contains(out, "from baz") ||
|
||||
strings.Contains(out, "/tmp/baz") ||
|
||||
!strings.Contains(out, "/tmp/Dockerfile") {
|
||||
t.Fatalf("Missing proper output: %s", out)
|
||||
}
|
||||
|
||||
logDone("build - from stdin with -f")
|
||||
}
|
||||
|
||||
func TestBuildFromOfficialNames(t *testing.T) {
|
||||
name := "testbuildfromofficial"
|
||||
fromNames := []string{
|
||||
|
||||
Reference in New Issue
Block a user