mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-05 02:57:41 +08:00
Merge pull request #1998 from dvdksn/build/docker-driver-errmsgs
build: improve error messages for docker driver
This commit is contained in:
commit
7b049b99c5
@ -391,7 +391,7 @@ func toSolveOpt(ctx context.Context, node builder.Node, multiDriver bool, opt Op
|
|||||||
|
|
||||||
for _, e := range opt.CacheTo {
|
for _, e := range opt.CacheTo {
|
||||||
if e.Type != "inline" && !nodeDriver.Features(ctx)[driver.CacheExport] {
|
if e.Type != "inline" && !nodeDriver.Features(ctx)[driver.CacheExport] {
|
||||||
return nil, nil, notSupported(nodeDriver, driver.CacheExport)
|
return nil, nil, notSupported(driver.CacheExport, nodeDriver, "https://docs.docker.com/go/build-cache-backends/")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -529,7 +529,7 @@ func toSolveOpt(ctx context.Context, node builder.Node, multiDriver bool, opt Op
|
|||||||
// set up exporters
|
// set up exporters
|
||||||
for i, e := range opt.Exports {
|
for i, e := range opt.Exports {
|
||||||
if e.Type == "oci" && !nodeDriver.Features(ctx)[driver.OCIExporter] {
|
if e.Type == "oci" && !nodeDriver.Features(ctx)[driver.OCIExporter] {
|
||||||
return nil, nil, notSupported(nodeDriver, driver.OCIExporter)
|
return nil, nil, notSupported(driver.OCIExporter, nodeDriver, "https://docs.docker.com/go/build-exporters/")
|
||||||
}
|
}
|
||||||
if e.Type == "docker" {
|
if e.Type == "docker" {
|
||||||
features := docker.Features(ctx, e.Attrs["context"])
|
features := docker.Features(ctx, e.Attrs["context"])
|
||||||
@ -555,7 +555,7 @@ func toSolveOpt(ctx context.Context, node builder.Node, multiDriver bool, opt Op
|
|||||||
opt.Exports[i].Output = wrapWriteCloser(w)
|
opt.Exports[i].Output = wrapWriteCloser(w)
|
||||||
}
|
}
|
||||||
} else if !nodeDriver.Features(ctx)[driver.DockerExporter] {
|
} else if !nodeDriver.Features(ctx)[driver.DockerExporter] {
|
||||||
return nil, nil, notSupported(nodeDriver, driver.DockerExporter)
|
return nil, nil, notSupported(driver.DockerExporter, nodeDriver, "https:/docs.docker.com/go/build-exporters/")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if e.Type == "image" && nodeDriver.IsMobyDriver() {
|
if e.Type == "image" && nodeDriver.IsMobyDriver() {
|
||||||
@ -627,7 +627,7 @@ func toSolveOpt(ctx context.Context, node builder.Node, multiDriver bool, opt Op
|
|||||||
pp[i] = platforms.Format(p)
|
pp[i] = platforms.Format(p)
|
||||||
}
|
}
|
||||||
if len(pp) > 1 && !nodeDriver.Features(ctx)[driver.MultiPlatform] {
|
if len(pp) > 1 && !nodeDriver.Features(ctx)[driver.MultiPlatform] {
|
||||||
return nil, nil, notSupported(nodeDriver, driver.MultiPlatform)
|
return nil, nil, notSupported(driver.MultiPlatform, nodeDriver, "https://docs.docker.com/go/build-multi-platform/")
|
||||||
}
|
}
|
||||||
so.FrontendAttrs["platform"] = strings.Join(pp, ",")
|
so.FrontendAttrs["platform"] = strings.Join(pp, ",")
|
||||||
}
|
}
|
||||||
@ -1560,8 +1560,10 @@ func waitContextDeps(ctx context.Context, index int, results *waitmap.Map, so *c
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func notSupported(d driver.Driver, f driver.Feature) error {
|
func notSupported(f driver.Feature, d driver.Driver, docs string) 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())
|
return errors.Errorf(`%s is not supported for the %s driver.
|
||||||
|
Switch to a different driver, or turn on the containerd image store, and try again.
|
||||||
|
Learn more at %s`, f, d.Factory().Name(), docs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func noDefaultLoad() bool {
|
func noDefaultLoad() bool {
|
||||||
|
@ -6,4 +6,4 @@ const OCIExporter Feature = "OCI exporter"
|
|||||||
const DockerExporter Feature = "Docker exporter"
|
const DockerExporter Feature = "Docker exporter"
|
||||||
|
|
||||||
const CacheExport Feature = "Cache export"
|
const CacheExport Feature = "Cache export"
|
||||||
const MultiPlatform Feature = "Multiple platforms"
|
const MultiPlatform Feature = "Multi-platform build"
|
||||||
|
@ -44,6 +44,9 @@ var buildTests = []func(t *testing.T, sb integration.Sandbox){
|
|||||||
testBuildAnnotations,
|
testBuildAnnotations,
|
||||||
testBuildBuildArgNoKey,
|
testBuildBuildArgNoKey,
|
||||||
testBuildLabelNoKey,
|
testBuildLabelNoKey,
|
||||||
|
testBuildCacheExportNotSupported,
|
||||||
|
testBuildOCIExportNotSupported,
|
||||||
|
testBuildMultiPlatformNotSupported,
|
||||||
}
|
}
|
||||||
|
|
||||||
func testBuild(t *testing.T, sb integration.Sandbox) {
|
func testBuild(t *testing.T, sb integration.Sandbox) {
|
||||||
@ -376,3 +379,39 @@ func testBuildLabelNoKey(t *testing.T, sb integration.Sandbox) {
|
|||||||
require.Error(t, err, string(out))
|
require.Error(t, err, string(out))
|
||||||
require.Equal(t, strings.TrimSpace(string(out)), `ERROR: invalid key-value pair "=TEST_STRING": empty key`)
|
require.Equal(t, strings.TrimSpace(string(out)), `ERROR: invalid key-value pair "=TEST_STRING": empty key`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testBuildCacheExportNotSupported(t *testing.T, sb integration.Sandbox) {
|
||||||
|
if sb.Name() != "docker" {
|
||||||
|
t.Skip("skipping test for non-docker workers")
|
||||||
|
}
|
||||||
|
|
||||||
|
dir := createTestProject(t)
|
||||||
|
cmd := buildxCmd(sb, withArgs("build", "--cache-to=type=registry", dir))
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
require.Error(t, err, string(out))
|
||||||
|
require.Contains(t, string(out), "Cache export is not supported")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testBuildOCIExportNotSupported(t *testing.T, sb integration.Sandbox) {
|
||||||
|
if sb.Name() != "docker" {
|
||||||
|
t.Skip("skipping test for non-docker workers")
|
||||||
|
}
|
||||||
|
|
||||||
|
dir := createTestProject(t)
|
||||||
|
cmd := buildxCmd(sb, withArgs("build", fmt.Sprintf("--output=type=oci,dest=%s/result", dir), dir))
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
require.Error(t, err, string(out))
|
||||||
|
require.Contains(t, string(out), "OCI exporter is not supported")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testBuildMultiPlatformNotSupported(t *testing.T, sb integration.Sandbox) {
|
||||||
|
if sb.Name() != "docker" {
|
||||||
|
t.Skip("skipping test for non-docker workers")
|
||||||
|
}
|
||||||
|
|
||||||
|
dir := createTestProject(t)
|
||||||
|
cmd := buildxCmd(sb, withArgs("build", "--platform=linux/amd64,linux/arm64", dir))
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
require.Error(t, err, string(out))
|
||||||
|
require.Contains(t, string(out), "Multi-platform build is not supported")
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user