mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #11002 from ahmetalpbalkan/win-cli/dockerfile-path-fix
Support windows style dockerfile paths for build cmd
This commit is contained in:
commit
1061c56a5f
6 changed files with 11 additions and 7 deletions
|
@ -155,11 +155,10 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
|
|||
if *dockerfileName == "" {
|
||||
// No -f/--file was specified so use the default
|
||||
*dockerfileName = api.DefaultDockerfileName
|
||||
filename = path.Join(absRoot, *dockerfileName)
|
||||
filename = filepath.Join(absRoot, *dockerfileName)
|
||||
}
|
||||
|
||||
origDockerfile := *dockerfileName // used for error msg
|
||||
|
||||
if filename, err = filepath.Abs(filename); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -175,6 +174,11 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// And canonicalize dockerfile name to a platform-independent one
|
||||
*dockerfileName, err = archive.CanonicalTarNameForPath(*dockerfileName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Cannot canonicalize dockerfile path %s: %v", dockerfileName, err)
|
||||
}
|
||||
|
||||
if _, err = os.Lstat(filename); os.IsNotExist(err) {
|
||||
return fmt.Errorf("Cannot locate Dockerfile: %s", origDockerfile)
|
||||
|
|
|
@ -175,7 +175,7 @@ type tarAppender struct {
|
|||
// canonicalTarName provides a platform-independent and consistent posix-style
|
||||
//path for files and directories to be archived regardless of the platform.
|
||||
func canonicalTarName(name string, isDir bool) (string, error) {
|
||||
name, err := canonicalTarNameForPath(name)
|
||||
name, err := CanonicalTarNameForPath(name)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
// canonicalTarNameForPath returns platform-specific filepath
|
||||
// to canonical posix-style path for tar archival. p is relative
|
||||
// path.
|
||||
func canonicalTarNameForPath(p string) (string, error) {
|
||||
func CanonicalTarNameForPath(p string) (string, error) {
|
||||
return p, nil // already unix-style
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ func TestCanonicalTarNameForPath(t *testing.T) {
|
|||
{"foo/dir/", "foo/dir/"},
|
||||
}
|
||||
for _, v := range cases {
|
||||
if out, err := canonicalTarNameForPath(v.in); err != nil {
|
||||
if out, err := CanonicalTarNameForPath(v.in); err != nil {
|
||||
t.Fatalf("cannot get canonical name for path: %s: %v", v.in, err)
|
||||
} else if out != v.expected {
|
||||
t.Fatalf("wrong canonical tar name. expected:%s got:%s", v.expected, out)
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
// canonicalTarNameForPath returns platform-specific filepath
|
||||
// to canonical posix-style path for tar archival. p is relative
|
||||
// path.
|
||||
func canonicalTarNameForPath(p string) (string, error) {
|
||||
func CanonicalTarNameForPath(p string) (string, error) {
|
||||
// windows: convert windows style relative path with backslashes
|
||||
// into forward slashes. since windows does not allow '/' or '\'
|
||||
// in file names, it is mostly safe to replace however we must
|
||||
|
|
|
@ -17,7 +17,7 @@ func TestCanonicalTarNameForPath(t *testing.T) {
|
|||
{`foo\bar`, "foo/bar/", false},
|
||||
}
|
||||
for _, v := range cases {
|
||||
if out, err := canonicalTarNameForPath(v.in); err != nil && !v.shouldFail {
|
||||
if out, err := CanonicalTarNameForPath(v.in); err != nil && !v.shouldFail {
|
||||
t.Fatalf("cannot get canonical name for path: %s: %v", v.in, err)
|
||||
} else if v.shouldFail && err == nil {
|
||||
t.Fatalf("canonical path call should have pailed with error. in=%s out=%s", v.in, out)
|
||||
|
|
Loading…
Add table
Reference in a new issue