Skip to content

Commit

Permalink
integration: fix more tests for dockerd
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Mar 21, 2022
1 parent f484793 commit 7d5986a
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 108 deletions.
58 changes: 32 additions & 26 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down
167 changes: 85 additions & 82 deletions frontend/dockerfile/dockerfile_buildinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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",
},
Expand Down Expand Up @@ -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)

Expand All @@ -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,
Expand All @@ -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)

Expand All @@ -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,
Expand All @@ -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)

Expand All @@ -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{
Expand All @@ -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{
Expand Down Expand Up @@ -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)

Expand All @@ -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,
Expand Down Expand Up @@ -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)

Expand All @@ -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(
Expand All @@ -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,
Expand Down

0 comments on commit 7d5986a

Please sign in to comment.