Skip to content

Commit

Permalink
docker-container: restart-policy opt
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Aug 14, 2022
1 parent da1f4b8 commit fd85125
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/reference/buildx_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ No driver options.
- `image=IMAGE` - Sets the container image to be used for running buildkit.
- `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`.
- `restart-policy=POLICY` - Sets the [restart policy](https://docs.docker.com/engine/reference/run/#restart-policies---restart) of the buildkit container.

#### `kubernetes` driver

Expand Down
16 changes: 9 additions & 7 deletions driver/docker-container/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ const (

type Driver struct {
driver.InitConfig
factory driver.Factory
userNSRemap bool // true if dockerd is running with userns-remap mode
netMode string
image string
cgroupParent string
env []string
factory driver.Factory
userNSRemap bool // true if dockerd is running with userns-remap mode
netMode string
image string
cgroupParent string
restartPolicy container.RestartPolicy
env []string
}

func (d *Driver) IsMobyDriver() bool {
Expand Down Expand Up @@ -112,7 +113,8 @@ func (d *Driver) create(ctx context.Context, l progress.SubLogger) error {

if err := l.Wrap("creating container "+d.Name, func() error {
hc := &container.HostConfig{
Privileged: true,
Privileged: true,
RestartPolicy: d.restartPolicy,
Mounts: []mount.Mount{
{
Type: mount.TypeVolume,
Expand Down
6 changes: 6 additions & 0 deletions driver/docker-container/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"

"github.com/docker/buildx/driver"
dockeropts "github.com/docker/cli/opts"
dockertypes "github.com/docker/docker/api/types"
dockerclient "github.com/docker/docker/client"
"github.com/pkg/errors"
Expand Down Expand Up @@ -66,6 +67,11 @@ func (f *factory) New(ctx context.Context, cfg driver.InitConfig) (driver.Driver
d.image = v
case k == "cgroup-parent":
d.cgroupParent = v
case k == "restart-policy":
d.restartPolicy, err = dockeropts.ParseRestartPolicy(v)
if err != nil {
return nil, err
}
case strings.HasPrefix(k, "env."):
envName := strings.TrimPrefix(k, "env.")
if envName == "" {
Expand Down

0 comments on commit fd85125

Please sign in to comment.