Skip to content
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
21 changes: 19 additions & 2 deletions cloudlift/deployment/service_template_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
DeploymentConfiguration, Environment,
LoadBalancer, LogConfiguration,
NetworkConfiguration, PlacementStrategy,
PortMapping, Service, TaskDefinition)
PortMapping, Service, MountPoint)
from troposphere.elasticloadbalancingv2 import Action, Certificate, Listener
from troposphere.elasticloadbalancingv2 import LoadBalancer as ALBLoadBalancer
from troposphere.elasticloadbalancingv2 import (Matcher, RedirectConfig,
TargetGroup,
TargetGroupAttribute)
from troposphere.iam import Role
from cloudlift.extensions.troposphere.ecs import TaskDefinition, Volume, EfsVolumeConfiguration

from cloudlift.config import region as region_service
from cloudlift.config import get_account_id
Expand Down Expand Up @@ -181,6 +182,13 @@ def _add_service(self, service_name, config):
if config['command'] is not None:
container_definition_arguments['Command'] = [config['command']]

if 'mountPoints' in config:
mountPoints = []
for mountPoint in config['mountPoints']:
mountPoints.append(MountPoint(ContainerPath=mountPoint['containerPath'],
SourceVolume=mountPoint['sourceVolume']))
container_definition_arguments['MountPoints'] = mountPoints

cd = ContainerDefinition(**container_definition_arguments)

task_role = self.template.add_resource(Role(
Expand All @@ -205,11 +213,19 @@ def _add_service(self, service_name, config):
'Cpu': str(config['fargate']['cpu']),
'Memory': str(config['fargate']['memory'])
}
volumes = []
if 'volumes' in config:
for volume in config['volumes']:
volumes.append(Volume(Name=volume['name'],
EfsVolumeConfiguration=EfsVolumeConfiguration(
FileSystemId=volume['efsFileSystemId'],
TransitEncryption='ENABLED')))

td = TaskDefinition(
service_name + "TaskDefinition",
Family=service_name + "Family",
ContainerDefinitions=[cd],
Volumes=volumes,
TaskRoleArn=Ref(task_role),
**launch_type_td
)
Expand Down Expand Up @@ -398,7 +414,8 @@ def _add_alb(self, cd, service_name, config, launch_type):
self.template.add_resource(alb)

target_group_name = "TargetGroup" + service_name
health_check_path = config['http_interface']['health_check_path'] if 'health_check_path' in config['http_interface'] else "/elb-check"
health_check_path = config['http_interface']['health_check_path'] if 'health_check_path' in config[
'http_interface'] else "/elb-check"
if config['http_interface']['internal']:
target_group_name = target_group_name + 'Internal'

Expand Down
Empty file.
Empty file.
41 changes: 41 additions & 0 deletions cloudlift/extensions/troposphere/ecs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from troposphere import AWSObject, Tags, AWSProperty
from troposphere.ecs import ContainerDefinition, InferenceAccelerator, PlacementConstraint, ProxyConfiguration, \
DockerVolumeConfiguration, Host


class EfsVolumeConfiguration(AWSProperty):
props = {
'FileSystemId': (str, True),
'TransitEncryption': (str, True)
}


class Volume(AWSProperty):
props = {
'DockerVolumeConfiguration': (DockerVolumeConfiguration, False),
'EfsVolumeConfiguration': (EfsVolumeConfiguration, False),
'Name': (str, True),
'Host': (Host, False),
}


class TaskDefinition(AWSObject):
resource_type = "AWS::ECS::TaskDefinition"

props = {
'ContainerDefinitions': ([ContainerDefinition], False),
'Cpu': (str, False),
'ExecutionRoleArn': (str, False),
'Family': (str, False),
'InferenceAccelerators': ([InferenceAccelerator], False),
'IpcMode': (str, False),
'Memory': (str, False),
'NetworkMode': (str, False),
'PidMode': (str, False),
'PlacementConstraints': ([PlacementConstraint], False),
'ProxyConfiguration': (ProxyConfiguration, False),
'RequiresCompatibilities': ([str], False),
'Tags': (Tags, False),
'TaskRoleArn': (str, False),
'Volumes': ([Volume], False),
}