Skip to content

Commit

Permalink
Merge pull request #52 from base2Services/linux-parameters
Browse files Browse the repository at this point in the history
support docker linux parameters
  • Loading branch information
Guslington authored Apr 9, 2020
2 parents 70af344 + 4f129e2 commit ccce4e0
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
35 changes: 33 additions & 2 deletions ecs-service.cfndsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
task_definition.each do |task_name, task|

env_vars, mount_points, ports, volumes_from, port_mappings = Array.new(5){[]}

name = task.has_key?('name') ? task['name'] : task_name

image_repo = task.has_key?('repo') ? "#{task['repo']}/" : ''
Expand Down Expand Up @@ -136,7 +136,38 @@
depends_on << { ContainerName: name, Condition: value}
end
end


linux_parameters = {}

if task.key?('cap_add')
linux_parameters[:Capabilities] = {Add: task['cap_add']}
end

if task.key?('cap_drop')
if linux_parameters.key?(:Capabilities)
linux_parameters[:Capabilities][:Drop] = task['cap_drop']
else
linux_parameters[:Capabilities] = {Drop: task['cap_drop']}
end
end

if task.key?('init')
linux_parameters[:InitProcessEnabled] = task['init']
end

if task.key?('memory_swap')
linux_parameters[:MaxSwap] = task['memory_swap'].to_i
end

if task.key?('shm_size')
linux_parameters[:SharedMemorySize] = task['shm_size'].to_i
end

if task.key?('memory_swappiness')
linux_parameters[:Swappiness] = task['memory_swappiness'].to_i
end

task_def.merge!({LinuxParameters: linux_parameters}) if linux_parameters.any?
task_def.merge!({EntryPoint: task['entrypoint'] }) if task.key?('entrypoint')
task_def.merge!({Command: task['command'] }) if task.key?('command')
task_def.merge!({HealthCheck: task['healthcheck'] }) if task.key?('healthcheck')
Expand Down
32 changes: 32 additions & 0 deletions tests/linux_parameters.test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
test_metadata:
type: config
name: linux_parameters
description: testing linux parameters in the task definition

task_definition:
one:
repo: nginx
image: nginx
cap_add:
- ALL
cap_drop:
- MKNOD
init: true
memory_swap: 10
shm_size: 10
memory_swappiness: 10
two:
repo: nginx
image: nginx
cap_drop:
- CHOWN

targetgroup:
name: nginx
container: nginx
port: 80
protocol: http
listener: http
healthcheck:
path: /
code: 200

0 comments on commit ccce4e0

Please sign in to comment.