Skip to content

Commit dc462ec

Browse files
committed
dockerfile: fix panic on warnings with multi-platform
Signed-off-by: Tonis Tiigi <[email protected]>
1 parent 2f27653 commit dc462ec

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

frontend/dockerfile/dockerfile2llb/convert.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ func toDispatchState(ctx context.Context, dt []byte, opt ConvertOpt) (*dispatchS
183183
opt.ContextLocalName = defaultContextLocalName
184184
}
185185

186+
if opt.Warn == nil {
187+
opt.Warn = func(string, string, [][]byte, *parser.Range) {}
188+
}
189+
186190
platformOpt := buildPlatformOpt(&opt)
187191

188192
optMetaArgs := getPlatformArgs(platformOpt)

frontend/dockerfile/dockerfile_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ var allTests = integration.TestFuncs(
156156
testSecretSSHProvenance,
157157
testNilProvenance,
158158
testSBOMScannerArgs,
159+
testMultiPlatformWarnings,
159160
)
160161

161162
// Tests that depend on the `security.*` entitlements
@@ -6394,6 +6395,81 @@ ARG BUILDKIT_SBOM_SCAN_STAGE=true
63946395
require.Equal(t, 1, len(att.LayersRaw))
63956396
}
63966397

6398+
// #3495
6399+
func testMultiPlatformWarnings(t *testing.T, sb integration.Sandbox) {
6400+
f := getFrontend(t, sb)
6401+
6402+
// empty line in here is intentional to cause line continuation warning
6403+
dockerfile := []byte(`
6404+
FROM scratch
6405+
COPY Dockerfile \
6406+
6407+
.
6408+
`)
6409+
6410+
dir, err := integration.Tmpdir(
6411+
t,
6412+
fstest.CreateFile("Dockerfile", dockerfile, 0600),
6413+
)
6414+
require.NoError(t, err)
6415+
defer os.RemoveAll(dir)
6416+
6417+
c, err := client.New(sb.Context(), sb.Address())
6418+
require.NoError(t, err)
6419+
defer c.Close()
6420+
6421+
status := make(chan *client.SolveStatus)
6422+
statusDone := make(chan struct{})
6423+
done := make(chan struct{})
6424+
6425+
var warnings []*client.VertexWarning
6426+
6427+
go func() {
6428+
defer close(statusDone)
6429+
for {
6430+
select {
6431+
case st, ok := <-status:
6432+
if !ok {
6433+
return
6434+
}
6435+
warnings = append(warnings, st.Warnings...)
6436+
case <-done:
6437+
return
6438+
}
6439+
}
6440+
}()
6441+
6442+
_, err = f.Solve(sb.Context(), c, client.SolveOpt{
6443+
FrontendAttrs: map[string]string{
6444+
"platform": "linux/amd64,linux/arm64",
6445+
},
6446+
LocalDirs: map[string]string{
6447+
builder.DefaultLocalNameDockerfile: dir,
6448+
builder.DefaultLocalNameContext: dir,
6449+
},
6450+
}, status)
6451+
require.NoError(t, err)
6452+
6453+
select {
6454+
case <-statusDone:
6455+
case <-time.After(10 * time.Second):
6456+
close(done)
6457+
}
6458+
6459+
<-statusDone
6460+
6461+
// two platforms only show one warning
6462+
require.Equal(t, 1, len(warnings))
6463+
6464+
w := warnings[0]
6465+
6466+
require.Equal(t, "Empty continuation line found in: COPY Dockerfile .", string(w.Short))
6467+
require.Equal(t, 1, len(w.Detail))
6468+
require.Equal(t, "Empty continuation lines will become errors in a future release", string(w.Detail[0]))
6469+
require.Equal(t, "https://github.com/moby/moby/pull/33719", w.URL)
6470+
require.Equal(t, 1, w.Level)
6471+
}
6472+
63976473
func runShell(dir string, cmds ...string) error {
63986474
for _, args := range cmds {
63996475
var cmd *exec.Cmd

0 commit comments

Comments
 (0)