Skip to content

Commit

Permalink
Create task blueprint, subclass for apps/services (#30)
Browse files Browse the repository at this point in the history
* Create task blueprint, subclass for apps/services

* Add PlacementConstraints

* Remove some naming to see if this works better

* Add tests

* Allow setting of NetworkMode

* Make fargate task type

* Handle extra stuff for Fargate Tasks

* Fargate tasks require cpu/memory
  • Loading branch information
phobologic authored Sep 23, 2018
1 parent 078152e commit 1f3b617
Show file tree
Hide file tree
Showing 9 changed files with 881 additions and 177 deletions.
373 changes: 235 additions & 138 deletions stacker_blueprints/ecs.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
},
"Service": {
"Properties": {
"Cluster": "fake-fargate-cluster",
"Cluster": "mycluster",
"DeploymentConfiguration": {
"Ref": "AWS::NoValue"
},
Expand All @@ -80,7 +80,9 @@
"NetworkConfiguration": {
"Ref": "AWS::NoValue"
},
"ServiceName": "WorkerService",
"PlacementConstraints": {
"Ref": "AWS::NoValue"
},
"TaskDefinition": {
"Ref": "TaskDefinition"
}
Expand Down Expand Up @@ -111,23 +113,26 @@
"LogConfiguration": {
"LogDriver": "awslogs",
"Options": {
"awslogs-group": "WorkerService",
"awslogs-group": "myapp",
"awslogs-region": {
"Ref": "AWS::Region"
},
"awslogs-stream-prefix": "WorkerService"
"awslogs-stream-prefix": "mytask"
}
},
"Memory": 2048,
"Name": "WorkerService",
"Name": "mytask",
"PortMappings": {
"Ref": "AWS::NoValue"
}
}
],
"Cpu": "1024",
"Family": "WorkerService",
"Memory": "2048",
"Cpu": {
"Ref": "AWS::NoValue"
},
"Memory": {
"Ref": "AWS::NoValue"
},
"NetworkMode": {
"Ref": "AWS::NoValue"
},
Expand All @@ -141,4 +146,4 @@
"Type": "AWS::ECS::TaskDefinition"
}
}
}
}
150 changes: 150 additions & 0 deletions tests/fixtures/blueprints/ecs__base_ecs_app_deployment_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
{
"Outputs": {
"RoleArn": {
"Value": {
"Fn::GetAtt": [
"Role",
"Arn"
]
}
},
"RoleId": {
"Value": {
"Fn::GetAtt": [
"Role",
"RoleId"
]
}
},
"RoleName": {
"Value": {
"Ref": "Role"
}
},
"ServiceArn": {
"Value": {
"Ref": "Service"
}
},
"ServiceName": {
"Value": {
"Fn::GetAtt": [
"Service",
"Name"
]
}
},
"TaskDefinitionArn": {
"Value": {
"Ref": "TaskDefinition"
}
}
},
"Resources": {
"Role": {
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": [
"sts:AssumeRole"
],
"Effect": "Allow",
"Principal": {
"Service": [
"ecs-tasks.amazonaws.com"
]
}
}
],
"Version": "2012-10-17"
},
"Path": "/"
},
"Type": "AWS::IAM::Role"
},
"Service": {
"Properties": {
"Cluster": "mycluster",
"DeploymentConfiguration": {
"MaximumPercent": 200,
"MinimumHealthyPercent": 50
},
"DesiredCount": 3,
"HealthCheckGracePeriodSeconds": {
"Ref": "AWS::NoValue"
},
"LaunchType": "EC2",
"LoadBalancers": {
"Ref": "AWS::NoValue"
},
"NetworkConfiguration": {
"Ref": "AWS::NoValue"
},
"PlacementConstraints": {
"Ref": "AWS::NoValue"
},
"TaskDefinition": {
"Ref": "TaskDefinition"
}
},
"Type": "AWS::ECS::Service"
},
"TaskDefinition": {
"Properties": {
"ContainerDefinitions": [
{
"Command": [
"/bin/run",
"--args 1"
],
"Cpu": 1024,
"Environment": [
{
"Name": "DATABASE_URL",
"Value": "sql://fake_db/fake_db"
},
{
"Name": "DEBUG",
"Value": "false"
}
],
"Essential": "true",
"Image": "fake_repo/image:12345",
"LogConfiguration": {
"LogDriver": "awslogs",
"Options": {
"awslogs-group": "myapp",
"awslogs-region": {
"Ref": "AWS::Region"
},
"awslogs-stream-prefix": "mytask"
}
},
"Memory": 2048,
"Name": "mytask",
"PortMappings": {
"Ref": "AWS::NoValue"
}
}
],
"Cpu": {
"Ref": "AWS::NoValue"
},
"Memory": {
"Ref": "AWS::NoValue"
},
"NetworkMode": {
"Ref": "AWS::NoValue"
},
"TaskRoleArn": {
"Fn::GetAtt": [
"Role",
"Arn"
]
}
},
"Type": "AWS::ECS::TaskDefinition"
}
}
}
158 changes: 158 additions & 0 deletions tests/fixtures/blueprints/ecs__base_ecs_app_load_balancers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
{
"Outputs": {
"RoleArn": {
"Value": {
"Fn::GetAtt": [
"Role",
"Arn"
]
}
},
"RoleId": {
"Value": {
"Fn::GetAtt": [
"Role",
"RoleId"
]
}
},
"RoleName": {
"Value": {
"Ref": "Role"
}
},
"ServiceArn": {
"Value": {
"Ref": "Service"
}
},
"ServiceName": {
"Value": {
"Fn::GetAtt": [
"Service",
"Name"
]
}
},
"TaskDefinitionArn": {
"Value": {
"Ref": "TaskDefinition"
}
}
},
"Resources": {
"Role": {
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": [
"sts:AssumeRole"
],
"Effect": "Allow",
"Principal": {
"Service": [
"ecs-tasks.amazonaws.com"
]
}
}
],
"Version": "2012-10-17"
},
"Path": "/"
},
"Type": "AWS::IAM::Role"
},
"Service": {
"Properties": {
"Cluster": "mycluster",
"DeploymentConfiguration": {
"Ref": "AWS::NoValue"
},
"DesiredCount": 3,
"HealthCheckGracePeriodSeconds": 300,
"LaunchType": "EC2",
"LoadBalancers": [
{
"ContainerName": "mytask",
"ContainerPort": 8000,
"TargetGroupArn": "arn:lb-1"
},
{
"ContainerName": "mytask",
"ContainerPort": 8000,
"TargetGroupArn": "arn:lb-2"
}
],
"NetworkConfiguration": {
"Ref": "AWS::NoValue"
},
"PlacementConstraints": {
"Ref": "AWS::NoValue"
},
"TaskDefinition": {
"Ref": "TaskDefinition"
}
},
"Type": "AWS::ECS::Service"
},
"TaskDefinition": {
"Properties": {
"ContainerDefinitions": [
{
"Command": [
"/bin/run",
"--args 1"
],
"Cpu": 1024,
"Environment": [
{
"Name": "DATABASE_URL",
"Value": "sql://fake_db/fake_db"
},
{
"Name": "DEBUG",
"Value": "false"
}
],
"Essential": "true",
"Image": "fake_repo/image:12345",
"LogConfiguration": {
"LogDriver": "awslogs",
"Options": {
"awslogs-group": "myapp",
"awslogs-region": {
"Ref": "AWS::Region"
},
"awslogs-stream-prefix": "mytask"
}
},
"Memory": 2048,
"Name": "mytask",
"PortMappings": [
{
"ContainerPort": 8000
}
]
}
],
"Cpu": {
"Ref": "AWS::NoValue"
},
"Memory": {
"Ref": "AWS::NoValue"
},
"NetworkMode": {
"Ref": "AWS::NoValue"
},
"TaskRoleArn": {
"Fn::GetAtt": [
"Role",
"Arn"
]
}
},
"Type": "AWS::ECS::TaskDefinition"
}
}
}
Loading

0 comments on commit 1f3b617

Please sign in to comment.