Skip to content

Commit 85f9c41

Browse files
committed
dockerfile: test support for custom sessionID for locals
Signed-off-by: Tonis Tiigi <[email protected]>
1 parent cd90732 commit 85f9c41

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

frontend/dockerfile/dockerfile_test.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import (
6262
digest "github.com/opencontainers/go-digest"
6363
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
6464
"github.com/pkg/errors"
65+
"github.com/stretchr/testify/assert"
6566
"github.com/stretchr/testify/require"
6667
statuspb "google.golang.org/genproto/googleapis/rpc/status"
6768
)
@@ -197,6 +198,7 @@ var allTests = integration.TestFuncs(
197198
testHistoryError,
198199
testHistoryFinalizeTrace,
199200
testEmptyStages,
201+
testLocalCustomSessionID,
200202
)
201203

202204
// Tests that depend on the `security.*` entitlements
@@ -6073,6 +6075,79 @@ COPY --from=base /o* /
60736075
require.True(t, errors.Is(err, os.ErrNotExist))
60746076
}
60756077

6078+
func testLocalCustomSessionID(t *testing.T, sb integration.Sandbox) {
6079+
integration.SkipOnPlatform(t, "windows")
6080+
ctx := sb.Context()
6081+
6082+
c, err := client.New(ctx, sb.Address())
6083+
require.NoError(t, err)
6084+
defer c.Close()
6085+
6086+
dockerfile := []byte(`
6087+
FROM scratch AS base
6088+
FROM scratch
6089+
COPY out /out1
6090+
COPY --from=base /another /out2
6091+
`)
6092+
6093+
dir := integration.Tmpdir(
6094+
t,
6095+
fstest.CreateFile("Dockerfile", dockerfile, 0600),
6096+
)
6097+
6098+
dir2 := integration.Tmpdir(
6099+
t,
6100+
fstest.CreateFile("out", []byte("contents1"), 0600),
6101+
)
6102+
6103+
dir3 := integration.Tmpdir(
6104+
t,
6105+
fstest.CreateFile("another", []byte("contents2"), 0600),
6106+
)
6107+
6108+
f := getFrontend(t, sb)
6109+
6110+
destDir := t.TempDir()
6111+
6112+
dirs := filesync.NewFSSyncProvider(filesync.StaticDirSource{
6113+
dockerui.DefaultLocalNameDockerfile: dir,
6114+
dockerui.DefaultLocalNameContext: dir2,
6115+
"basedir": dir3,
6116+
})
6117+
6118+
s, err := session.NewSession(ctx, "hint")
6119+
require.NoError(t, err)
6120+
s.Allow(dirs)
6121+
go func() {
6122+
err := s.Run(ctx, c.Dialer())
6123+
assert.NoError(t, err)
6124+
}()
6125+
6126+
_, err = f.Solve(sb.Context(), c, client.SolveOpt{
6127+
FrontendAttrs: map[string]string{
6128+
"context:base": "local:basedir",
6129+
"local-sessionid:" + dockerui.DefaultLocalNameDockerfile: s.ID(),
6130+
"local-sessionid:" + dockerui.DefaultLocalNameContext: s.ID(),
6131+
"local-sessionid:basedir": s.ID(),
6132+
},
6133+
Exports: []client.ExportEntry{
6134+
{
6135+
Type: client.ExporterLocal,
6136+
OutputDir: destDir,
6137+
},
6138+
},
6139+
}, nil)
6140+
require.NoError(t, err)
6141+
6142+
dt, err := os.ReadFile(filepath.Join(destDir, "out1"))
6143+
require.NoError(t, err)
6144+
require.Equal(t, "contents1", string(dt))
6145+
6146+
dt, err = os.ReadFile(filepath.Join(destDir, "out2"))
6147+
require.NoError(t, err)
6148+
require.Equal(t, "contents2", string(dt))
6149+
}
6150+
60766151
func testNamedOCILayoutContext(t *testing.T, sb integration.Sandbox) {
60776152
integration.SkipOnPlatform(t, "windows")
60786153
workers.CheckFeatureCompat(t, sb, workers.FeatureOCIExporter, workers.FeatureOCILayout)

0 commit comments

Comments
 (0)