docker-container: restart-policy opt

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
pull/1271/head
CrazyMax 2 years ago
parent 04804ff355
commit 81ad6b35a7
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7

@ -153,6 +153,7 @@ No driver options.
- `image=IMAGE` - Sets the container image to be used for running buildkit. - `image=IMAGE` - Sets the container image to be used for running buildkit.
- `network=NETMODE` - Sets the network mode for running the buildkit container. - `network=NETMODE` - Sets the network mode for running the buildkit container.
- `cgroup-parent=CGROUP` - Sets the cgroup parent of the buildkit container if docker is using the "cgroupfs" driver. Defaults to `/docker/buildx`. - `cgroup-parent=CGROUP` - Sets the cgroup parent of the buildkit container if docker is using the "cgroupfs" driver. Defaults to `/docker/buildx`.
- `restart-policy=POLICY` - Sets the [restart policy](https://docs.docker.com/engine/reference/run/#restart-policies---restart) of the buildkit container.
#### `kubernetes` driver #### `kubernetes` driver

@ -39,6 +39,7 @@ type Driver struct {
netMode string netMode string
image string image string
cgroupParent string cgroupParent string
restartPolicy container.RestartPolicy
env []string env []string
} }
@ -111,6 +112,7 @@ func (d *Driver) create(ctx context.Context, l progress.SubLogger) error {
if err := l.Wrap("creating container "+d.Name, func() error { if err := l.Wrap("creating container "+d.Name, func() error {
hc := &container.HostConfig{ hc := &container.HostConfig{
Privileged: true, Privileged: true,
RestartPolicy: d.restartPolicy,
Mounts: []mount.Mount{ Mounts: []mount.Mount{
{ {
Type: mount.TypeVolume, Type: mount.TypeVolume,

@ -6,12 +6,14 @@ import (
"strings" "strings"
"github.com/docker/buildx/driver" "github.com/docker/buildx/driver"
dockeropts "github.com/docker/cli/opts"
dockerclient "github.com/docker/docker/client" dockerclient "github.com/docker/docker/client"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
const prioritySupported = 30 const prioritySupported = 30
const priorityUnsupported = 70 const priorityUnsupported = 70
const defaultRestartPolicy = "unless-stopped"
func init() { func init() {
driver.Register(&factory{}) driver.Register(&factory{})
@ -39,7 +41,15 @@ func (f *factory) New(ctx context.Context, cfg driver.InitConfig) (driver.Driver
if cfg.DockerAPI == nil { if cfg.DockerAPI == nil {
return nil, errors.Errorf("%s driver requires docker API access", f.Name()) return nil, errors.Errorf("%s driver requires docker API access", f.Name())
} }
d := &Driver{factory: f, InitConfig: cfg} rp, err := dockeropts.ParseRestartPolicy(defaultRestartPolicy)
if err != nil {
return nil, err
}
d := &Driver{
factory: f,
InitConfig: cfg,
restartPolicy: rp,
}
for k, v := range cfg.DriverOpts { for k, v := range cfg.DriverOpts {
switch { switch {
case k == "network": case k == "network":
@ -51,6 +61,11 @@ func (f *factory) New(ctx context.Context, cfg driver.InitConfig) (driver.Driver
d.image = v d.image = v
case k == "cgroup-parent": case k == "cgroup-parent":
d.cgroupParent = v d.cgroupParent = v
case k == "restart-policy":
d.restartPolicy, err = dockeropts.ParseRestartPolicy(v)
if err != nil {
return nil, err
}
case strings.HasPrefix(k, "env."): case strings.HasPrefix(k, "env."):
envName := strings.TrimPrefix(k, "env.") envName := strings.TrimPrefix(k, "env.")
if envName == "" { if envName == "" {

Loading…
Cancel
Save