mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
driver: add feature testing
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
@ -50,7 +50,8 @@ func Build(ctx context.Context, drivers []driver.Driver, opt map[string]Options,
|
||||
}
|
||||
|
||||
pwOld := pw
|
||||
c, pw, err := driver.Boot(ctx, drivers[0], pw)
|
||||
d := drivers[0]
|
||||
c, pw, err := driver.Boot(ctx, d, pw)
|
||||
if err != nil {
|
||||
close(pwOld.Status())
|
||||
<-pwOld.Done()
|
||||
@ -94,6 +95,28 @@ func Build(ctx context.Context, drivers []driver.Driver, opt map[string]Options,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for i, e := range opt.Exports {
|
||||
if e.Type == "oci" && !d.Features()[driver.OCIExporter] {
|
||||
return nil, notSupported(d, driver.OCIExporter)
|
||||
}
|
||||
if e.Type == "docker" && e.Output != nil && !d.Features()[driver.DockerExporter] {
|
||||
return nil, notSupported(d, driver.DockerExporter)
|
||||
}
|
||||
if e.Type == "image" {
|
||||
if _, ok := d.(interface {
|
||||
IsDefaultMobyDriver()
|
||||
}); ok {
|
||||
opt.Exports[i].Type = "moby"
|
||||
if e.Attrs["push"] != "" {
|
||||
if ok, _ := strconv.ParseBool(e.Attrs["push"]); ok {
|
||||
return nil, errors.Errorf("auto-push is currently not implemented for moby driver")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: handle loading to docker daemon
|
||||
|
||||
so.Exports = opt.Exports
|
||||
@ -124,6 +147,9 @@ func Build(ctx context.Context, drivers []driver.Driver, opt map[string]Options,
|
||||
for i, p := range opt.Platforms {
|
||||
pp[i] = platforms.Format(p)
|
||||
}
|
||||
if len(pp) > 1 && !d.Features()[driver.MultiPlatform] {
|
||||
return nil, notSupported(d, driver.MultiPlatform)
|
||||
}
|
||||
so.FrontendAttrs["platform"] = strings.Join(pp, ",")
|
||||
}
|
||||
|
||||
@ -180,3 +206,7 @@ func LoadInputs(inp Inputs, target *client.SolveOpt) error {
|
||||
target.FrontendAttrs["filename"] = filepath.Base(inp.DockerfilePath)
|
||||
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 new\")", f, d.Factory().Name())
|
||||
}
|
||||
|
Reference in New Issue
Block a user