2015-08-23 11:52:25 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"archive/tar"
|
|
|
|
"bytes"
|
2017-02-28 11:12:30 -05:00
|
|
|
"io/ioutil"
|
2015-08-23 11:52:25 -04:00
|
|
|
"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
|
2017-01-13 11:23:28 -05:00
|
|
|
if testEnv.DaemonPlatform() == "windows" {
|
2016-09-19 15:53:14 -04:00
|
|
|
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/`
|
|
|
|
}
|
2017-01-16 05:30:14 -05:00
|
|
|
server := fakeStorage(c, map[string]string{"testD": testD})
|
2015-08-23 11:52:25 -04:00
|
|
|
defer server.Close()
|
|
|
|
|
2017-03-06 10:35:27 -05:00
|
|
|
res, body, err := request.Post("/build?dockerfile=baz&remote="+server.URL()+"/testD", request.JSON)
|
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
|
|
|
|
2017-01-16 05:30:14 -05:00
|
|
|
server := fakeBinaryStorage(c, map[string]*bytes.Buffer{
|
2015-08-23 11:52:25 -04:00
|
|
|
"testT.tar": buffer,
|
|
|
|
})
|
|
|
|
defer server.Close()
|
|
|
|
|
2017-03-06 10:35:27 -05:00
|
|
|
res, b, err := request.Post("/build?remote="+server.URL()+"/testT.tar", request.ContentType("application/tar"))
|
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
|
|
|
|
2017-01-16 05:30:14 -05:00
|
|
|
server := fakeBinaryStorage(c, map[string]*bytes.Buffer{
|
2015-08-23 11:52:25 -04:00
|
|
|
"testT.tar": buffer,
|
|
|
|
})
|
|
|
|
defer server.Close()
|
2017-01-16 05:30:14 -05:00
|
|
|
|
2015-08-23 11:52:25 -04:00
|
|
|
url := "/build?dockerfile=custom&remote=" + server.URL() + "/testT.tar"
|
2017-03-06 10:35:27 -05:00
|
|
|
res, body, err := request.Post(url, request.ContentType("application/tar"))
|
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) {
|
2017-01-16 05:30:14 -05:00
|
|
|
git := newFakeGit(c, "repo", map[string]string{
|
2015-08-23 11:52:25 -04:00
|
|
|
"dockerfile": `FROM busybox
|
|
|
|
RUN echo from dockerfile`,
|
|
|
|
}, false)
|
|
|
|
defer git.Close()
|
|
|
|
|
2017-03-06 10:35:27 -05:00
|
|
|
res, body, err := request.Post("/build?remote="+git.RepoURL, request.JSON)
|
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) {
|
2017-01-16 05:30:14 -05:00
|
|
|
git := newFakeGit(c, "repo", map[string]string{
|
2015-08-23 11:52:25 -04:00
|
|
|
"baz": `FROM busybox
|
|
|
|
RUN echo from baz`,
|
|
|
|
"Dockerfile": `FROM busybox
|
|
|
|
RUN echo from Dockerfile`,
|
|
|
|
}, false)
|
|
|
|
defer git.Close()
|
|
|
|
|
|
|
|
// Make sure it tries to 'dockerfile' query param value
|
2017-03-06 10:35:27 -05:00
|
|
|
res, body, err := request.Post("/build?dockerfile=baz&remote="+git.RepoURL, request.JSON)
|
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
|
2017-01-16 05:30:14 -05:00
|
|
|
git := newFakeGit(c, "repo", map[string]string{
|
2015-08-23 11:52:25 -04:00
|
|
|
"Dockerfile": `FROM busybox
|
|
|
|
RUN echo from Dockerfile`,
|
|
|
|
"dockerfile": `FROM busybox
|
|
|
|
RUN echo from dockerfile`,
|
|
|
|
}, false)
|
|
|
|
defer git.Close()
|
|
|
|
|
|
|
|
// Make sure it tries to 'dockerfile' query param value
|
2017-03-06 10:35:27 -05:00
|
|
|
res, body, err := request.Post("/build?remote="+git.RepoURL, request.JSON)
|
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)
|
|
|
|
|
2017-03-06 10:35:27 -05:00
|
|
|
res, body, err := request.Post("/build", request.RawContent(ioutil.NopCloser(buffer)), request.ContentType("application/x-tar"))
|
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)
|
|
|
|
}
|