diff --git a/driver/docker-container/driver.go b/driver/docker-container/driver.go index 38be74a4..b68b00b0 100644 --- a/driver/docker-container/driver.go +++ b/driver/docker-container/driver.go @@ -29,6 +29,7 @@ type Driver struct { factory driver.Factory netMode string image string + env []string } func (d *Driver) Bootstrap(ctx context.Context, l progress.Logger) error { @@ -57,6 +58,7 @@ func (d *Driver) create(ctx context.Context, l progress.SubLogger) error { if d.image != "" { imageName = d.image } + env := d.env if err := l.Wrap("pulling image "+imageName, func() error { rc, err := d.DockerAPI.ImageCreate(ctx, imageName, types.ImageCreateOptions{}) if err != nil { @@ -70,6 +72,7 @@ func (d *Driver) create(ctx context.Context, l progress.SubLogger) error { cfg := &container.Config{ Image: imageName, + Env: env, } if d.InitConfig.BuildkitFlags != nil { cfg.Cmd = d.InitConfig.BuildkitFlags diff --git a/driver/docker-container/factory.go b/driver/docker-container/factory.go index 0b6c7968..f1f65250 100644 --- a/driver/docker-container/factory.go +++ b/driver/docker-container/factory.go @@ -2,6 +2,8 @@ package docker import ( "context" + "fmt" + "strings" "github.com/docker/buildx/driver" dockerclient "github.com/docker/docker/client" @@ -39,14 +41,20 @@ func (f *factory) New(ctx context.Context, cfg driver.InitConfig) (driver.Driver } d := &Driver{factory: f, InitConfig: cfg} for k, v := range cfg.DriverOpts { - switch k { - case "network": + switch { + case k == "network": d.netMode = v if v == "host" { d.InitConfig.BuildkitFlags = append(d.InitConfig.BuildkitFlags, "--allow-insecure-entitlement=network.host") } - case "image": + case k == "image": d.image = v + case strings.HasPrefix(k, "env."): + envName := strings.TrimPrefix(k, "env.") + if envName == "" { + return nil, errors.Errorf("invalid env option %q, expecting env.FOO=bar", k) + } + d.env = append(d.env, fmt.Sprintf("%s=%s", envName, v)) default: return nil, errors.Errorf("invalid driver option %s for docker-container driver", k) }