forked from awslabs/ecs-refarch-continuous-deployment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.yaml
135 lines (117 loc) · 3.2 KB
/
service.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
---
AWSTemplateFormatVersion: 2010-09-09
Parameters:
Cluster:
Type: String
DesiredCount:
Type: Number
Default: 1
LaunchType:
Type: String
Default: Fargate
AllowedValues:
- Fargate
- EC2
TargetGroup:
Type: String
SourceSecurityGroup:
Type: AWS::EC2::SecurityGroup::Id
Subnets:
Type: List<AWS::EC2::Subnet::Id>
Conditions:
Fargate: !Equals [ !Ref LaunchType, "Fargate" ]
EC2: !Equals [ !Ref LaunchType, "EC2" ]
Resources:
TaskExecutionRole:
Type: AWS::IAM::Role
Properties:
Path: /
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service: ecs-tasks.amazonaws.com
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy
LogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub /ecs/${AWS::StackName}
FargateService:
Type: AWS::ECS::Service
Condition: Fargate
Properties:
Cluster: !Ref Cluster
DesiredCount: !Ref DesiredCount
TaskDefinition: !Ref TaskDefinition
LaunchType: FARGATE
NetworkConfiguration:
AwsvpcConfiguration:
AssignPublicIp: ENABLED
SecurityGroups:
- !Ref SourceSecurityGroup
Subnets: !Ref Subnets
LoadBalancers:
- ContainerName: simple-app
ContainerPort: 80
TargetGroupArn: !Ref TargetGroup
EC2Service:
Type: AWS::ECS::Service
Condition: EC2
Properties:
Cluster: !Ref Cluster
DesiredCount: !Ref DesiredCount
TaskDefinition: !Ref TaskDefinition
LaunchType: EC2
LoadBalancers:
- ContainerName: simple-app
ContainerPort: 80
TargetGroupArn: !Ref TargetGroup
TaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
Family: !Sub ${AWS::StackName}-simple-app
RequiresCompatibilities:
- !If [ Fargate, "FARGATE", "EC2" ]
Memory: 512
Cpu: 256
NetworkMode: !If [ Fargate, "awsvpc", "bridge" ]
ExecutionRoleArn: !Ref TaskExecutionRole
ContainerDefinitions:
- Name: simple-app
Image: amazon/amazon-ecs-sample
EntryPoint:
- /usr/sbin/apache2
- -D
- FOREGROUND
Essential: true
Memory: 256
MountPoints:
- SourceVolume: my-vol
ContainerPath: /var/www/my-vol
PortMappings:
- ContainerPort: 80
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-region: !Ref AWS::Region
awslogs-group: !Ref LogGroup
awslogs-stream-prefix: !Ref AWS::StackName
- Name: busybox
Image: busybox
EntryPoint:
- sh
- -c
Essential: true
Memory: 256
VolumesFrom:
- SourceContainer: simple-app
Command:
- /bin/sh -c "while true; do /bin/date > /var/www/my-vol/date; sleep 1; done"
Volumes:
- Name: my-vol
Outputs:
Service:
Value: !If [ Fargate, !Ref FargateService, !Ref EC2Service ]