Skip to content

Commit

Permalink
Merge pull request #1191 from zebrunner/#1190
Browse files Browse the repository at this point in the history
Moved generic env vars and command field fill to task definition regi…
  • Loading branch information
vdelendik authored Oct 10, 2024
2 parents d24e8a4 + d9a4647 commit f8f2cd5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
49 changes: 38 additions & 11 deletions environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,32 @@ func (env *ExecutionEnvironment) ContainerOverrides() []*ecs.ContainerOverride {
cpu := container.Cpu()
memory := container.Memory()
override := ecs.ContainerOverride{
Name: &container.Name,
Cpu: &cpu,
Memory: &memory,
Command: aws.StringSlice(container.Command),
Name: &container.Name,
Cpu: &cpu,
Memory: &memory,
}

if strings.ToLower(env.Capabilities.PlatformName.ToPrimitive()) != envtype.WINDOWS.String() {
override.MemoryReservation = &memory
}

env := []*ecs.KeyValuePair{}
for k, v := range container.Env {
// need to declare local variables to provide as pointer later
key := k
value := v
env = append(env, &ecs.KeyValuePair{Name: &key, Value: &value})
// Env vars and command var are passed on task definition register phase for generic env due to:
// Task definition ovveride max symbols num constraint:
// InvalidParameterException: Container Overrides length must be at most 8192.
// When task definition register max symbols constraint is much higher:
// ClientException: Actual length: '117374'. Max allowed length is '65536' bytes.
// It is also possible because we always register new generic task definition before it starts
if env.Type != envtype.GENERIC {
override.Command = aws.StringSlice(container.Command)
env := []*ecs.KeyValuePair{}
for k, v := range container.Env {
// need to declare local variables to provide as pointer later
key := k
value := v
env = append(env, &ecs.KeyValuePair{Name: &key, Value: &value})
}
override.Environment = env
}
override.Environment = env

overrides = append(overrides, &override)
}
Expand Down Expand Up @@ -182,6 +190,25 @@ func (env *ExecutionEnvironment) ContainerDefinitions() []*ecs.ContainerDefiniti
}
containerDefinition.PortMappings = portMappings

// Env vars and command var are passed on task definition register phase for generic env due to:
// Task definition ovveride max symbols num constraint:
// InvalidParameterException: Container Overrides length must be at most 8192.
// When task definition register max symbols constraint is much higher:
// ClientException: Actual length: '117374'. Max allowed length is '65536' bytes.
// It is also possible because we always register new generic task definition before it starts
if env.Type == envtype.GENERIC {
env := []*ecs.KeyValuePair{}
for k, v := range c.Env {
// need to declare local variables to provide as pointer later
key := k
value := v
env = append(env, &ecs.KeyValuePair{Name: &key, Value: &value})
}

containerDefinition.Environment = env
containerDefinition.Command = aws.StringSlice(c.Command)
}

definitions = append(definitions, &containerDefinition)
}

Expand Down
1 change: 1 addition & 0 deletions starter/taskRegistrar.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func registerTask(ctx context.Context, env *environment.ExecutionEnvironment, ro
},
CapacityProviderStrategy: []*ecs.CapacityProviderStrategyItem{{CapacityProvider: &env.CapacityProvider}},
}

l.WithField("runTaskInput", runTaskInput).Trace("Res runTaskInput")

// TODO: explicitly minimize errors range to wait only by well-known reasons aka RESOURCE:CPU etc
Expand Down

0 comments on commit f8f2cd5

Please sign in to comment.