-
Notifications
You must be signed in to change notification settings - Fork 18.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LCOW: WORKDIR correct handling #34405
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,25 +5,31 @@ package dockerfile | |
import "testing" | ||
|
||
func TestNormaliseWorkdir(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Normalize" |
||
tests := []struct{ current, requested, expected, etext string }{ | ||
{``, ``, ``, `cannot normalise nothing`}, | ||
{``, `C:`, ``, `C:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`}, | ||
{``, `C:.`, ``, `C:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`}, | ||
{`c:`, `\a`, ``, `c:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`}, | ||
{`c:.`, `\a`, ``, `c:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`}, | ||
{``, `a`, `C:\a`, ``}, | ||
{``, `c:\foo`, `C:\foo`, ``}, | ||
{``, `c:\\foo`, `C:\foo`, ``}, | ||
{``, `\foo`, `C:\foo`, ``}, | ||
{``, `\\foo`, `C:\foo`, ``}, | ||
{``, `/foo`, `C:\foo`, ``}, | ||
{``, `C:/foo`, `C:\foo`, ``}, | ||
{`C:\foo`, `bar`, `C:\foo\bar`, ``}, | ||
{`C:\foo`, `/bar`, `C:\bar`, ``}, | ||
{`C:\foo`, `\bar`, `C:\bar`, ``}, | ||
tests := []struct{ platform, current, requested, expected, etext string }{ | ||
{"windows", ``, ``, ``, `cannot normalise nothing`}, | ||
{"windows", ``, `C:`, ``, `C:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`}, | ||
{"windows", ``, `C:.`, ``, `C:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`}, | ||
{"windows", `c:`, `\a`, ``, `c:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`}, | ||
{"windows", `c:.`, `\a`, ``, `c:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`}, | ||
{"windows", ``, `a`, `C:\a`, ``}, | ||
{"windows", ``, `c:\foo`, `C:\foo`, ``}, | ||
{"windows", ``, `c:\\foo`, `C:\foo`, ``}, | ||
{"windows", ``, `\foo`, `C:\foo`, ``}, | ||
{"windows", ``, `\\foo`, `C:\foo`, ``}, | ||
{"windows", ``, `/foo`, `C:\foo`, ``}, | ||
{"windows", ``, `C:/foo`, `C:\foo`, ``}, | ||
{"windows", `C:\foo`, `bar`, `C:\foo\bar`, ``}, | ||
{"windows", `C:\foo`, `/bar`, `C:\bar`, ``}, | ||
{"windows", `C:\foo`, `\bar`, `C:\bar`, ``}, | ||
{"linux", ``, ``, ``, `cannot normalise nothing`}, | ||
{"linux", ``, `foo`, `/foo`, ``}, | ||
{"linux", ``, `/foo`, `/foo`, ``}, | ||
{"linux", `/foo`, `bar`, `/foo/bar`, ``}, | ||
{"linux", `/foo`, `/bar`, `/bar`, ``}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added case |
||
{"linux", `\a`, `b\c`, `/a/b/c`, ``}, | ||
} | ||
for _, i := range tests { | ||
r, e := normaliseWorkdir(i.current, i.requested) | ||
r, e := normaliseWorkdir(i.platform, i.current, i.requested) | ||
|
||
if i.etext != "" && e == nil { | ||
t.Fatalf("TestNormaliseWorkingDir Expected error %s for '%s' '%s', got no error", i.etext, i.current, i.requested) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,10 @@ package daemon | |
import ( | ||
"fmt" | ||
"os" | ||
"path" | ||
"path/filepath" | ||
"runtime" | ||
"strings" | ||
"time" | ||
|
||
containertypes "github.com/docker/docker/api/types/container" | ||
|
@@ -226,13 +229,24 @@ func (daemon *Daemon) setHostConfig(container *container.Container, hostConfig * | |
|
||
// verifyContainerSettings performs validation of the hostconfig and config | ||
// structures. | ||
func (daemon *Daemon) verifyContainerSettings(hostConfig *containertypes.HostConfig, config *containertypes.Config, update bool) ([]string, error) { | ||
|
||
func (daemon *Daemon) verifyContainerSettings(platform string, hostConfig *containertypes.HostConfig, config *containertypes.Config, update bool) ([]string, error) { | ||
// First perform verification of settings common across all platforms. | ||
if config != nil { | ||
if config.WorkingDir != "" { | ||
config.WorkingDir = filepath.FromSlash(config.WorkingDir) // Ensure in platform semantics | ||
if !system.IsAbs(config.WorkingDir) { | ||
wdInvalid := false | ||
if runtime.GOOS == platform { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a sufficient LCOW check? I think so, at least for now, but maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could be more explicit, but in reality, here it's redundant. It can only be LCOW. |
||
config.WorkingDir = filepath.FromSlash(config.WorkingDir) // Ensure in platform semantics | ||
if !system.IsAbs(config.WorkingDir) { | ||
wdInvalid = true | ||
} | ||
} else { | ||
// LCOW. Force Unix semantics | ||
config.WorkingDir = strings.Replace(config.WorkingDir, string(os.PathSeparator), "/", -1) | ||
if !path.IsAbs(config.WorkingDir) { | ||
wdInvalid = true | ||
} | ||
} | ||
if wdInvalid { | ||
return nil, fmt.Errorf("the working directory '%s' is invalid, it needs to be an absolute path", config.WorkingDir) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
normalize
(do we standardize on us eng?)