Skip to content

Commit

Permalink
Merge pull request #24 from theonestack/volumes_with_refs
Browse files Browse the repository at this point in the history
adds support for adding volumes with driver config
  • Loading branch information
Guslington authored Mar 20, 2019
2 parents e0fa901 + 81e005d commit feea509
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
19 changes: 14 additions & 5 deletions ecs-service.cfndsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
31 changes: 31 additions & 0 deletions tests/volumes-ref.test.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit feea509

Please sign in to comment.