Add proper support for relative WORKDIR instructions
Docker-DCO-1.1-Signed-off-by: Andrew Page <admwiggin@gmail.com> (github: tianon)
This commit is contained in:
parent
f9090567af
commit
054b85a7b2
2 changed files with 25 additions and 1 deletions
|
@ -441,6 +441,23 @@ func TestBuildUser(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestBuildRelativeWorkdir(t *testing.T) {
|
||||
img, err := buildImage(testContextTemplate{`
|
||||
FROM {IMAGE}
|
||||
RUN [ "$PWD" = '/' ]
|
||||
WORKDIR /test1
|
||||
RUN [ "$PWD" = '/test1' ]
|
||||
WORKDIR test2
|
||||
RUN [ "$PWD" = '/test1/test2' ]
|
||||
`, nil, nil}, t, nil, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if img.Config.WorkingDir != "/test1/test2" {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildEnv(t *testing.T) {
|
||||
img, err := buildImage(testContextTemplate{`
|
||||
from {IMAGE}
|
||||
|
|
|
@ -338,7 +338,14 @@ func (b *buildFile) CmdCopy(args string) error {
|
|||
}
|
||||
|
||||
func (b *buildFile) CmdWorkdir(workdir string) error {
|
||||
if workdir[0] == '/' {
|
||||
b.config.WorkingDir = workdir
|
||||
} else {
|
||||
if b.config.WorkingDir == "" {
|
||||
b.config.WorkingDir = "/"
|
||||
}
|
||||
b.config.WorkingDir = filepath.Join(b.config.WorkingDir, workdir)
|
||||
}
|
||||
return b.commit("", b.config.Cmd, fmt.Sprintf("WORKDIR %v", workdir))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue