dockerfile: add test for default shell and path

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
v0.8
Tonis Tiigi 2020-10-23 15:30:07 -07:00
parent 63856b6a36
commit cec6dae19d
2 changed files with 92 additions and 1 deletions

View File

@ -143,7 +143,7 @@ func TestFallbackPath(t *testing.T) {
require.False(t, def.Metadata[e.Vertex.Digest()].Caps[pb.CapExecMetaSetsDefaultPath]) require.False(t, def.Metadata[e.Vertex.Digest()].Caps[pb.CapExecMetaSetsDefaultPath])
v, ok := getenv(e, "PATH") v, ok := getenv(e, "PATH")
require.True(t, ok) require.True(t, ok)
require.Equal(t, system.DefaultPathEnv, v) require.Equal(t, system.DefaultPathEnvUnix, v)
// All capabilities, including pb.CapExecMetaSetsDefaultPath, // All capabilities, including pb.CapExecMetaSetsDefaultPath,
// so should get no PATH (not present at all, rather than // so should get no PATH (not present at all, rather than

View File

@ -106,6 +106,7 @@ var allTests = []integration.Test{
testMultiArgs, testMultiArgs,
testFrontendSubrequests, testFrontendSubrequests,
testDockefileCheckHostname, testDockefileCheckHostname,
testDefaultShellAndPath,
} }
var fileOpTests = []integration.Test{ var fileOpTests = []integration.Test{
@ -1209,6 +1210,96 @@ COPY --from=build /out .
require.Equal(t, "foo bar:box-foo:123 456", string(dt)) require.Equal(t, "foo bar:box-foo:123 456", string(dt))
} }
func testDefaultShellAndPath(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)
f := getFrontend(t, sb)
dockerfile := []byte(`
FROM scratch
ENTRYPOINT foo bar
COPY Dockerfile .
`)
dir, err := tmpdir(
fstest.CreateFile("Dockerfile", dockerfile, 0600),
)
require.NoError(t, err)
defer os.RemoveAll(dir)
c, err := client.New(context.TODO(), sb.Address())
require.NoError(t, err)
defer c.Close()
destDir, err := ioutil.TempDir("", "buildkit")
require.NoError(t, err)
defer os.RemoveAll(destDir)
out := filepath.Join(destDir, "out.tar")
outW, err := os.Create(out)
require.NoError(t, err)
_, err = f.Solve(context.TODO(), c, client.SolveOpt{
LocalDirs: map[string]string{
builder.DefaultLocalNameDockerfile: dir,
builder.DefaultLocalNameContext: dir,
},
FrontendAttrs: map[string]string{
"platform": "windows/amd64,linux/amd64",
},
Exports: []client.ExportEntry{
{
Type: client.ExporterOCI,
Output: fixedWriteCloser(outW),
},
},
}, nil)
require.NoError(t, err)
dt, err := ioutil.ReadFile(filepath.Join(destDir, "out.tar"))
require.NoError(t, err)
m, err := testutil.ReadTarToMap(dt, false)
require.NoError(t, err)
var idx ocispec.Index
err = json.Unmarshal(m["index.json"].Data, &idx)
require.NoError(t, err)
mlistHex := idx.Manifests[0].Digest.Hex()
idx = ocispec.Index{}
err = json.Unmarshal(m["blobs/sha256/"+mlistHex].Data, &idx)
require.NoError(t, err)
require.Equal(t, 2, len(idx.Manifests))
for i, exp := range []struct {
p string
entrypoint []string
env []string
}{
{p: "windows/amd64", entrypoint: []string{"cmd", "/S", "/C", "foo bar"}, env: []string{"PATH=c:\\Windows\\System32;c:\\Windows"}},
{p: "linux/amd64", entrypoint: []string{"/bin/sh", "-c", "foo bar"}, env: []string{"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"}},
} {
t.Run(exp.p, func(t *testing.T) {
require.Equal(t, exp.p, platforms.Format(*idx.Manifests[i].Platform))
var mfst ocispec.Manifest
err = json.Unmarshal(m["blobs/sha256/"+idx.Manifests[i].Digest.Hex()].Data, &mfst)
require.NoError(t, err)
require.Equal(t, 1, len(mfst.Layers))
var img ocispec.Image
err = json.Unmarshal(m["blobs/sha256/"+mfst.Config.Digest.Hex()].Data, &img)
require.NoError(t, err)
require.Equal(t, exp.entrypoint, img.Config.Entrypoint)
require.Equal(t, exp.env, img.Config.Env)
})
}
}
func testExportMultiPlatform(t *testing.T, sb integration.Sandbox) { func testExportMultiPlatform(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb) skipDockerd(t, sb)
f := getFrontend(t, sb) f := getFrontend(t, sb)