Skip to content

Commit

Permalink
Add group_add docker option (#17313)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamilcuk authored Jun 3, 2023
1 parent 91a3eb7 commit da9ec8c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/17313.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
docker: Add `group_add` configuration
```
2 changes: 2 additions & 0 deletions drivers/docker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ var (
"entrypoint": hclspec.NewAttr("entrypoint", "list(string)", false),
"extra_hosts": hclspec.NewAttr("extra_hosts", "list(string)", false),
"force_pull": hclspec.NewAttr("force_pull", "bool", false),
"group_add": hclspec.NewAttr("group_add", "list(string)", false),
"healthchecks": hclspec.NewBlock("healthchecks", false, healthchecksBodySpec),
"hostname": hclspec.NewAttr("hostname", "string", false),
"init": hclspec.NewAttr("init", "bool", false),
Expand Down Expand Up @@ -443,6 +444,7 @@ type TaskConfig struct {
Entrypoint []string `codec:"entrypoint"`
ExtraHosts []string `codec:"extra_hosts"`
ForcePull bool `codec:"force_pull"`
GroupAdd []string `codec:"group_add"`
Healthchecks DockerHealthchecks `codec:"healthchecks"`
Hostname string `codec:"hostname"`
Init bool `codec:"init"`
Expand Down
2 changes: 2 additions & 0 deletions drivers/docker/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ config {
entrypoint = ["/bin/bash", "-c"]
extra_hosts = ["127.0.0.1 localhost.example.com"]
force_pull = true
group_add = ["group1", "group2"]
healthchecks {
disable = true
}
Expand Down Expand Up @@ -389,6 +390,7 @@ config {
Entrypoint: []string{"/bin/bash", "-c"},
ExtraHosts: []string{"127.0.0.1 localhost.example.com"},
ForcePull: true,
GroupAdd: []string{"group1", "group2"},
Healthchecks: DockerHealthchecks{Disable: true},
Hostname: "self.example.com",
Interactive: true,
Expand Down
3 changes: 2 additions & 1 deletion drivers/docker/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,8 @@ func (d *Driver) createContainerConfig(task *drivers.TaskConfig, driverConfig *T

PidsLimit: &pidsLimit,

Runtime: containerRuntime,
Runtime: containerRuntime,
GroupAdd: driverConfig.GroupAdd,
}

// This translates to docker create/run --cpuset-cpus option.
Expand Down
20 changes: 20 additions & 0 deletions drivers/docker/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3089,3 +3089,23 @@ func TestDockerDriver_StopSignal(t *testing.T) {
})
}
}

func TestDockerDriver_GroupAdd(t *testing.T) {
if !tu.IsCI() {
t.Parallel()
}
testutil.DockerCompatible(t)

task, cfg, _ := dockerTask(t)
cfg.GroupAdd = []string{"12345", "9999"}
require.NoError(t, task.EncodeConcreteDriverConfig(cfg))

client, d, handle, cleanup := dockerSetup(t, task, nil)
defer cleanup()
require.NoError(t, d.WaitUntilStarted(task.ID, 5*time.Second))

container, err := client.InspectContainer(handle.containerID)
require.NoError(t, err)

require.Exactly(t, cfg.GroupAdd, container.HostConfig.GroupAdd)
}
3 changes: 3 additions & 0 deletions website/content/docs/drivers/docker.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ config {
are mutable. If image's tag is `latest` or omitted, the image will always be pulled
regardless of this setting.

- `group_add` - (Optional) A list of supplementary groups to be applied
to the container user.

- `healthchecks` - (Optional) A configuration block for controlling how the
docker driver manages HEALTHCHECK directives built into the container. Set
`healthchecks.disable` to disable any built-in healthcheck.
Expand Down

0 comments on commit da9ec8c

Please sign in to comment.