mirror of
https://github.com/docker/cli.git
synced 2026-09-28 02:06:53 -04:00
Merge pull request #89 from tonistiigi/fix-add-remote
[17.06] build: fix add from remote url
This commit is contained in:
@@ -30,9 +30,10 @@ type pathCache interface {
|
|||||||
// copyInfo is a data object which stores the metadata about each source file in
|
// copyInfo is a data object which stores the metadata about each source file in
|
||||||
// a copyInstruction
|
// a copyInstruction
|
||||||
type copyInfo struct {
|
type copyInfo struct {
|
||||||
root string
|
root string
|
||||||
path string
|
path string
|
||||||
hash string
|
hash string
|
||||||
|
noDecompress bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCopyInfoFromSource(source builder.Source, path string, hash string) copyInfo {
|
func newCopyInfoFromSource(source builder.Source, path string, hash string) copyInfo {
|
||||||
@@ -118,7 +119,9 @@ func (o *copier) getCopyInfoForSourcePath(orig string) ([]copyInfo, error) {
|
|||||||
o.tmpPaths = append(o.tmpPaths, remote.Root())
|
o.tmpPaths = append(o.tmpPaths, remote.Root())
|
||||||
|
|
||||||
hash, err := remote.Hash(path)
|
hash, err := remote.Hash(path)
|
||||||
return newCopyInfos(newCopyInfoFromSource(remote, path, hash)), err
|
ci := newCopyInfoFromSource(remote, path, hash)
|
||||||
|
ci.noDecompress = true // data from http shouldn't be extracted even on ADD
|
||||||
|
return newCopyInfos(ci), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup removes any temporary directories created as part of downloading
|
// Cleanup removes any temporary directories created as part of downloading
|
||||||
|
|||||||
@@ -156,6 +156,11 @@ func add(req dispatchRequest) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
copyInstruction.allowLocalDecompression = true
|
copyInstruction.allowLocalDecompression = true
|
||||||
|
for _, ci := range copyInstruction.infos {
|
||||||
|
if ci.noDecompress {
|
||||||
|
copyInstruction.allowLocalDecompression = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return req.builder.performCopy(req.state, copyInstruction)
|
return req.builder.performCopy(req.state, copyInstruction)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"archive/tar"
|
"archive/tar"
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -322,6 +323,50 @@ func (s *DockerSuite) TestBuildOnBuildCache(c *check.C) {
|
|||||||
assert.Equal(c, parentID, image.Parent)
|
assert.Equal(c, parentID, image.Parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *DockerSuite) TestBuildAddRemoteNoDecompress(c *check.C) {
|
||||||
|
buffer := new(bytes.Buffer)
|
||||||
|
tw := tar.NewWriter(buffer)
|
||||||
|
dt := []byte("contents")
|
||||||
|
err := tw.WriteHeader(&tar.Header{
|
||||||
|
Name: "foo",
|
||||||
|
Size: int64(len(dt)),
|
||||||
|
Mode: 0600,
|
||||||
|
Typeflag: tar.TypeReg,
|
||||||
|
})
|
||||||
|
require.NoError(c, err)
|
||||||
|
_, err = tw.Write(dt)
|
||||||
|
require.NoError(c, err)
|
||||||
|
err = tw.Close()
|
||||||
|
require.NoError(c, err)
|
||||||
|
|
||||||
|
server := fakestorage.New(c, "", fakecontext.WithBinaryFiles(map[string]*bytes.Buffer{
|
||||||
|
"test.tar": buffer,
|
||||||
|
}))
|
||||||
|
defer server.Close()
|
||||||
|
|
||||||
|
dockerfile := fmt.Sprintf(`
|
||||||
|
FROM busybox
|
||||||
|
ADD %s/test.tar /
|
||||||
|
RUN [ -f test.tar ]
|
||||||
|
`, server.URL())
|
||||||
|
|
||||||
|
ctx := fakecontext.New(c, "",
|
||||||
|
fakecontext.WithDockerfile(dockerfile),
|
||||||
|
)
|
||||||
|
defer ctx.Close()
|
||||||
|
|
||||||
|
res, body, err := request.Post(
|
||||||
|
"/build",
|
||||||
|
request.RawContent(ctx.AsTarReader(c)),
|
||||||
|
request.ContentType("application/x-tar"))
|
||||||
|
require.NoError(c, err)
|
||||||
|
assert.Equal(c, http.StatusOK, res.StatusCode)
|
||||||
|
|
||||||
|
out, err := testutil.ReadBody(body)
|
||||||
|
require.NoError(c, err)
|
||||||
|
assert.Contains(c, string(out), "Successfully built")
|
||||||
|
}
|
||||||
|
|
||||||
type buildLine struct {
|
type buildLine struct {
|
||||||
Stream string
|
Stream string
|
||||||
Aux struct {
|
Aux struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user