Merge pull request #401 from tonistiigi/relative-wd
llb: fix relative working directory in clientdocker-18.09
commit
06d81be140
|
@ -33,6 +33,7 @@ import (
|
|||
|
||||
func TestClientIntegration(t *testing.T) {
|
||||
integration.Run(t, []integration.Test{
|
||||
testRelativeWorkDir,
|
||||
testCallDiskUsage,
|
||||
testBuildMultiMount,
|
||||
testBuildHTTPSource,
|
||||
|
@ -52,6 +53,37 @@ func TestClientIntegration(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func testRelativeWorkDir(t *testing.T, sb integration.Sandbox) {
|
||||
t.Parallel()
|
||||
requiresLinux(t)
|
||||
c, err := New(sb.Address())
|
||||
require.NoError(t, err)
|
||||
defer c.Close()
|
||||
|
||||
pwd := llb.Image("docker.io/library/busybox:latest").
|
||||
Dir("test1").
|
||||
Dir("test2").
|
||||
Run(llb.Shlex(`sh -c "pwd > /out/pwd"`)).
|
||||
AddMount("/out", llb.Scratch())
|
||||
|
||||
def, err := pwd.Marshal()
|
||||
require.NoError(t, err)
|
||||
|
||||
destDir, err := ioutil.TempDir("", "buildkit")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(destDir)
|
||||
|
||||
_, err = c.Solve(context.TODO(), def, SolveOpt{
|
||||
Exporter: ExporterLocal,
|
||||
ExporterOutputDir: destDir,
|
||||
}, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
dt, err := ioutil.ReadFile(filepath.Join(destDir, "pwd"))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []byte("/test1/test2\n"), dt)
|
||||
}
|
||||
|
||||
func testCallDiskUsage(t *testing.T, sb integration.Sandbox) {
|
||||
t.Parallel()
|
||||
c, err := New(sb.Address())
|
||||
|
|
|
@ -2,6 +2,7 @@ package llb
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
|
||||
"github.com/google/shlex"
|
||||
)
|
||||
|
@ -31,7 +32,15 @@ func dir(str string) StateOption {
|
|||
|
||||
func dirf(str string, v ...interface{}) StateOption {
|
||||
return func(s State) State {
|
||||
return s.WithValue(keyDir, fmt.Sprintf(str, v...))
|
||||
value := fmt.Sprintf(str, v...)
|
||||
if !path.IsAbs(value) {
|
||||
prev := getDir(s)
|
||||
if prev == "" {
|
||||
prev = "/"
|
||||
}
|
||||
value = path.Join(prev, value)
|
||||
}
|
||||
return s.WithValue(keyDir, value)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package llb
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestRelativeWd(t *testing.T) {
|
||||
st := Scratch().Dir("foo")
|
||||
require.Equal(t, st.GetDir(), "/foo")
|
||||
|
||||
st = st.Dir("bar")
|
||||
require.Equal(t, st.GetDir(), "/foo/bar")
|
||||
|
||||
st = st.Dir("..")
|
||||
require.Equal(t, st.GetDir(), "/foo")
|
||||
|
||||
st = st.Dir("/baz")
|
||||
require.Equal(t, st.GetDir(), "/baz")
|
||||
|
||||
st = st.Dir("../../..")
|
||||
require.Equal(t, st.GetDir(), "/")
|
||||
}
|
Loading…
Reference in New Issue