From 81e005da0fb39210822802775eb678665f2387e9 Mon Sep 17 00:00:00 2001 From: Aaron Walker Date: Wed, 20 Mar 2019 14:02:17 +0100 Subject: [PATCH] adds support for adding volumes with driver config --- ecs-service.cfndsl.rb | 19 ++++++++++++++----- tests/volumes-ref.test.yaml | 31 +++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 tests/volumes-ref.test.yaml diff --git a/ecs-service.cfndsl.rb b/ecs-service.cfndsl.rb index 666e9b5..90a4a1e 100644 --- a/ecs-service.cfndsl.rb +++ b/ecs-service.cfndsl.rb @@ -89,8 +89,12 @@ # add docker volumes if task.key?('mounts') task['mounts'].each do |mount| - parts = mount.split(':') - mount_points << { ContainerPath: parts[0], SourceVolume: parts[1], ReadOnly: (parts[2] == 'ro' ? true : false) } + if mount.is_a? String + parts = mount.split(':',2) + mount_points << { ContainerPath: FnSub(parts[0]), SourceVolume: FnSub(parts[1]), ReadOnly: (parts[2] == 'ro' ? true : false) } + else + mount_points << mount + end end task_def.merge!({MountPoints: mount_points }) end @@ -119,6 +123,7 @@ task_def.merge!({Command: task['command'] }) if task.key?('command') task_def.merge!({HealthCheck: task['healthcheck'] }) if task.key?('healthcheck') task_def.merge!({WorkingDirectory: task['working_dir'] }) if task.key?('working_dir') + task_def.merge!({Privileged: task['privileged'] }) if task.key?('privileged') definitions << task_def @@ -127,9 +132,13 @@ # add docker volumes if defined?(volumes) volumes.each do |volume| - parts = volume.split(':') - object = { Name: parts[0]} - object.merge!({ Host: { SourcePath: parts[1] }}) if parts[1] + if volume.is_a? String + parts = volume.split(':') + object = { Name: FnSub(parts[0])} + object.merge!({ Host: { SourcePath: FnSub(parts[1]) }}) if parts[1] + else + object = volume + end task_volumes << object end end diff --git a/tests/volumes-ref.test.yaml b/tests/volumes-ref.test.yaml new file mode 100644 index 0000000..1902a7d --- /dev/null +++ b/tests/volumes-ref.test.yaml @@ -0,0 +1,31 @@ +test_metadata: + type: config + name: ecs service with volumes that include a Ref + description: Creates an ecs service with volumes + +volumes: + - /data + - test:/test + - ${EnvironmentName}:/etc/${EnvironmentName} + - Name: + Fn::Sub: ${EnvironmentName}.mybucket + DockerVolumeConfiguration: + Driver: rexray/s3fs + Scope: shared + + +task_definition: + sftp: + image: nginx + tag: latest + privileged: true + mounts: + - /etc/${EnvironmentName}:${EnvironmentName} + - /data:${EnvironmentName}.mybucket + - /data:${EnvironmentName}.mybucket-${AWS::Region} + - ContainerPath: /data + SourceVolume: + Fn::Sub: bucket-${EnvironmentName}-${AWS::Region} + ReadOnly: false + ports: + - 80 \ No newline at end of file