From afd821010dc8774635dac39c374978ecea901e79 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Wed, 31 Jul 2019 18:19:03 -0700 Subject: [PATCH] docker-container: allow setting custom buildkit image Signed-off-by: Tonis Tiigi --- driver/docker-container/driver.go | 13 +++++++++---- driver/docker-container/factory.go | 4 +++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/driver/docker-container/driver.go b/driver/docker-container/driver.go index ecdd7199..38be74a4 100644 --- a/driver/docker-container/driver.go +++ b/driver/docker-container/driver.go @@ -22,12 +22,13 @@ import ( "github.com/pkg/errors" ) -var buildkitImage = "moby/buildkit:master" // TODO: make this verified and configuratble +var defaultBuildkitImage = "moby/buildkit:buildx-stable-1" // TODO: make this verified type Driver struct { driver.InitConfig factory driver.Factory netMode string + image string } func (d *Driver) Bootstrap(ctx context.Context, l progress.Logger) error { @@ -52,8 +53,12 @@ func (d *Driver) Bootstrap(ctx context.Context, l progress.Logger) error { } func (d *Driver) create(ctx context.Context, l progress.SubLogger) error { - if err := l.Wrap("pulling image "+buildkitImage, func() error { - rc, err := d.DockerAPI.ImageCreate(ctx, buildkitImage, types.ImageCreateOptions{}) + imageName := defaultBuildkitImage + if d.image != "" { + imageName = d.image + } + if err := l.Wrap("pulling image "+imageName, func() error { + rc, err := d.DockerAPI.ImageCreate(ctx, imageName, types.ImageCreateOptions{}) if err != nil { return err } @@ -64,7 +69,7 @@ func (d *Driver) create(ctx context.Context, l progress.SubLogger) error { } cfg := &container.Config{ - Image: buildkitImage, + Image: imageName, } 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 37db8268..0b6c7968 100644 --- a/driver/docker-container/factory.go +++ b/driver/docker-container/factory.go @@ -45,8 +45,10 @@ func (f *factory) New(ctx context.Context, cfg driver.InitConfig) (driver.Driver if v == "host" { d.InitConfig.BuildkitFlags = append(d.InitConfig.BuildkitFlags, "--allow-insecure-entitlement=network.host") } + case "image": + d.image = v default: - return nil, errors.Errorf("invalid driver option %s for docker-container driver") + return nil, errors.Errorf("invalid driver option %s for docker-container driver", k) } }