Skip to content

Commit 7f4721b

Browse files
committed
build: improve error messages for docker driver
Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
1 parent e5419ef commit 7f4721b

File tree

2 files changed

+56
-6
lines changed

2 files changed

+56
-6
lines changed

build/build.go

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ func toSolveOpt(ctx context.Context, node builder.Node, multiDriver bool, opt Op
391391

392392
for _, e := range opt.CacheTo {
393393
if e.Type != "inline" && !nodeDriver.Features(ctx)[driver.CacheExport] {
394-
return nil, nil, notSupported(nodeDriver, driver.CacheExport)
394+
return nil, nil, cacheExportNotSupported(nodeDriver)
395395
}
396396
}
397397

@@ -529,7 +529,7 @@ func toSolveOpt(ctx context.Context, node builder.Node, multiDriver bool, opt Op
529529
// set up exporters
530530
for i, e := range opt.Exports {
531531
if e.Type == "oci" && !nodeDriver.Features(ctx)[driver.OCIExporter] {
532-
return nil, nil, notSupported(nodeDriver, driver.OCIExporter)
532+
return nil, nil, exporterNotSupported(nodeDriver, driver.OCIExporter)
533533
}
534534
if e.Type == "docker" {
535535
features := docker.Features(ctx, e.Attrs["context"])
@@ -555,7 +555,7 @@ func toSolveOpt(ctx context.Context, node builder.Node, multiDriver bool, opt Op
555555
opt.Exports[i].Output = wrapWriteCloser(w)
556556
}
557557
} else if !nodeDriver.Features(ctx)[driver.DockerExporter] {
558-
return nil, nil, notSupported(nodeDriver, driver.DockerExporter)
558+
return nil, nil, exporterNotSupported(nodeDriver, driver.DockerExporter)
559559
}
560560
}
561561
if e.Type == "image" && nodeDriver.IsMobyDriver() {
@@ -627,7 +627,7 @@ func toSolveOpt(ctx context.Context, node builder.Node, multiDriver bool, opt Op
627627
pp[i] = platforms.Format(p)
628628
}
629629
if len(pp) > 1 && !nodeDriver.Features(ctx)[driver.MultiPlatform] {
630-
return nil, nil, notSupported(nodeDriver, driver.MultiPlatform)
630+
return nil, nil, multiPlatformBuildNotSupported(nodeDriver)
631631
}
632632
so.FrontendAttrs["platform"] = strings.Join(pp, ",")
633633
}
@@ -1560,8 +1560,28 @@ func waitContextDeps(ctx context.Context, index int, results *waitmap.Map, so *c
15601560
return nil
15611561
}
15621562

1563-
func notSupported(d driver.Driver, f driver.Feature) error {
1564-
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())
1563+
func cacheExportNotSupported(d driver.Driver) error {
1564+
return errors.Errorf(`Cache export is not supported for the %s driver.
1565+
1566+
Switch to a different driver and try again.
1567+
1568+
Learn more at https://docs.docker.com/go/build-cache-backends/`, d.Factory().Name())
1569+
}
1570+
1571+
func exporterNotSupported(d driver.Driver, f driver.Feature) error {
1572+
return errors.Errorf(`%s is not supported for the %s driver.
1573+
1574+
Switch to a different driver and try again.
1575+
1576+
Learn more at https://docs.docker.com/go/build-exporters/`, f, d.Factory().Name())
1577+
}
1578+
1579+
func multiPlatformBuildNotSupported(d driver.Driver) error {
1580+
return errors.Errorf(`Multi-platform builds is not supported for the %s driver without the containerd image store.
1581+
1582+
Switch to a different driver, or turn on the containerd image store, and try again.
1583+
1584+
Learn more at https://docs.docker.com/go/build-multi-platform/`, d.Factory().Name())
15651585
}
15661586

15671587
func noDefaultLoad() bool {

tests/build.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var buildTests = []func(t *testing.T, sb integration.Sandbox){
4040
testBuildMobyFromLocalImage,
4141
testBuildDetailsLink,
4242
testBuildProgress,
43+
testBuildDockerWorkerErrors,
4344
}
4445

4546
func testBuild(t *testing.T, sb integration.Sandbox) {
@@ -313,3 +314,32 @@ func testBuildProgress(t *testing.T, sb integration.Sandbox) {
313314
require.Contains(t, string(plainOutput), "[internal] load build definition from Dockerfile")
314315
require.Contains(t, string(plainOutput), "[base 1/3] FROM docker.io/library/busybox:latest")
315316
}
317+
318+
func testBuildDockerWorkerErrors(t *testing.T, sb integration.Sandbox) {
319+
if !isDockerWorker(sb) {
320+
t.Skip("skipping test for non-docker workers")
321+
}
322+
323+
dir := createTestProject(t)
324+
325+
// registry cache backend
326+
cmd := buildxCmd(sb, withArgs("build", "--cache-to=type=registry", dir))
327+
out, err := cmd.CombinedOutput()
328+
require.NoError(t, err)
329+
require.Contains(t, string(out), "Cache export is not supported")
330+
require.Contains(t, string(out), "https://docs.docker.com/go/build-cache-backends/")
331+
332+
// oci exporter
333+
cmd = buildxCmd(sb, withArgs("build", (fmt.Sprintf("--output=type=oci,dest=%s/result", dir)), dir))
334+
out, err = cmd.CombinedOutput()
335+
require.NoError(t, err)
336+
require.Contains(t, string(out), "OCI exporter feature is not supported")
337+
require.Contains(t, string(out), "https://docs.docker.com/go/build-exporters/")
338+
339+
// multi-platform
340+
cmd = buildxCmd(sb, withArgs("build", "--platform=linux/amd64,linux/arm64", dir))
341+
out, err = cmd.CombinedOutput()
342+
require.NoError(t, err)
343+
require.Contains(t, string(out), "Multi-platform builds is not supported")
344+
require.Contains(t, string(out), "https://docs.docker.com/go/build-multi-platform/")
345+
}

0 commit comments

Comments
 (0)