2015-08-23 11:52:25 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"archive/tar"
|
|
|
|
"bytes"
|
|
|
|
"net/http"
|
2016-04-01 13:49:04 -04:00
|
|
|
"regexp"
|
|
|
|
"strings"
|
2015-08-23 11:52:25 -04:00
|
|
|
|
2016-12-30 12:23:00 -05:00
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
2016-12-30 04:49:36 -05:00
|
|
|
"github.com/docker/docker/integration-cli/request"
|
2016-12-30 12:23:00 -05:00
|
|
|
"github.com/docker/docker/pkg/testutil"
|
2015-08-23 11:52:25 -04:00
|
|
|
"github.com/go-check/check"
|
|
|
|
)
|
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-27 21:50:12 -04:00
|
|
|
func (s *DockerSuite) TestBuildAPIDockerFileRemote(c *check.C) {
|
2015-09-18 13:41:12 -04:00
|
|
|
testRequires(c, NotUserNamespace)
|
2016-09-19 15:53:14 -04:00
|
|
|
var testD string
|
|
|
|
if daemonPlatform == "windows" {
|
|
|
|
testD = `FROM busybox
|
2015-08-23 11:52:25 -04:00
|
|
|
COPY * /tmp/
|
|
|
|
RUN find / -name ba*
|
2016-09-19 15:53:14 -04:00
|
|
|
RUN find /tmp/`
|
|
|
|
} else {
|
|
|
|
// -xdev is required because sysfs can cause EPERM
|
|
|
|
testD = `FROM busybox
|
|
|
|
COPY * /tmp/
|
|
|
|
RUN find / -xdev -name ba*
|
|
|
|
RUN find /tmp/`
|
|
|
|
}
|
|
|
|
server, err := fakeStorage(map[string]string{"testD": testD})
|
2015-10-17 08:24:56 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-08-23 11:52:25 -04:00
|
|
|
defer server.Close()
|
|
|
|
|
2016-12-30 04:49:36 -05:00
|
|
|
res, body, err := request.SockRequestRaw("POST", "/build?dockerfile=baz&remote="+server.URL()+"/testD", nil, "application/json", daemonHost())
|
2015-10-17 08:24:56 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
2015-08-23 11:52:25 -04:00
|
|
|
|
2016-12-30 12:23:00 -05:00
|
|
|
buf, err := testutil.ReadBody(body)
|
2015-10-17 08:24:56 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-08-23 11:52:25 -04:00
|
|
|
|
|
|
|
// Make sure Dockerfile exists.
|
|
|
|
// Make sure 'baz' doesn't exist ANYWHERE despite being mentioned in the URL
|
|
|
|
out := string(buf)
|
2015-10-17 08:24:56 -04:00
|
|
|
c.Assert(out, checker.Contains, "/tmp/Dockerfile")
|
|
|
|
c.Assert(out, checker.Not(checker.Contains), "baz")
|
2015-08-23 11:52:25 -04:00
|
|
|
}
|
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-27 21:50:12 -04:00
|
|
|
func (s *DockerSuite) TestBuildAPIRemoteTarballContext(c *check.C) {
|
2015-08-23 11:52:25 -04:00
|
|
|
buffer := new(bytes.Buffer)
|
|
|
|
tw := tar.NewWriter(buffer)
|
|
|
|
defer tw.Close()
|
|
|
|
|
|
|
|
dockerfile := []byte("FROM busybox")
|
2015-10-17 08:24:56 -04:00
|
|
|
err := tw.WriteHeader(&tar.Header{
|
2015-08-23 11:52:25 -04:00
|
|
|
Name: "Dockerfile",
|
|
|
|
Size: int64(len(dockerfile)),
|
2015-10-17 08:24:56 -04:00
|
|
|
})
|
|
|
|
// failed to write tar file header
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
_, err = tw.Write(dockerfile)
|
|
|
|
// failed to write tar file content
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
// failed to close tar archive
|
|
|
|
c.Assert(tw.Close(), checker.IsNil)
|
2015-08-23 11:52:25 -04:00
|
|
|
|
|
|
|
server, err := fakeBinaryStorage(map[string]*bytes.Buffer{
|
|
|
|
"testT.tar": buffer,
|
|
|
|
})
|
2015-10-17 08:24:56 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-08-23 11:52:25 -04:00
|
|
|
|
|
|
|
defer server.Close()
|
|
|
|
|
2016-12-30 04:49:36 -05:00
|
|
|
res, b, err := request.SockRequestRaw("POST", "/build?remote="+server.URL()+"/testT.tar", nil, "application/tar", daemonHost())
|
2015-10-17 08:24:56 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
2015-08-23 11:52:25 -04:00
|
|
|
b.Close()
|
|
|
|
}
|
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-27 21:50:12 -04:00
|
|
|
func (s *DockerSuite) TestBuildAPIRemoteTarballContextWithCustomDockerfile(c *check.C) {
|
2015-08-23 11:52:25 -04:00
|
|
|
buffer := new(bytes.Buffer)
|
|
|
|
tw := tar.NewWriter(buffer)
|
|
|
|
defer tw.Close()
|
|
|
|
|
|
|
|
dockerfile := []byte(`FROM busybox
|
|
|
|
RUN echo 'wrong'`)
|
2015-10-17 08:24:56 -04:00
|
|
|
err := tw.WriteHeader(&tar.Header{
|
2015-08-23 11:52:25 -04:00
|
|
|
Name: "Dockerfile",
|
|
|
|
Size: int64(len(dockerfile)),
|
2015-10-17 08:24:56 -04:00
|
|
|
})
|
|
|
|
// failed to write tar file header
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
_, err = tw.Write(dockerfile)
|
|
|
|
// failed to write tar file content
|
|
|
|
c.Assert(err, checker.IsNil)
|
2015-08-23 11:52:25 -04:00
|
|
|
|
|
|
|
custom := []byte(`FROM busybox
|
|
|
|
RUN echo 'right'
|
|
|
|
`)
|
2015-10-17 08:24:56 -04:00
|
|
|
err = tw.WriteHeader(&tar.Header{
|
2015-08-23 11:52:25 -04:00
|
|
|
Name: "custom",
|
|
|
|
Size: int64(len(custom)),
|
2015-10-17 08:24:56 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
// failed to write tar file header
|
|
|
|
c.Assert(err, checker.IsNil)
|
2015-08-23 11:52:25 -04:00
|
|
|
|
2015-10-17 08:24:56 -04:00
|
|
|
_, err = tw.Write(custom)
|
|
|
|
// failed to write tar file content
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
// failed to close tar archive
|
|
|
|
c.Assert(tw.Close(), checker.IsNil)
|
2015-08-23 11:52:25 -04:00
|
|
|
|
|
|
|
server, err := fakeBinaryStorage(map[string]*bytes.Buffer{
|
|
|
|
"testT.tar": buffer,
|
|
|
|
})
|
2015-10-17 08:24:56 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-08-23 11:52:25 -04:00
|
|
|
|
|
|
|
defer server.Close()
|
|
|
|
url := "/build?dockerfile=custom&remote=" + server.URL() + "/testT.tar"
|
2016-12-30 04:49:36 -05:00
|
|
|
res, body, err := request.SockRequestRaw("POST", url, nil, "application/tar", daemonHost())
|
2015-10-17 08:24:56 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
2015-08-23 11:52:25 -04:00
|
|
|
|
|
|
|
defer body.Close()
|
2016-12-30 12:23:00 -05:00
|
|
|
content, err := testutil.ReadBody(body)
|
2015-10-17 08:24:56 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-08-23 11:52:25 -04:00
|
|
|
|
2015-10-17 08:24:56 -04:00
|
|
|
// Build used the wrong dockerfile.
|
|
|
|
c.Assert(string(content), checker.Not(checker.Contains), "wrong")
|
2015-08-23 11:52:25 -04:00
|
|
|
}
|
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-27 21:50:12 -04:00
|
|
|
func (s *DockerSuite) TestBuildAPILowerDockerfile(c *check.C) {
|
2015-08-23 11:52:25 -04:00
|
|
|
git, err := newFakeGit("repo", map[string]string{
|
|
|
|
"dockerfile": `FROM busybox
|
|
|
|
RUN echo from dockerfile`,
|
|
|
|
}, false)
|
2015-10-17 08:24:56 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-08-23 11:52:25 -04:00
|
|
|
defer git.Close()
|
|
|
|
|
2016-12-30 04:49:36 -05:00
|
|
|
res, body, err := request.SockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json", daemonHost())
|
2015-10-17 08:24:56 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
2015-08-23 11:52:25 -04:00
|
|
|
|
2016-12-30 12:23:00 -05:00
|
|
|
buf, err := testutil.ReadBody(body)
|
2015-10-17 08:24:56 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-08-23 11:52:25 -04:00
|
|
|
|
|
|
|
out := string(buf)
|
2015-10-17 08:24:56 -04:00
|
|
|
c.Assert(out, checker.Contains, "from dockerfile")
|
2015-08-23 11:52:25 -04:00
|
|
|
}
|
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-27 21:50:12 -04:00
|
|
|
func (s *DockerSuite) TestBuildAPIBuildGitWithF(c *check.C) {
|
2015-08-23 11:52:25 -04:00
|
|
|
git, err := newFakeGit("repo", map[string]string{
|
|
|
|
"baz": `FROM busybox
|
|
|
|
RUN echo from baz`,
|
|
|
|
"Dockerfile": `FROM busybox
|
|
|
|
RUN echo from Dockerfile`,
|
|
|
|
}, false)
|
2015-10-17 08:24:56 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-08-23 11:52:25 -04:00
|
|
|
defer git.Close()
|
|
|
|
|
|
|
|
// Make sure it tries to 'dockerfile' query param value
|
2016-12-30 04:49:36 -05:00
|
|
|
res, body, err := request.SockRequestRaw("POST", "/build?dockerfile=baz&remote="+git.RepoURL, nil, "application/json", daemonHost())
|
2015-10-17 08:24:56 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
2015-08-23 11:52:25 -04:00
|
|
|
|
2016-12-30 12:23:00 -05:00
|
|
|
buf, err := testutil.ReadBody(body)
|
2015-10-17 08:24:56 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-08-23 11:52:25 -04:00
|
|
|
|
|
|
|
out := string(buf)
|
2015-10-17 08:24:56 -04:00
|
|
|
c.Assert(out, checker.Contains, "from baz")
|
2015-08-23 11:52:25 -04:00
|
|
|
}
|
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-27 21:50:12 -04:00
|
|
|
func (s *DockerSuite) TestBuildAPIDoubleDockerfile(c *check.C) {
|
2015-08-23 11:52:25 -04:00
|
|
|
testRequires(c, UnixCli) // dockerfile overwrites Dockerfile on Windows
|
|
|
|
git, err := newFakeGit("repo", map[string]string{
|
|
|
|
"Dockerfile": `FROM busybox
|
|
|
|
RUN echo from Dockerfile`,
|
|
|
|
"dockerfile": `FROM busybox
|
|
|
|
RUN echo from dockerfile`,
|
|
|
|
}, false)
|
2015-10-17 08:24:56 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-08-23 11:52:25 -04:00
|
|
|
defer git.Close()
|
|
|
|
|
|
|
|
// Make sure it tries to 'dockerfile' query param value
|
2016-12-30 04:49:36 -05:00
|
|
|
res, body, err := request.SockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json", daemonHost())
|
2015-10-17 08:24:56 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
2015-08-23 11:52:25 -04:00
|
|
|
|
2016-12-30 12:23:00 -05:00
|
|
|
buf, err := testutil.ReadBody(body)
|
2015-10-17 08:24:56 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-08-23 11:52:25 -04:00
|
|
|
|
|
|
|
out := string(buf)
|
2015-10-17 08:24:56 -04:00
|
|
|
c.Assert(out, checker.Contains, "from Dockerfile")
|
2015-08-23 11:52:25 -04:00
|
|
|
}
|
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-27 21:50:12 -04:00
|
|
|
func (s *DockerSuite) TestBuildAPIUnnormalizedTarPaths(c *check.C) {
|
2016-04-01 13:49:04 -04:00
|
|
|
// Make sure that build context tars with entries of the form
|
|
|
|
// x/./y don't cause caching false positives.
|
|
|
|
|
|
|
|
buildFromTarContext := func(fileContents []byte) string {
|
|
|
|
buffer := new(bytes.Buffer)
|
|
|
|
tw := tar.NewWriter(buffer)
|
|
|
|
defer tw.Close()
|
|
|
|
|
|
|
|
dockerfile := []byte(`FROM busybox
|
|
|
|
COPY dir /dir/`)
|
|
|
|
err := tw.WriteHeader(&tar.Header{
|
|
|
|
Name: "Dockerfile",
|
|
|
|
Size: int64(len(dockerfile)),
|
|
|
|
})
|
|
|
|
//failed to write tar file header
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
_, err = tw.Write(dockerfile)
|
|
|
|
// failed to write Dockerfile in tar file content
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
err = tw.WriteHeader(&tar.Header{
|
|
|
|
Name: "dir/./file",
|
|
|
|
Size: int64(len(fileContents)),
|
|
|
|
})
|
|
|
|
//failed to write tar file header
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
_, err = tw.Write(fileContents)
|
|
|
|
// failed to write file contents in tar file content
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
// failed to close tar archive
|
|
|
|
c.Assert(tw.Close(), checker.IsNil)
|
|
|
|
|
2016-12-30 04:49:36 -05:00
|
|
|
res, body, err := request.SockRequestRaw("POST", "/build", buffer, "application/x-tar", daemonHost())
|
2016-04-01 13:49:04 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
|
|
|
|
2016-12-30 12:23:00 -05:00
|
|
|
out, err := testutil.ReadBody(body)
|
2016-04-01 13:49:04 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
lines := strings.Split(string(out), "\n")
|
|
|
|
c.Assert(len(lines), checker.GreaterThan, 1)
|
|
|
|
c.Assert(lines[len(lines)-2], checker.Matches, ".*Successfully built [0-9a-f]{12}.*")
|
|
|
|
|
|
|
|
re := regexp.MustCompile("Successfully built ([0-9a-f]{12})")
|
|
|
|
matches := re.FindStringSubmatch(lines[len(lines)-2])
|
|
|
|
return matches[1]
|
|
|
|
}
|
|
|
|
|
|
|
|
imageA := buildFromTarContext([]byte("abc"))
|
|
|
|
imageB := buildFromTarContext([]byte("def"))
|
|
|
|
|
|
|
|
c.Assert(imageA, checker.Not(checker.Equals), imageB)
|
|
|
|
}
|