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 <35727626+dvdksn@users.noreply.github.com>
  • Loading branch information
dvdksn committed Aug 10, 2023
1 parent e5419ef commit 6ed6e77
Showing 1 changed file with 26 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 currently not supported for the %s driver.
Switch to a different driver, or use inline cache, 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 currently supported for the %s driver.
Switch to a different driver, or a different output type, 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 currently 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

0 comments on commit 6ed6e77

Please sign in to comment.