From 3e30eaa0547113cbf4f4c718196eb871040b5b31 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Thu, 12 Jan 2023 21:41:09 -0800 Subject: [PATCH 1/3] dockerfile: fix panic on warnings with multi-platform Signed-off-by: Tonis Tiigi (cherry picked from commit dc462ec87f60479f8de59f1e9cdfaf74efcef0bf) --- frontend/dockerfile/dockerfile2llb/convert.go | 4 + frontend/dockerfile/dockerfile_test.go | 76 +++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/frontend/dockerfile/dockerfile2llb/convert.go b/frontend/dockerfile/dockerfile2llb/convert.go index 546187202afa..6476267e2d32 100644 --- a/frontend/dockerfile/dockerfile2llb/convert.go +++ b/frontend/dockerfile/dockerfile2llb/convert.go @@ -183,6 +183,10 @@ func toDispatchState(ctx context.Context, dt []byte, opt ConvertOpt) (*dispatchS opt.ContextLocalName = defaultContextLocalName } + if opt.Warn == nil { + opt.Warn = func(string, string, [][]byte, *parser.Range) {} + } + platformOpt := buildPlatformOpt(&opt) optMetaArgs := getPlatformArgs(platformOpt) diff --git a/frontend/dockerfile/dockerfile_test.go b/frontend/dockerfile/dockerfile_test.go index f99ff1181d54..4b5d65028766 100644 --- a/frontend/dockerfile/dockerfile_test.go +++ b/frontend/dockerfile/dockerfile_test.go @@ -156,6 +156,7 @@ var allTests = integration.TestFuncs( testSecretSSHProvenance, testNilProvenance, testSBOMScannerArgs, + testMultiPlatformWarnings, ) // Tests that depend on the `security.*` entitlements @@ -6394,6 +6395,81 @@ ARG BUILDKIT_SBOM_SCAN_STAGE=true require.Equal(t, 1, len(att.LayersRaw)) } +// #3495 +func testMultiPlatformWarnings(t *testing.T, sb integration.Sandbox) { + f := getFrontend(t, sb) + + // empty line in here is intentional to cause line continuation warning + dockerfile := []byte(` +FROM scratch +COPY Dockerfile \ + +. +`) + + dir, err := integration.Tmpdir( + t, + fstest.CreateFile("Dockerfile", dockerfile, 0600), + ) + require.NoError(t, err) + defer os.RemoveAll(dir) + + c, err := client.New(sb.Context(), sb.Address()) + require.NoError(t, err) + defer c.Close() + + status := make(chan *client.SolveStatus) + statusDone := make(chan struct{}) + done := make(chan struct{}) + + var warnings []*client.VertexWarning + + go func() { + defer close(statusDone) + for { + select { + case st, ok := <-status: + if !ok { + return + } + warnings = append(warnings, st.Warnings...) + case <-done: + return + } + } + }() + + _, err = f.Solve(sb.Context(), c, client.SolveOpt{ + FrontendAttrs: map[string]string{ + "platform": "linux/amd64,linux/arm64", + }, + LocalDirs: map[string]string{ + builder.DefaultLocalNameDockerfile: dir, + builder.DefaultLocalNameContext: dir, + }, + }, status) + require.NoError(t, err) + + select { + case <-statusDone: + case <-time.After(10 * time.Second): + close(done) + } + + <-statusDone + + // two platforms only show one warning + require.Equal(t, 1, len(warnings)) + + w := warnings[0] + + require.Equal(t, "Empty continuation line found in: COPY Dockerfile .", string(w.Short)) + require.Equal(t, 1, len(w.Detail)) + require.Equal(t, "Empty continuation lines will become errors in a future release", string(w.Detail[0])) + require.Equal(t, "https://github.com/moby/moby/pull/33719", w.URL) + require.Equal(t, 1, w.Level) +} + func runShell(dir string, cmds ...string) error { for _, args := range cmds { var cmd *exec.Cmd From 0282ebe9844b314cc6160dfa834ba532c826ebee Mon Sep 17 00:00:00 2001 From: Aaron Lehmann Date: Fri, 13 Jan 2023 11:13:23 -0800 Subject: [PATCH 2/3] Propagate sshforward send side connection close PR #3431 caused connections closed on the remote side of a sshforward session to not always result in the local side reading an EOF from the connection. This change restores that behavior by closing the write side of the forwarded connection after reading an EOF from the stream. Since only the write side is being closed, it doesn't prevent the remote side from continuing to read from the connection. Signed-off-by: Aaron Lehmann (cherry picked from commit 8c978cf909068e0f1aacd039a8100f0190a426f1) --- session/sshforward/copy.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/session/sshforward/copy.go b/session/sshforward/copy.go index 936e1826af92..a4a065b46e36 100644 --- a/session/sshforward/copy.go +++ b/session/sshforward/copy.go @@ -23,7 +23,12 @@ func Copy(ctx context.Context, conn io.ReadWriteCloser, stream Stream, closeStre if err := stream.RecvMsg(p); err != nil { if err == io.EOF { // indicates client performed CloseSend, but they may still be - // reading data, so don't close conn yet + // reading data + if conn, ok := conn.(interface { + CloseWrite() error + }); ok { + conn.CloseWrite() + } return nil } conn.Close() From 822a6ec58982b940e39cbe2f8f3dce09810d51aa Mon Sep 17 00:00:00 2001 From: Chris Goller Date: Sun, 15 Jan 2023 12:47:51 -0600 Subject: [PATCH 3/3] fix(tracing): spelling of OTEL_TRACES_EXPORTER value This checks if the OTEL_TRACES_EXPORTER is "otlp." Signed-off-by: Chris Goller (cherry picked from commit de41f3f6018a9db947ca0e900d3052f39e7c2e89) --- util/tracing/detect/otlp.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/tracing/detect/otlp.go b/util/tracing/detect/otlp.go index 2bea75c1c663..aa68f876ef20 100644 --- a/util/tracing/detect/otlp.go +++ b/util/tracing/detect/otlp.go @@ -16,7 +16,7 @@ func init() { } func otlpExporter() (sdktrace.SpanExporter, error) { - set := os.Getenv("OTEL_TRACES_EXPORTER") == "otpl" || os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT") != "" || os.Getenv("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT") != "" + set := os.Getenv("OTEL_TRACES_EXPORTER") == "otlp" || os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT") != "" || os.Getenv("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT") != "" if !set { return nil, nil }