Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for alternative docker runtimes #4073

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions agent/api/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -1946,6 +1946,15 @@ func (task *Task) dockerHostConfig(container *apicontainer.Container, dockerCont
// overrideContainerRuntime overrides the runtime for the container in host config if needed.
func (task *Task) overrideContainerRuntime(container *apicontainer.Container, hostCfg *dockercontainer.HostConfig,
cfg *config.Config) *apierrors.HostConfigError {
if cfg.Runtime != "" {
logger.Debug("Setting runtime for container", logger.Fields{
field.TaskID: task.GetID(),
field.Container: container.Name,
"runTime": cfg.Runtime,
})
hostCfg.Runtime = cfg.Runtime
}

if task.isGPUEnabled() && task.shouldRequireNvidiaRuntime(container) {
if !cfg.External.Enabled() {
if task.NvidiaRuntime == "" {
Expand Down
16 changes: 16 additions & 0 deletions agent/api/task/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3542,6 +3542,22 @@ func TestDockerHostConfigNvidiaRuntime(t *testing.T) {
assert.Equal(t, testTask.NvidiaRuntime, dockerHostConfig.Runtime)
}

func TestDockerHostConfigCustomRuntime(t *testing.T) {
testTask := &Task{
Arn: "test",
Containers: []*apicontainer.Container{
{
Name: "myName1",
Image: "image:tag",
},
},
}

dockerHostConfig, _ := testTask.DockerHostConfig(testTask.Containers[0], dockerMap(testTask), defaultDockerClientAPIVersion,
&config.Config{Runtime: "custom-runtime"})
assert.Equal(t, "custom-runtime", dockerHostConfig.Runtime)
}

func TestDockerHostConfigRuntimeWithoutGPU(t *testing.T) {
testTask := &Task{
Arn: "test",
Expand Down
1 change: 1 addition & 0 deletions agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ func environmentConfig() (Config, error) {
WarmPoolsSupport: parseBooleanDefaultFalseConfig("ECS_WARM_POOLS_CHECK"),
DynamicHostPortRange: parseDynamicHostPortRange("ECS_DYNAMIC_HOST_PORT_RANGE"),
TaskPidsLimit: parseTaskPidsLimit(),
Runtime: os.Getenv("ECS_DOCKER_RUNTIME"),
}, err
}

Expand Down
2 changes: 2 additions & 0 deletions agent/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func TestEnvironmentConfig(t *testing.T) {
defer setTestEnv("ECS_EXCLUDE_IPV6_PORTBINDING", "true")()
defer setTestEnv("ECS_WARM_POOLS_CHECK", "false")()
defer setTestEnv("ECS_DYNAMIC_HOST_PORT_RANGE", "200-300")()
defer setTestEnv("ECS_DOCKER_RUNTIME", "custom-runtime")()
additionalLocalRoutesJSON := `["1.2.3.4/22","5.6.7.8/32"]`
setTestEnv("ECS_AWSVPC_ADDITIONAL_LOCAL_ROUTES", additionalLocalRoutesJSON)
setTestEnv("ECS_ENABLE_CONTAINER_METADATA", "true")
Expand Down Expand Up @@ -222,6 +223,7 @@ func TestEnvironmentConfig(t *testing.T) {
assert.True(t, conf.ShouldExcludeIPv6PortBinding.Enabled(), "Wrong value for ShouldExcludeIPv6PortBinding")
assert.False(t, conf.WarmPoolsSupport.Enabled(), "Wrong value for WarmPoolsSupport")
assert.Equal(t, "200-300", conf.DynamicHostPortRange)
assert.Equal(t, "custom-runtime", conf.Runtime)
}

func TestTrimWhitespaceWhenCreating(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions agent/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,4 +376,7 @@ type Config struct {
// cgroup setting at the ECS task level.
// see https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html#pid
TaskPidsLimit int

// Runtime specifies a custom docker runtime to be used when launching tasks.
Runtime string
}