-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathTemplatePipeline.yaml
263 lines (233 loc) · 8.13 KB
/
TemplatePipeline.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# Copyright 2019 Amazon.com, Inc. and its affiliates. All Rights Reserved.
#
# Licensed under the Amazon Software License (the 'License').
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
# http://aws.amazon.com/asl/
#
# or in the 'license' file accompanying this file. This file is distributed
# on an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.
AWSTemplateFormatVersion: "2010-09-09"
Description: "Pipeline Template"
Parameters:
RepositoryName:
Type: String
BranchName:
Type: String
Default: "master"
Setup:
Type: String
Default: false
Conditions:
BranchMaster: !Equals [ !Ref BranchName, "master" ]
BranchDevelop: !Equals [ !Ref BranchName, "develop"]
Setup: !Equals [ !Ref Setup, true ]
Resources:
#----------------------------------------------------------------------#
# Create CodeCommit Repository
# Condition: Only at Microservice Setup
#----------------------------------------------------------------------#
Repository:
Type: AWS::CodeCommit::Repository
Condition: Setup
Properties:
RepositoryName: !Ref RepositoryName
Code:
S3:
Bucket: !Sub '${AWS::AccountId}-templates'
Key: seed.zip
#----------------------------------------------------------------------#
# Resource CodePipeline
#----------------------------------------------------------------------#
Pipeline:
Type: "AWS::CodePipeline::Pipeline"
Properties:
Name: !Join ['-', [!Ref RepositoryName, !Ref BranchName]]
RoleArn: !Sub 'arn:aws:iam::${AWS::AccountId}:role/CodePipelineRole'
ArtifactStore:
Type: S3
Location: !Sub '${AWS::AccountId}-templates'
Stages:
- Name: Source
Actions:
- Name: App
ActionTypeId:
Category: Source
Owner: AWS
Version: "1"
Provider: CodeCommit
Configuration:
RepositoryName: !Ref RepositoryName
BranchName: !Ref BranchName
OutputArtifacts:
- Name: Source
RunOrder: 1
#----------------------------------------------------------------------#
# Regardless of branch type, the CI Stage will always be created.
#----------------------------------------------------------------------#
- Name: Continuous-Integration
Actions:
- Name: CI-Action
ActionTypeId:
Category: Build
Owner: AWS
Version: "1"
Provider: CodeBuild
OutputArtifacts:
- Name: CIAction
InputArtifacts:
- Name: Source
Configuration:
ProjectName: !Join ['-', [!Ref 'RepositoryName', 'CIAction' ]]
RunOrder: 1
#----------------------------------------------------------------------#
# If BranchName=Develop, then create the CD Stage to deploy to Dev
#----------------------------------------------------------------------#
- !If
- BranchDevelop
- Name: Deploy-Dev
Actions:
- Name: CDActionDev
ActionTypeId:
Category: Build
Owner: AWS
Version: "1"
Provider: CodeBuild
InputArtifacts:
- Name: Source
OutputArtifacts:
- Name: CDActionDev
Configuration:
ProjectName: !Join ['-', [!Ref 'RepositoryName', 'CDActionDev']]
RunOrder: 1
- !Ref AWS::NoValue
#----------------------------------------------------------------------#
# If BranchName=Master, then create the CD Stage to deploy to Homolog
#----------------------------------------------------------------------#
- !If
- BranchMaster
- Name: Deploy-Homolog
Actions:
- Name: CDActionHomolog
ActionTypeId:
Category: Build
Owner: AWS
Version: "1"
Provider: CodeBuild
InputArtifacts:
- Name: Source
OutputArtifacts:
- Name: CDActionHomolog
Configuration:
ProjectName: !Join ['-', [!Ref 'RepositoryName', 'CDActionHomolog']]
RunOrder: 1
- !Ref AWS::NoValue
#----------------------------------------------------------------------#
# If BranchName=Master, then create CD Stage to deploy to Prod
#----------------------------------------------------------------------#
- !If
- BranchMaster
- Name: Deploy-Prod
Actions:
- Name: CDActionProd
ActionTypeId:
Category: Build
Owner: AWS
Version: "1"
Provider: CodeBuild
InputArtifacts:
- Name: Source
OutputArtifacts:
- Name: CDActionProd
Configuration:
ProjectName: !Join ['-', [!Ref 'RepositoryName', 'CDActionProd']]
RunOrder: 2
- !Ref AWS::NoValue
#----------------------------------------------------------------------#
# CodeBuild Projects
#----------------------------------------------------------------------#
CIAction:
Condition: Setup
Type: AWS::CodeBuild::Project
Properties:
Name: !Join ['-', [!Ref 'RepositoryName', 'CIAction' ]]
Source:
Type: CODEPIPELINE
BuildSpec: 'buildspec/CIAction.yaml'
Environment:
Type: LINUX_CONTAINER
ComputeType: BUILD_GENERAL1_SMALL
Image: aws/codebuild/standard:2.0
EnvironmentVariables:
- Name: BranchName
Value: !Ref BranchName
Artifacts:
Type: CODEPIPELINE
ServiceRole: !Sub 'arn:aws:iam::${AWS::AccountId}:role/CodeBuildRole'
TimeoutInMinutes: 10
CDActionDev:
Condition: Setup
Type: AWS::CodeBuild::Project
Properties:
Name: !Join ['-', [!Ref 'RepositoryName', 'CDActionDev' ]]
Source:
Type: CODEPIPELINE
BuildSpec: 'buildspec/CDAction.yaml'
Environment:
Type: LINUX_CONTAINER
ComputeType: BUILD_GENERAL1_SMALL
Image: aws/codebuild/standard:2.0
EnvironmentVariables:
- Name: pipeline_environment
Value: DEV
- Name: BranchName
Value: !Ref BranchName
Artifacts:
Type: CODEPIPELINE
ServiceRole: !Sub 'arn:aws:iam::${AWS::AccountId}:role/CodeBuildRole'
TimeoutInMinutes: 10
CDActionHomolog:
Condition: Setup
Type: AWS::CodeBuild::Project
Properties:
Name: !Join ['-', [!Ref 'RepositoryName', 'CDActionHomolog']]
Source:
Type: CODEPIPELINE
BuildSpec: 'buildspec/CDAction.yaml'
Environment:
Type: LINUX_CONTAINER
ComputeType: BUILD_GENERAL1_SMALL
Image: aws/codebuild/standard:2.0
EnvironmentVariables:
- Name: pipeline_environment
Value: HOMOLOG
- Name: BranchName
Value: !Ref BranchName
Artifacts:
Type: CODEPIPELINE
ServiceRole: !Sub 'arn:aws:iam::${AWS::AccountId}:role/CodeBuildRole'
TimeoutInMinutes: 10
CDActionProd:
Condition: Setup
Type: AWS::CodeBuild::Project
Properties:
Name: !Join ['-', [!Ref 'RepositoryName', 'CDActionProd']]
Source:
Type: CODEPIPELINE
BuildSpec: 'buildspec/CDAction.yaml'
Environment:
Type: LINUX_CONTAINER
ComputeType: BUILD_GENERAL1_SMALL
Image: aws/codebuild/standard:2.0
EnvironmentVariables:
- Name: pipeline_environment
Value: PROD
- Name: BranchName
Value: !Ref BranchName
Artifacts:
Type: CODEPIPELINE
ServiceRole: !Sub 'arn:aws:iam::${AWS::AccountId}:role/CodeBuildRole'
TimeoutInMinutes: 10