Skip to content

Commit

Permalink
Merge pull request #209 from rikislaw/entrypoint_in_docker_style
Browse files Browse the repository at this point in the history
Podman entrypoint works the same as for docker driver
  • Loading branch information
lgfa29 authored Mar 24, 2023
2 parents d51a7af + 68e158e commit 0700309
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ IMPROVEMENTS:
* config: Add `extra_labels` option [[GH-215](https://github.com/hashicorp/nomad-driver-podman/pull/215)]
* config: Allow setting `pids_limit` option. [[GH-203](https://github.com/hashicorp/nomad-driver-podman/pull/203)]
* config: Allow setting `userns` option. [[GH-212](https://github.com/hashicorp/nomad-driver-podman/pull/212)]
* config: Allow setting `entrypoint` as a list of strings. [[GH-209](https://github.com/hashicorp/nomad-driver-podman/pull/209)]
* runtime: Set mount propagation from TaskConfig [[GH-204](https://github.com/hashicorp/nomad-driver-podman/pull/204)]

BUG FIXES:
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,14 @@ config {
}
```

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

```hcl
config {
entrypoint = "/entrypoint.sh"
entrypoint = [
"/bin/bash",
"-c"
]
}
```

Expand Down
38 changes: 22 additions & 16 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ var (
"cpu_hard_limit": hclspec.NewAttr("cpu_hard_limit", "bool", false),
"cpu_cfs_period": hclspec.NewAttr("cpu_cfs_period", "number", false),
"devices": hclspec.NewAttr("devices", "list(string)", false),
"entrypoint": hclspec.NewAttr("entrypoint", "string", false),
"working_dir": hclspec.NewAttr("working_dir", "string", false),
"hostname": hclspec.NewAttr("hostname", "string", false),
"image": hclspec.NewAttr("image", "string", true),

// Use `any` to maintain backwards compability.
// Expected type is `list(string)` but may be `string` for old tasks.
"entrypoint": hclspec.NewAttr("entrypoint", "any", false),
"working_dir": hclspec.NewAttr("working_dir", "string", false),
"hostname": hclspec.NewAttr("hostname", "string", false),
"image": hclspec.NewAttr("image", "string", true),
"image_pull_timeout": hclspec.NewDefault(
hclspec.NewAttr("image_pull_timeout", "string", false),
hclspec.NewLiteral(`"5m"`),
Expand Down Expand Up @@ -131,18 +134,21 @@ type PluginConfig struct {

// TaskConfig is the driver configuration of a task within a job
type TaskConfig struct {
ApparmorProfile string `codec:"apparmor_profile"`
Args []string `codec:"args"`
Auth AuthConfig `codec:"auth"`
Ports []string `codec:"ports"`
Tmpfs []string `codec:"tmpfs"`
Volumes []string `codec:"volumes"`
CapAdd []string `codec:"cap_add"`
CapDrop []string `codec:"cap_drop"`
SelinuxOpts []string `codec:"selinux_opts"`
Command string `codec:"command"`
Devices []string `codec:"devices"`
Entrypoint string `codec:"entrypoint"`
ApparmorProfile string `codec:"apparmor_profile"`
Args []string `codec:"args"`
Auth AuthConfig `codec:"auth"`
Ports []string `codec:"ports"`
Tmpfs []string `codec:"tmpfs"`
Volumes []string `codec:"volumes"`
CapAdd []string `codec:"cap_add"`
CapDrop []string `codec:"cap_drop"`
SelinuxOpts []string `codec:"selinux_opts"`
Command string `codec:"command"`
Devices []string `codec:"devices"`

// Use `any` to maintain backwards compability.
// Expected type is `[]string` but may be `string` for old tasks.
Entrypoint any `codec:"entrypoint"`
WorkingDir string `codec:"working_dir"`
Hostname string `codec:"hostname"`
Image string `codec:"image"`
Expand Down
17 changes: 15 additions & 2 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,21 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
}
allArgs = append(allArgs, driverConfig.Args...)

if driverConfig.Entrypoint != "" {
createOpts.ContainerBasicConfig.Entrypoint = append(createOpts.ContainerBasicConfig.Entrypoint, driverConfig.Entrypoint)
// Parse entrypoint.
switch v := driverConfig.Entrypoint.(type) {
case string:
// Check for a string type to maintain backwards compatibility.
d.logger.Warn("Defining the entrypoint as a string has been deprecated, use a list of strings instead.")
createOpts.ContainerBasicConfig.Entrypoint = append(createOpts.ContainerBasicConfig.Entrypoint, v)
case []interface{}:
entrypoint := make([]string, len(v))
for i, e := range v {
entrypoint[i] = fmt.Sprintf("%v", e)
}
createOpts.ContainerBasicConfig.Entrypoint = entrypoint
case nil:
default:
return nil, nil, fmt.Errorf("invalid entrypoint type %T", driverConfig.Entrypoint)
}

containerName := BuildContainerName(cfg)
Expand Down

0 comments on commit 0700309

Please sign in to comment.