Skip to content

Commit 0700309

Browse files
authored
Merge pull request #209 from rikislaw/entrypoint_in_docker_style
Podman entrypoint works the same as for docker driver
2 parents d51a7af + 68e158e commit 0700309

File tree

4 files changed

+43
-20
lines changed

4 files changed

+43
-20
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ IMPROVEMENTS:
55
* config: Add `extra_labels` option [[GH-215](https://github.com/hashicorp/nomad-driver-podman/pull/215)]
66
* config: Allow setting `pids_limit` option. [[GH-203](https://github.com/hashicorp/nomad-driver-podman/pull/203)]
77
* config: Allow setting `userns` option. [[GH-212](https://github.com/hashicorp/nomad-driver-podman/pull/212)]
8+
* config: Allow setting `entrypoint` as a list of strings. [[GH-209](https://github.com/hashicorp/nomad-driver-podman/pull/209)]
89
* runtime: Set mount propagation from TaskConfig [[GH-204](https://github.com/hashicorp/nomad-driver-podman/pull/204)]
910

1011
BUG FIXES:

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,14 @@ config {
218218
}
219219
```
220220

221-
* **entrypoint** - (Optional) The entrypoint for the container. Defaults to the entrypoint set in the image.
221+
* **entrypoint** - (Optional) A string list overriding the image's entrypoint. Defaults to the entrypoint set in the image.
222222

223223
```hcl
224224
config {
225-
entrypoint = "/entrypoint.sh"
225+
entrypoint = [
226+
"/bin/bash",
227+
"-c"
228+
]
226229
}
227230
```
228231

config.go

+22-16
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,13 @@ var (
6161
"cpu_hard_limit": hclspec.NewAttr("cpu_hard_limit", "bool", false),
6262
"cpu_cfs_period": hclspec.NewAttr("cpu_cfs_period", "number", false),
6363
"devices": hclspec.NewAttr("devices", "list(string)", false),
64-
"entrypoint": hclspec.NewAttr("entrypoint", "string", false),
65-
"working_dir": hclspec.NewAttr("working_dir", "string", false),
66-
"hostname": hclspec.NewAttr("hostname", "string", false),
67-
"image": hclspec.NewAttr("image", "string", true),
64+
65+
// Use `any` to maintain backwards compability.
66+
// Expected type is `list(string)` but may be `string` for old tasks.
67+
"entrypoint": hclspec.NewAttr("entrypoint", "any", false),
68+
"working_dir": hclspec.NewAttr("working_dir", "string", false),
69+
"hostname": hclspec.NewAttr("hostname", "string", false),
70+
"image": hclspec.NewAttr("image", "string", true),
6871
"image_pull_timeout": hclspec.NewDefault(
6972
hclspec.NewAttr("image_pull_timeout", "string", false),
7073
hclspec.NewLiteral(`"5m"`),
@@ -131,18 +134,21 @@ type PluginConfig struct {
131134

132135
// TaskConfig is the driver configuration of a task within a job
133136
type TaskConfig struct {
134-
ApparmorProfile string `codec:"apparmor_profile"`
135-
Args []string `codec:"args"`
136-
Auth AuthConfig `codec:"auth"`
137-
Ports []string `codec:"ports"`
138-
Tmpfs []string `codec:"tmpfs"`
139-
Volumes []string `codec:"volumes"`
140-
CapAdd []string `codec:"cap_add"`
141-
CapDrop []string `codec:"cap_drop"`
142-
SelinuxOpts []string `codec:"selinux_opts"`
143-
Command string `codec:"command"`
144-
Devices []string `codec:"devices"`
145-
Entrypoint string `codec:"entrypoint"`
137+
ApparmorProfile string `codec:"apparmor_profile"`
138+
Args []string `codec:"args"`
139+
Auth AuthConfig `codec:"auth"`
140+
Ports []string `codec:"ports"`
141+
Tmpfs []string `codec:"tmpfs"`
142+
Volumes []string `codec:"volumes"`
143+
CapAdd []string `codec:"cap_add"`
144+
CapDrop []string `codec:"cap_drop"`
145+
SelinuxOpts []string `codec:"selinux_opts"`
146+
Command string `codec:"command"`
147+
Devices []string `codec:"devices"`
148+
149+
// Use `any` to maintain backwards compability.
150+
// Expected type is `[]string` but may be `string` for old tasks.
151+
Entrypoint any `codec:"entrypoint"`
146152
WorkingDir string `codec:"working_dir"`
147153
Hostname string `codec:"hostname"`
148154
Image string `codec:"image"`

driver.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,21 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
419419
}
420420
allArgs = append(allArgs, driverConfig.Args...)
421421

422-
if driverConfig.Entrypoint != "" {
423-
createOpts.ContainerBasicConfig.Entrypoint = append(createOpts.ContainerBasicConfig.Entrypoint, driverConfig.Entrypoint)
422+
// Parse entrypoint.
423+
switch v := driverConfig.Entrypoint.(type) {
424+
case string:
425+
// Check for a string type to maintain backwards compatibility.
426+
d.logger.Warn("Defining the entrypoint as a string has been deprecated, use a list of strings instead.")
427+
createOpts.ContainerBasicConfig.Entrypoint = append(createOpts.ContainerBasicConfig.Entrypoint, v)
428+
case []interface{}:
429+
entrypoint := make([]string, len(v))
430+
for i, e := range v {
431+
entrypoint[i] = fmt.Sprintf("%v", e)
432+
}
433+
createOpts.ContainerBasicConfig.Entrypoint = entrypoint
434+
case nil:
435+
default:
436+
return nil, nil, fmt.Errorf("invalid entrypoint type %T", driverConfig.Entrypoint)
424437
}
425438

426439
containerName := BuildContainerName(cfg)

0 commit comments

Comments
 (0)