Support environment variables in docker-container driver

Fixes #169

Signed-off-by: Sune Keller <absukl@almbrand.dk>
pull/170/head
Sune Keller 5 years ago committed by Sune Keller
parent 43edd6b77e
commit fd44accc79

@ -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

@ -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)
}

Loading…
Cancel
Save