зеркало из https://github.com/microsoft/docker.git
Buildfile: for ADD command, determine filename from URL.
This is used if the destination is a directory. This makes the URL download behavior more closely match file copying. Fixes #1142.
This commit is contained in:
Родитель
f236e62d9d
Коммит
2b0ebf5d32
21
buildfile.go
21
buildfile.go
|
@ -7,6 +7,7 @@ import (
|
||||||
"github.com/dotcloud/docker/utils"
|
"github.com/dotcloud/docker/utils"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
@ -201,6 +202,24 @@ func (b *buildFile) addRemote(container *Container, orig, dest string) error {
|
||||||
}
|
}
|
||||||
defer file.Body.Close()
|
defer file.Body.Close()
|
||||||
|
|
||||||
|
// If the destination is a directory, figure out the filename.
|
||||||
|
if strings.HasSuffix(dest, "/") {
|
||||||
|
u, err := url.Parse(orig)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
path := u.Path
|
||||||
|
if strings.HasSuffix(path, "/") {
|
||||||
|
path = path[:len(path)-1]
|
||||||
|
}
|
||||||
|
parts := strings.Split(path, "/")
|
||||||
|
filename := parts[len(parts)-1]
|
||||||
|
if filename == "" {
|
||||||
|
return fmt.Errorf("cannot determine filename from url: %s", u)
|
||||||
|
}
|
||||||
|
dest = dest + filename
|
||||||
|
}
|
||||||
|
|
||||||
return container.Inject(file.Body, dest)
|
return container.Inject(file.Body, dest)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,7 +227,7 @@ func (b *buildFile) addContext(container *Container, orig, dest string) error {
|
||||||
origPath := path.Join(b.context, orig)
|
origPath := path.Join(b.context, orig)
|
||||||
destPath := path.Join(container.RootfsPath(), dest)
|
destPath := path.Join(container.RootfsPath(), dest)
|
||||||
// Preserve the trailing '/'
|
// Preserve the trailing '/'
|
||||||
if dest[len(dest)-1] == '/' {
|
if strings.HasSuffix(dest, "/") {
|
||||||
destPath = destPath + "/"
|
destPath = destPath + "/"
|
||||||
}
|
}
|
||||||
fi, err := os.Stat(origPath)
|
fi, err := os.Stat(origPath)
|
||||||
|
|
|
@ -84,6 +84,22 @@ run [ "$(cat /somewheeeere/over/the/rainbooow/ga)" = "bu" ]
|
||||||
nil,
|
nil,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
`
|
||||||
|
from {IMAGE}
|
||||||
|
add http://{SERVERADDR}/x /a/b/c
|
||||||
|
run [ "$(cat /a/b/c)" = "hello" ]
|
||||||
|
add http://{SERVERADDR}/x?foo=bar /
|
||||||
|
run [ "$(cat /x)" = "hello" ]
|
||||||
|
add http://{SERVERADDR}/x /d/
|
||||||
|
run [ "$(cat /d/x)" = "hello" ]
|
||||||
|
add http://{SERVERADDR} /e
|
||||||
|
run [ "$(cat /e)" = "blah" ]
|
||||||
|
`,
|
||||||
|
nil,
|
||||||
|
[][2]string{{"/x", "hello"}, {"/", "blah"}},
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
`
|
`
|
||||||
from {IMAGE}
|
from {IMAGE}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче