Skip to content

Commit 947c05e

Browse files
Add support for entrypoint.
Signed-off-by: Shishir Mahajan <[email protected]>
1 parent 7513ee0 commit 947c05e

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ More detailed instructions are in the [`example README.md`](https://github.com/R
9595
| **image** | string | yes | OCI image (docker is also OCI compatible) for your container. |
9696
| **command** | string | no | Command to override command defined in the image. |
9797
| **args** | []string | no | Arguments to the command. |
98+
| **entrypoint** | string | no | Overwrite the default ENTRYPOINT of the image. |
9899
| **cwd** | string | no | Specify the current working directory for your container process. If the directory does not exist, one will be created for you. |
99100
| **privileged** | bool | no | Run container in privileged mode. Your container will have all linux capabilities when running in privileged mode. |
100101
| **host_dns** | bool | no | Default (`true`). By default, a container launched using `containerd-driver` will use host `/etc/resolv.conf`. This is similar to [`docker behavior`](https://docs.docker.com/config/containers/container-networking/#dns-services). However, if you don't want to use host DNS, you can turn off this flag by setting `host_dns=false`. |

containerd/containerd.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,16 @@ func (d *Driver) pullImage(imageName string) (containerd.Image, error) {
7676
}
7777

7878
func (d *Driver) createContainer(containerConfig *ContainerConfig, config *TaskConfig) (containerd.Container, error) {
79-
if config.Command == "" && len(config.Args) > 0 {
80-
return nil, fmt.Errorf("Command is empty. Cannot set --args without --command.")
79+
if config.Command != "" && config.Entrypoint != "" {
80+
return nil, fmt.Errorf("Both command and entrypoint are set. Only one of them needs to be set.")
8181
}
8282

83-
// Command set by the user, to override entrypoint or cmd defined in the image.
83+
// Entrypoint or Command set by the user, to override entrypoint or cmd defined in the image.
8484
var args []string
8585
if config.Command != "" {
8686
args = append(args, config.Command)
87+
} else if config.Entrypoint != "" {
88+
args = append(args, config.Entrypoint)
8789
}
8890

8991
// Arguments to the command set by the user.
@@ -93,7 +95,11 @@ func (d *Driver) createContainer(containerConfig *ContainerConfig, config *TaskC
9395

9496
var opts []oci.SpecOpts
9597

96-
opts = append(opts, oci.WithImageConfigArgs(containerConfig.Image, args))
98+
if config.Entrypoint != "" {
99+
opts = append(opts, oci.WithProcessArgs(args...))
100+
} else {
101+
opts = append(opts, oci.WithImageConfigArgs(containerConfig.Image, args))
102+
}
97103

98104
if !d.config.AllowPrivileged && config.Privileged {
99105
return nil, fmt.Errorf("Running privileged jobs are not allowed. Set allow_privileged to true in plugin config to allow running privileged jobs.")

containerd/driver.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ var (
103103
hclspec.NewLiteral("true"),
104104
),
105105
"extra_hosts": hclspec.NewAttr("extra_hosts", "list(string)", false),
106+
"entrypoint": hclspec.NewAttr("entrypoint", "string", false),
106107
"seccomp": hclspec.NewAttr("seccomp", "bool", false),
107108
"seccomp_profile": hclspec.NewAttr("seccomp_profile", "string", false),
108109
"readonly_rootfs": hclspec.NewAttr("readonly_rootfs", "bool", false),
@@ -161,6 +162,7 @@ type TaskConfig struct {
161162
Privileged bool `codec:"privileged"`
162163
HostDNS bool `codec:"host_dns"`
163164
ExtraHosts []string `codec:"extra_hosts"`
165+
Entrypoint string `codec:"entrypoint"`
164166
ReadOnlyRootfs bool `codec:"readonly_rootfs"`
165167
HostNetwork bool `codec:"host_network"`
166168
Mounts []Mount `codec:"mounts"`

0 commit comments

Comments
 (0)