Merge pull request #1223 from sileht/fix-workdir-relative
feat: ensure relative WorkingDir work
This commit is contained in:
commit
b62b3779fe
|
|
@ -1,6 +1,6 @@
|
||||||
FROM debian:9.11
|
FROM debian:9.11
|
||||||
COPY context/foo foo
|
COPY context/foo foo
|
||||||
WORKDIR /test
|
WORKDIR test
|
||||||
# Test that this will be appended on to the previous command, to create /test/workdir
|
# Test that this will be appended on to the previous command, to create /test/workdir
|
||||||
WORKDIR workdir
|
WORKDIR workdir
|
||||||
COPY context/foo ./currentfoo
|
COPY context/foo ./currentfoo
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,11 @@ func (w *WorkdirCommand) ExecuteCommand(config *v1.Config, buildArgs *dockerfile
|
||||||
if filepath.IsAbs(resolvedWorkingDir) {
|
if filepath.IsAbs(resolvedWorkingDir) {
|
||||||
config.WorkingDir = resolvedWorkingDir
|
config.WorkingDir = resolvedWorkingDir
|
||||||
} else {
|
} else {
|
||||||
config.WorkingDir = filepath.Join(config.WorkingDir, resolvedWorkingDir)
|
if config.WorkingDir != "" {
|
||||||
|
config.WorkingDir = filepath.Join(config.WorkingDir, resolvedWorkingDir)
|
||||||
|
} else {
|
||||||
|
config.WorkingDir = filepath.Join("/", resolvedWorkingDir)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
logrus.Infof("Changed working directory to %s", config.WorkingDir)
|
logrus.Infof("Changed working directory to %s", config.WorkingDir)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,11 @@ var workdirTests = []struct {
|
||||||
expectedPath string
|
expectedPath string
|
||||||
snapshotFiles []string
|
snapshotFiles []string
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
path: "a",
|
||||||
|
expectedPath: "/a",
|
||||||
|
snapshotFiles: []string{"/a"},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: "/a",
|
path: "/a",
|
||||||
expectedPath: "/a",
|
expectedPath: "/a",
|
||||||
|
|
@ -92,7 +97,7 @@ func TestWorkdirCommand(t *testing.T) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
cfg := &v1.Config{
|
cfg := &v1.Config{
|
||||||
WorkingDir: "/",
|
WorkingDir: "",
|
||||||
Env: []string{
|
Env: []string{
|
||||||
"path=usr/",
|
"path=usr/",
|
||||||
"home=/root",
|
"home=/root",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue