Skip to content

Commit d6df06e

Browse files
authored
Merge pull request moby#5562 from tonistiigi/dockerfile-step-stability-test
dockerfile: add test for step names stability
2 parents 7d7a919 + 93177d4 commit d6df06e

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

frontend/dockerfile/dockerfile_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ var allTests = integration.TestFuncs(
211211
testEmptyStages,
212212
testLocalCustomSessionID,
213213
testTargetStageNameArg,
214+
testStepNames,
214215
)
215216

216217
// Tests that depend on the `security.*` entitlements
@@ -6915,6 +6916,74 @@ COPY --from=base /out /
69156916
require.Contains(t, strings.TrimSpace(string(dt)), `Resource temporarily unavailable`)
69166917
}
69176918

6919+
func testStepNames(t *testing.T, sb integration.Sandbox) {
6920+
integration.SkipOnPlatform(t, "windows")
6921+
ctx := sb.Context()
6922+
6923+
c, err := client.New(ctx, sb.Address())
6924+
require.NoError(t, err)
6925+
defer c.Close()
6926+
6927+
dockerfile := []byte(`
6928+
FROM busybox AS base
6929+
WORKDIR /out
6930+
RUN echo "base" > base
6931+
FROM scratch
6932+
COPY --from=base --chmod=0644 /out /out
6933+
`)
6934+
6935+
dir := integration.Tmpdir(
6936+
t,
6937+
fstest.CreateFile("Dockerfile", dockerfile, 0600),
6938+
)
6939+
6940+
f := getFrontend(t, sb)
6941+
6942+
ch := make(chan *client.SolveStatus)
6943+
6944+
eg, ctx := errgroup.WithContext(ctx)
6945+
6946+
eg.Go(func() error {
6947+
_, err = f.Solve(ctx, c, client.SolveOpt{
6948+
LocalMounts: map[string]fsutil.FS{
6949+
dockerui.DefaultLocalNameDockerfile: dir,
6950+
dockerui.DefaultLocalNameContext: dir,
6951+
},
6952+
}, ch)
6953+
return err
6954+
})
6955+
6956+
eg.Go(func() error {
6957+
hasCopy := false
6958+
hasRun := false
6959+
visited := make(map[string]struct{})
6960+
for status := range ch {
6961+
for _, vtx := range status.Vertexes {
6962+
if _, ok := visited[vtx.Name]; ok {
6963+
continue
6964+
}
6965+
visited[vtx.Name] = struct{}{}
6966+
t.Logf("step: %q", vtx.Name)
6967+
if vtx.Name == `[base 3/3] RUN echo "base" > base` {
6968+
hasRun = true
6969+
} else if vtx.Name == `[stage-1 1/1] COPY --from=base --chmod=0644 /out /out` {
6970+
hasCopy = true
6971+
}
6972+
}
6973+
}
6974+
if !hasCopy {
6975+
return errors.New("missing copy step")
6976+
}
6977+
if !hasRun {
6978+
return errors.New("missing run step")
6979+
}
6980+
return nil
6981+
})
6982+
6983+
err = eg.Wait()
6984+
require.NoError(t, err)
6985+
}
6986+
69186987
func testNamedImageContext(t *testing.T, sb integration.Sandbox) {
69196988
integration.SkipOnPlatform(t, "windows")
69206989
ctx := sb.Context()

0 commit comments

Comments
 (0)