diff --git a/client/client_test.go b/client/client_test.go index d90e6fe8f163..9f41cad1ad35 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -1996,7 +1996,6 @@ func testOCIExporter(t *testing.T, sb integration.Sandbox) { } func testFrontendMetadataReturn(t *testing.T, sb integration.Sandbox) { - integration.SkipIfDockerd(t, sb, "oci exporter") requiresLinux(t) c, err := New(sb.Context(), sb.Address()) require.NoError(t, err) @@ -2010,14 +2009,24 @@ func testFrontendMetadataReturn(t *testing.T, sb integration.Sandbox) { return res, nil } - res, err := c.Build(sb.Context(), SolveOpt{ - Exports: []ExportEntry{ - { - Type: ExporterOCI, - Attrs: map[string]string{}, - Output: fixedWriteCloser(nopWriteCloser{io.Discard}), + var exports []ExportEntry + if integration.IsTestDockerd() { + exports = []ExportEntry{{ + Type: "moby", + Attrs: map[string]string{ + "name": "reg.dummy:5000/buildkit/test:latest", }, - }, + }} + } else { + exports = []ExportEntry{{ + Type: ExporterOCI, + Attrs: map[string]string{}, + Output: fixedWriteCloser(nopWriteCloser{io.Discard}), + }} + } + + res, err := c.Build(sb.Context(), SolveOpt{ + Exports: exports, }, "", frontend, nil) require.NoError(t, err) require.Contains(t, res.ExporterResponse, "frontend.returned") @@ -2127,8 +2136,6 @@ func testExporterTargetExists(t *testing.T, sb integration.Sandbox) { } func testTarExporterWithSocket(t *testing.T, sb integration.Sandbox) { - integration.SkipIfDockerd(t, sb, "tar exporter") - requiresLinux(t) c, err := New(sb.Context(), sb.Address()) require.NoError(t, err) @@ -2153,8 +2160,6 @@ func testTarExporterWithSocket(t *testing.T, sb integration.Sandbox) { } func testTarExporterWithSocketCopy(t *testing.T, sb integration.Sandbox) { - integration.SkipIfDockerd(t, sb, "tar exporter") - requiresLinux(t) c, err := New(sb.Context(), sb.Address()) require.NoError(t, err) @@ -5536,7 +5541,6 @@ func testRelativeMountpoint(t *testing.T, sb integration.Sandbox) { // moby/buildkit#2476 func testBuildInfoExporter(t *testing.T, sb integration.Sandbox) { - integration.SkipIfDockerd(t, sb, "direct push") requiresLinux(t) c, err := New(sb.Context(), sb.Address()) require.NoError(t, err) @@ -5556,22 +5560,24 @@ func testBuildInfoExporter(t *testing.T, sb integration.Sandbox) { }) } - registry, err := sb.NewRegistry() - if errors.Is(err, integration.ErrRequirements) { - t.Skip(err.Error()) + var exports []ExportEntry + if integration.IsTestDockerd() { + exports = []ExportEntry{{ + Type: "moby", + Attrs: map[string]string{ + "name": "reg.dummy:5000/buildkit/test:latest", + }, + }} + } else { + exports = []ExportEntry{{ + Type: ExporterOCI, + Attrs: map[string]string{}, + Output: fixedWriteCloser(nopWriteCloser{io.Discard}), + }} } - require.NoError(t, err) res, err := c.Build(sb.Context(), SolveOpt{ - Exports: []ExportEntry{ - { - Type: ExporterImage, - Attrs: map[string]string{ - "name": registry + "/buildkit/test-buildinfo:latest", - "push": "true", - }, - }, - }, + Exports: exports, }, "", frontend, nil) require.NoError(t, err) diff --git a/frontend/dockerfile/dockerfile_buildinfo_test.go b/frontend/dockerfile/dockerfile_buildinfo_test.go index 4034298680da..ae06ea094ae9 100644 --- a/frontend/dockerfile/dockerfile_buildinfo_test.go +++ b/frontend/dockerfile/dockerfile_buildinfo_test.go @@ -5,6 +5,7 @@ import ( "encoding/base64" "encoding/json" "fmt" + "io" "net/http" "net/http/httptest" "os" @@ -43,7 +44,6 @@ func init() { // moby/buildkit#2311 func testBuildInfoSources(t *testing.T, sb integration.Sandbox) { - integration.SkipIfDockerd(t, sb, "oci export") f := getFrontend(t, sb) f.RequiresBuildctl(t) @@ -75,25 +75,28 @@ COPY --from=alpine /bin/busybox /alpine-busybox server := httptest.NewServer(http.FileServer(http.Dir(filepath.Join(gitDir)))) defer server.Close() - destDir, err := os.MkdirTemp("", "buildkit") - require.NoError(t, err) - defer os.RemoveAll(destDir) - - out := filepath.Join(destDir, "out.tar") - outW, err := os.Create(out) - require.NoError(t, err) - c, err := client.New(sb.Context(), sb.Address()) require.NoError(t, err) defer c.Close() - res, err := f.Solve(sb.Context(), c, client.SolveOpt{ - Exports: []client.ExportEntry{ - { - Type: client.ExporterOCI, - Output: fixedWriteCloser(outW), + var exports []client.ExportEntry + if integration.IsTestDockerd() { + exports = []client.ExportEntry{{ + Type: "moby", + Attrs: map[string]string{ + "name": "reg.dummy:5000/buildkit/test:latest", }, - }, + }} + } else { + exports = []client.ExportEntry{{ + Type: client.ExporterOCI, + Attrs: map[string]string{}, + Output: fixedWriteCloser(nopWriteCloser{io.Discard}), + }} + } + + res, err := f.Solve(sb.Context(), c, client.SolveOpt{ + Exports: exports, FrontendAttrs: map[string]string{ builder.DefaultLocalNameContext: server.URL + "/.git#buildinfo", }, @@ -128,7 +131,6 @@ COPY --from=alpine /bin/busybox /alpine-busybox } func testBuildInfoSourcesNoop(t *testing.T, sb integration.Sandbox) { - integration.SkipIfDockerd(t, sb, "oci export") f := getFrontend(t, sb) f.RequiresBuildctl(t) @@ -146,21 +148,24 @@ FROM busybox:latest require.NoError(t, err) defer c.Close() - destDir, err := os.MkdirTemp("", "buildkit") - require.NoError(t, err) - defer os.RemoveAll(destDir) - - out := filepath.Join(destDir, "out.tar") - outW, err := os.Create(out) - require.NoError(t, err) + var exports []client.ExportEntry + if integration.IsTestDockerd() { + exports = []client.ExportEntry{{ + Type: "moby", + Attrs: map[string]string{ + "name": "reg.dummy:5000/buildkit/test:latest", + }, + }} + } else { + exports = []client.ExportEntry{{ + Type: client.ExporterOCI, + Attrs: map[string]string{}, + Output: fixedWriteCloser(nopWriteCloser{io.Discard}), + }} + } res, err := f.Solve(sb.Context(), c, client.SolveOpt{ - Exports: []client.ExportEntry{ - { - Type: client.ExporterOCI, - Output: fixedWriteCloser(outW), - }, - }, + Exports: exports, LocalDirs: map[string]string{ builder.DefaultLocalNameDockerfile: dir, builder.DefaultLocalNameContext: dir, @@ -186,7 +191,6 @@ FROM busybox:latest // moby/buildkit#2476 func testBuildInfoAttrs(t *testing.T, sb integration.Sandbox) { - integration.SkipIfDockerd(t, sb, "oci export") f := getFrontend(t, sb) f.RequiresBuildctl(t) @@ -206,24 +210,27 @@ RUN echo $foo require.NoError(t, err) defer c.Close() - destDir, err := os.MkdirTemp("", "buildkit") - require.NoError(t, err) - defer os.RemoveAll(destDir) - - out := filepath.Join(destDir, "out.tar") - outW, err := os.Create(out) - require.NoError(t, err) + var exports []client.ExportEntry + if integration.IsTestDockerd() { + exports = []client.ExportEntry{{ + Type: "moby", + Attrs: map[string]string{ + "name": "reg.dummy:5000/buildkit/test:latest", + }, + }} + } else { + exports = []client.ExportEntry{{ + Type: client.ExporterOCI, + Attrs: map[string]string{}, + Output: fixedWriteCloser(nopWriteCloser{io.Discard}), + }} + } res, err := f.Solve(sb.Context(), c, client.SolveOpt{ FrontendAttrs: map[string]string{ "build-arg:foo": "bar", }, - Exports: []client.ExportEntry{ - { - Type: client.ExporterOCI, - Output: fixedWriteCloser(outW), - }, - }, + Exports: exports, LocalDirs: map[string]string{ builder.DefaultLocalNameDockerfile: dir, builder.DefaultLocalNameContext: dir, @@ -245,7 +252,7 @@ RUN echo $foo // moby/buildkit#2476 func testBuildInfoMultiPlatform(t *testing.T, sb integration.Sandbox) { - integration.SkipIfDockerd(t, sb, "oci export") + integration.SkipIfDockerd(t, sb, "multi-platform") f := getFrontend(t, sb) f.RequiresBuildctl(t) @@ -266,14 +273,6 @@ ADD https://raw.githubusercontent.com/moby/moby/master/README.md / require.NoError(t, err) defer c.Close() - destDir, err := os.MkdirTemp("", "buildkit") - require.NoError(t, err) - defer os.RemoveAll(destDir) - - out := filepath.Join(destDir, "out.tar") - outW, err := os.Create(out) - require.NoError(t, err) - platforms := []string{"linux/amd64", "linux/arm64"} res, err := f.Solve(sb.Context(), c, client.SolveOpt{ @@ -284,7 +283,7 @@ ADD https://raw.githubusercontent.com/moby/moby/master/README.md / Exports: []client.ExportEntry{ { Type: client.ExporterOCI, - Output: fixedWriteCloser(outW), + Output: fixedWriteCloser(nopWriteCloser{io.Discard}), }, }, LocalDirs: map[string]string{ @@ -320,7 +319,6 @@ ADD https://raw.githubusercontent.com/moby/moby/master/README.md / } func testBuildInfoImageContext(t *testing.T, sb integration.Sandbox) { - integration.SkipIfDockerd(t, sb, "oci export") f := getFrontend(t, sb) f.RequiresBuildctl(t) @@ -341,25 +339,28 @@ COPY --from=base /out / require.NoError(t, err) defer c.Close() - destDir, err := os.MkdirTemp("", "buildkit") - require.NoError(t, err) - defer os.RemoveAll(destDir) - - out := filepath.Join(destDir, "out.tar") - outW, err := os.Create(out) - require.NoError(t, err) + var exports []client.ExportEntry + if integration.IsTestDockerd() { + exports = []client.ExportEntry{{ + Type: "moby", + Attrs: map[string]string{ + "name": "reg.dummy:5000/buildkit/test:latest", + }, + }} + } else { + exports = []client.ExportEntry{{ + Type: client.ExporterOCI, + Attrs: map[string]string{}, + Output: fixedWriteCloser(nopWriteCloser{io.Discard}), + }} + } res, err := f.Solve(sb.Context(), c, client.SolveOpt{ FrontendAttrs: map[string]string{ "build-arg:foo": "bar", "context:busybox": "docker-image://alpine", }, - Exports: []client.ExportEntry{ - { - Type: client.ExporterOCI, - Output: fixedWriteCloser(outW), - }, - }, + Exports: exports, LocalDirs: map[string]string{ builder.DefaultLocalNameDockerfile: dir, builder.DefaultLocalNameContext: dir, @@ -388,7 +389,6 @@ COPY --from=base /out / } func testBuildInfoLocalContext(t *testing.T, sb integration.Sandbox) { - integration.SkipIfDockerd(t, sb, "oci export") f := getFrontend(t, sb) f.RequiresBuildctl(t) @@ -409,14 +409,6 @@ COPY --from=base /o* / require.NoError(t, err) defer c.Close() - destDir, err := os.MkdirTemp("", "buildkit") - require.NoError(t, err) - defer os.RemoveAll(destDir) - - out := filepath.Join(destDir, "out.tar") - outW, err := os.Create(out) - require.NoError(t, err) - outf := []byte(`dummy-result`) dir2, err := tmpdir( @@ -427,17 +419,28 @@ COPY --from=base /o* / require.NoError(t, err) defer os.RemoveAll(dir2) + var exports []client.ExportEntry + if integration.IsTestDockerd() { + exports = []client.ExportEntry{{ + Type: "moby", + Attrs: map[string]string{ + "name": "reg.dummy:5000/buildkit/test:latest", + }, + }} + } else { + exports = []client.ExportEntry{{ + Type: client.ExporterOCI, + Attrs: map[string]string{}, + Output: fixedWriteCloser(nopWriteCloser{io.Discard}), + }} + } + res, err := f.Solve(sb.Context(), c, client.SolveOpt{ FrontendAttrs: map[string]string{ "build-arg:foo": "bar", "context:base": "local:basedir", }, - Exports: []client.ExportEntry{ - { - Type: client.ExporterOCI, - Output: fixedWriteCloser(outW), - }, - }, + Exports: exports, LocalDirs: map[string]string{ builder.DefaultLocalNameDockerfile: dir, builder.DefaultLocalNameContext: dir,