Skip to content

Commit

Permalink
build: improve error messages for docker driver
Browse files Browse the repository at this point in the history
Signed-off-by: David Karlsson <[email protected]>
  • Loading branch information
dvdksn committed Aug 15, 2023
1 parent e5419ef commit 7f4721b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 6 deletions.
32 changes: 26 additions & 6 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ func toSolveOpt(ctx context.Context, node builder.Node, multiDriver bool, opt Op

for _, e := range opt.CacheTo {
if e.Type != "inline" && !nodeDriver.Features(ctx)[driver.CacheExport] {
return nil, nil, notSupported(nodeDriver, driver.CacheExport)
return nil, nil, cacheExportNotSupported(nodeDriver)
}
}

Expand Down Expand Up @@ -529,7 +529,7 @@ func toSolveOpt(ctx context.Context, node builder.Node, multiDriver bool, opt Op
// set up exporters
for i, e := range opt.Exports {
if e.Type == "oci" && !nodeDriver.Features(ctx)[driver.OCIExporter] {
return nil, nil, notSupported(nodeDriver, driver.OCIExporter)
return nil, nil, exporterNotSupported(nodeDriver, driver.OCIExporter)
}
if e.Type == "docker" {
features := docker.Features(ctx, e.Attrs["context"])
Expand All @@ -555,7 +555,7 @@ func toSolveOpt(ctx context.Context, node builder.Node, multiDriver bool, opt Op
opt.Exports[i].Output = wrapWriteCloser(w)
}
} else if !nodeDriver.Features(ctx)[driver.DockerExporter] {
return nil, nil, notSupported(nodeDriver, driver.DockerExporter)
return nil, nil, exporterNotSupported(nodeDriver, driver.DockerExporter)
}
}
if e.Type == "image" && nodeDriver.IsMobyDriver() {
Expand Down Expand Up @@ -627,7 +627,7 @@ func toSolveOpt(ctx context.Context, node builder.Node, multiDriver bool, opt Op
pp[i] = platforms.Format(p)
}
if len(pp) > 1 && !nodeDriver.Features(ctx)[driver.MultiPlatform] {
return nil, nil, notSupported(nodeDriver, driver.MultiPlatform)
return nil, nil, multiPlatformBuildNotSupported(nodeDriver)
}
so.FrontendAttrs["platform"] = strings.Join(pp, ",")
}
Expand Down Expand Up @@ -1560,8 +1560,28 @@ func waitContextDeps(ctx context.Context, index int, results *waitmap.Map, so *c
return nil
}

func notSupported(d driver.Driver, f driver.Feature) error {
return errors.Errorf("%s feature is currently not supported for %s driver. Please switch to a different driver (eg. \"docker buildx create --use\")", f, d.Factory().Name())
func cacheExportNotSupported(d driver.Driver) error {
return errors.Errorf(`Cache export is not supported for the %s driver.
Switch to a different driver and try again.
Learn more at https://docs.docker.com/go/build-cache-backends/`, d.Factory().Name())
}

func exporterNotSupported(d driver.Driver, f driver.Feature) error {
return errors.Errorf(`%s is not supported for the %s driver.
Switch to a different driver and try again.
Learn more at https://docs.docker.com/go/build-exporters/`, f, d.Factory().Name())
}

func multiPlatformBuildNotSupported(d driver.Driver) error {
return errors.Errorf(`Multi-platform builds is not supported for the %s driver without the containerd image store.
Switch to a different driver, or turn on the containerd image store, and try again.
Learn more at https://docs.docker.com/go/build-multi-platform/`, d.Factory().Name())
}

func noDefaultLoad() bool {
Expand Down
30 changes: 30 additions & 0 deletions tests/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var buildTests = []func(t *testing.T, sb integration.Sandbox){
testBuildMobyFromLocalImage,
testBuildDetailsLink,
testBuildProgress,
testBuildDockerWorkerErrors,
}

func testBuild(t *testing.T, sb integration.Sandbox) {
Expand Down Expand Up @@ -313,3 +314,32 @@ func testBuildProgress(t *testing.T, sb integration.Sandbox) {
require.Contains(t, string(plainOutput), "[internal] load build definition from Dockerfile")
require.Contains(t, string(plainOutput), "[base 1/3] FROM docker.io/library/busybox:latest")
}

func testBuildDockerWorkerErrors(t *testing.T, sb integration.Sandbox) {
if !isDockerWorker(sb) {
t.Skip("skipping test for non-docker workers")
}

dir := createTestProject(t)

// registry cache backend
cmd := buildxCmd(sb, withArgs("build", "--cache-to=type=registry", dir))
out, err := cmd.CombinedOutput()
require.NoError(t, err)

Check failure on line 328 in tests/build.go

View workflow job for this annotation

GitHub Actions / test (docker, ./tests)

Failed: tests/TestIntegration/TestBuildDockerWorkerErrors/worker=docker

=== RUN TestIntegration/TestBuildDockerWorkerErrors/worker=docker === PAUSE TestIntegration/TestBuildDockerWorkerErrors/worker=docker === CONT TestIntegration/TestBuildDockerWorkerErrors/worker=docker build.go:328: Error Trace: /src/tests/build.go:328 /src/vendor/github.com/moby/buildkit/util/testutil/integration/run.go:91 /src/vendor/github.com/moby/buildkit/util/testutil/integration/run.go:205 Error: Received unexpected error: exit status 1 Test: TestIntegration/TestBuildDockerWorkerErrors/worker=docker sandbox.go:140: stdout: /usr/bin/dockerd sandbox.go:140: stderr: /usr/bin/dockerd sandbox.go:143: > startCmd 2023-08-15 09:02:57.69202393 +0000 UTC m=+33.369953972 /usr/bin/dockerd --data-root /tmp/integration300998485/dt22ya2frxvv5/root --exec-root /tmp/dxr/dt22ya2frxvv5 --pidfile /tmp/integration300998485/dt22ya2frxvv5/docker.pid --containerd-namespace dt22ya2frxvv5 --containerd-plugins-namespace dt22ya2frxvv5p --host unix:///tmp/docker-integration/dt22ya2frxvv5.sock --config-file /tmp/integration300998485/daemon.json --userland-proxy=false --tls=false --debug sandbox.go:143: time="2023-08-15T09:02:57.734788618Z" level=info msg="Starting up" sandbox.go:143: time="2023-08-15T09:02:57.736000019Z" level=warning msg="could not change group /tmp/docker-integration/dt22ya2frxvv5.sock to docker: group docker not found" sandbox.go:143: time="2023-08-15T09:02:57.736213137Z" level=debug msg="Listener created for HTTP on unix (/tmp/docker-integration/dt22ya2frxvv5.sock)" sandbox.go:143: time="2023-08-15T09:02:57.736233239Z" level=info msg="containerd not running, starting managed containerd" sandbox.go:143: time="2023-08-15T09:02:57.736924097Z" level=info msg="started new containerd process" address=/tmp/dxr/dt22ya2frxvv5/containerd/containerd.sock module=libcontainerd pid=8149 sandbox.go:143: time="2023-08-15T09:02:57.755115423Z" level=info msg="starting containerd" revision=1677a17964311325ed1c31e2c0a3589ce6d5c30d version=v1.7.1 sandbox.go:143: time="2023-08-15T09:02:57.778117653Z" level=info msg="loading plugin \"io.containerd.snapshotter.v1.aufs\"..." type=io.containerd.snapshotter.v1 sandbox.go:143: time="2023-08-15T09:02:57.779036330Z" level=info msg="skip loading plugin \"io.containerd.snapshotter.v1.aufs\"..." error="aufs is not supported (modprobe aufs failed: exit status 1 \"modprobe: can't change directory to '/lib/modules': No such file or directory\\n\"): skip plugin" type=io.containerd.snapshotter.v1 sandbox.go:143: time="2023-08-15T09:02:57.779066832Z" level=info msg="loading plugin \"io.containerd.content.v1.content\"..." type=io.containerd.content.v1 sandbox.go:143: time="2023-08-15T09:02:57.779219545Z" level=info msg="loading plugin \"io.containerd.snapshotter.v1.native\"..." type=io.containerd.snapshotter.v1 sandbox.go:143: time="2023-08-15T09:02:57.779314753Z" level=info msg="loading plugin \"io.containerd.snapshotter.v1.overlayfs\"..." type=io.containerd.snapshotter.v1 sandbox.go:143: time="2023-08-15T09:02:57.779558074Z" level=info msg="loading plugin \"io.containerd.snapshotter.v1.devmapper\"..." type=io.containerd.snapshotter.v1 sandbox.go:143: time="2023-08-15T09:02:57.779581576Z" level=warning msg="failed to load plugin io.containerd.snapshotter.v1.devmapper" error="devmapper not configured" sandbox.go:143: time="2023-08-15T09:02:57.779613178Z" level=info msg="loading plugin \"io.containerd.snapshotter.v1.zfs\"..." type=io.containerd.snapshotter.v1 sandbox.go:143: time="2023-08-15T09:02:57.779766291Z" level=info msg="skip loading plugin \"io.containerd.snapshotter.v1.zfs\"..." error="path /tmp/integration300998485/dt22ya2frxvv5/root/containerd/daemon/io.containerd.snapshotter.v1.zfs must be a zfs filesystem to be used with the zfs snapshotter: skip plugin" type=io.containerd.snapshotter.v1 sandbox.go:143: time="2023-08-15T09:02:57.779787893Z" level=info msg="loading plugin \"io.containerd.metadata.v1.bolt\"..."

Check failure on line 328 in tests/build.go

View workflow job for this annotation

GitHub Actions / test (docker\+containerd, ./tests)

Failed: tests/TestIntegration/TestBuildDockerWorkerErrors/worker=docker+containerd

=== RUN TestIntegration/TestBuildDockerWorkerErrors/worker=docker+containerd === PAUSE TestIntegration/TestBuildDockerWorkerErrors/worker=docker+containerd === CONT TestIntegration/TestBuildDockerWorkerErrors/worker=docker+containerd build.go:328: Error Trace: /src/tests/build.go:328 /src/vendor/github.com/moby/buildkit/util/testutil/integration/run.go:91 /src/vendor/github.com/moby/buildkit/util/testutil/integration/run.go:205 Error: Received unexpected error: exit status 1 Test: TestIntegration/TestBuildDockerWorkerErrors/worker=docker+containerd sandbox.go:140: stdout: /usr/bin/dockerd sandbox.go:140: stderr: /usr/bin/dockerd sandbox.go:143: > startCmd 2023-08-15 09:02:20.225061783 +0000 UTC m=+31.950926869 /usr/bin/dockerd --data-root /tmp/integration387465065/drj12g7ohh1je/root --exec-root /tmp/dxr/drj12g7ohh1je --pidfile /tmp/integration387465065/drj12g7ohh1je/docker.pid --containerd-namespace drj12g7ohh1je --containerd-plugins-namespace drj12g7ohh1jep --host unix:///tmp/docker-integration/drj12g7ohh1je.sock --config-file /tmp/integration387465065/daemon.json --userland-proxy=false --tls=false --debug sandbox.go:143: time="2023-08-15T09:02:20.260363572Z" level=info msg="Starting up" sandbox.go:143: time="2023-08-15T09:02:20.261221335Z" level=warning msg="could not change group /tmp/docker-integration/drj12g7ohh1je.sock to docker: group docker not found" sandbox.go:143: time="2023-08-15T09:02:20.261374246Z" level=debug msg="Listener created for HTTP on unix (/tmp/docker-integration/drj12g7ohh1je.sock)" sandbox.go:143: time="2023-08-15T09:02:20.261388447Z" level=info msg="containerd not running, starting managed containerd" sandbox.go:143: time="2023-08-15T09:02:20.261890184Z" level=info msg="started new containerd process" address=/tmp/dxr/drj12g7ohh1je/containerd/containerd.sock module=libcontainerd pid=7968 sandbox.go:143: time="2023-08-15T09:02:20.277704944Z" level=info msg="starting containerd" revision=1677a17964311325ed1c31e2c0a3589ce6d5c30d version=v1.7.1 sandbox.go:143: time="2023-08-15T09:02:20.300273399Z" level=info msg="loading plugin \"io.containerd.snapshotter.v1.aufs\"..." type=io.containerd.snapshotter.v1 sandbox.go:143: time="2023-08-15T09:02:20.300874043Z" level=info msg="skip loading plugin \"io.containerd.snapshotter.v1.aufs\"..." error="aufs is not supported (modprobe aufs failed: exit status 1 \"modprobe: can't change directory to '/lib/modules': No such file or directory\\n\"): skip plugin" type=io.containerd.snapshotter.v1 sandbox.go:143: time="2023-08-15T09:02:20.300896945Z" level=info msg="loading plugin \"io.containerd.content.v1.content\"..." type=io.containerd.content.v1 sandbox.go:143: time="2023-08-15T09:02:20.300987351Z" level=info msg="loading plugin \"io.containerd.snapshotter.v1.native\"..." type=io.containerd.snapshotter.v1 sandbox.go:143: time="2023-08-15T09:02:20.301051656Z" level=info msg="loading plugin \"io.containerd.snapshotter.v1.overlayfs\"..." type=io.containerd.snapshotter.v1 sandbox.go:143: time="2023-08-15T09:02:20.301212968Z" level=info msg="loading plugin \"io.containerd.snapshotter.v1.devmapper\"..." type=io.containerd.snapshotter.v1 sandbox.go:143: time="2023-08-15T09:02:20.301233869Z" level=warning msg="failed to load plugin io.containerd.snapshotter.v1.devmapper" error="devmapper not configured" sandbox.go:143: time="2023-08-15T09:02:20.301244070Z" level=info msg="loading plugin \"io.containerd.snapshotter.v1.zfs\"..." type=io.containerd.snapshotter.v1 sandbox.go:143: time="2023-08-15T09:02:20.301352178Z" level=info msg="skip loading plugin \"io.containerd.snapshotter.v1.zfs\"..." error="path /tmp/integration387465065/drj12g7ohh1je/root/containerd/daemon/io.containerd.snapshotter.v1.zfs must be a zfs filesystem to be used with the zfs snapshotter: skip plugin" type=io.containerd.snapshotter.v1 sandbox.go:143: time="2023-08-15T09:02:20.301368579Z" level=info msg="loading
require.Contains(t, string(out), "Cache export is not supported")
require.Contains(t, string(out), "https://docs.docker.com/go/build-cache-backends/")

// oci exporter
cmd = buildxCmd(sb, withArgs("build", (fmt.Sprintf("--output=type=oci,dest=%s/result", dir)), dir))
out, err = cmd.CombinedOutput()
require.NoError(t, err)
require.Contains(t, string(out), "OCI exporter feature is not supported")
require.Contains(t, string(out), "https://docs.docker.com/go/build-exporters/")

// multi-platform
cmd = buildxCmd(sb, withArgs("build", "--platform=linux/amd64,linux/arm64", dir))
out, err = cmd.CombinedOutput()
require.NoError(t, err)
require.Contains(t, string(out), "Multi-platform builds is not supported")
require.Contains(t, string(out), "https://docs.docker.com/go/build-multi-platform/")
}

0 comments on commit 7f4721b

Please sign in to comment.