-
Notifications
You must be signed in to change notification settings - Fork 4
/
pipeline.template
181 lines (167 loc) · 4.92 KB
/
pipeline.template
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
---
AWSTemplateFormatVersion: "2010-09-09"
Description: Build and deployment pipeline.
Parameters:
SiteBucketArn:
Description: The bucket that serves the static site
Type: AWS::SSM::Parameter::Value<String>
SiteBucketName:
Description: The bucket that serves the static site
Type: AWS::SSM::Parameter::Value<String>
GitHubBranch:
Description: The git branch to watch for changes
Type: String
Default: master
GitHubRepo:
Description: GitHub repository to watch for changes
Type: String
GitHubOwner:
Description: The repository's owner
Type: String
GitHubToken:
Description: OAuth token to use when communicating with GitHub
Type: String
NoEcho: true
Resources:
Bucket:
Type: AWS::S3::Bucket
DeletionPolicy: Delete
PipelineRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service:
- codepipeline.amazonaws.com
Action:
- sts:AssumeRole
Path: /
Policies:
- PolicyName: CodePipeline
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
# TODO: Fix this scope
Action:
- s3:*
- codebuild:*
# - logs:*
- cloudformation:*
Resource: "*"
Pipeline:
Type: AWS::CodePipeline::Pipeline
Properties:
ArtifactStore:
Type: S3
Location: !Ref Bucket
RestartExecutionOnUpdate: false
RoleArn: !Sub ${PipelineRole.Arn}
Stages:
- Name: Source
Actions:
- Name: Source
ActionTypeId:
Category: Source
Owner: ThirdParty
Provider: GitHub
Version: "1"
Configuration:
Owner: !Ref GitHubOwner
Repo: !Ref GitHubRepo
Branch: !Ref GitHubBranch
OAuthToken: !Ref GitHubToken
OutputArtifacts:
- Name: SourceOutput
- Name: Build
Actions:
- Name: Build
ActionTypeId:
Category: Build
Owner: AWS
Provider: CodeBuild
Version: "1"
Configuration:
ProjectName: !Ref Project
EnvironmentVariables: '[{ "name": "API", "value": "/updates/api", "type": "PLAINTEXT"}]'
InputArtifacts:
- Name: SourceOutput
OutputArtifacts:
- Name: BuildOutput
# TODO: Deploy infrastructure
- Name: Site
Actions:
- Name: Deploy
ActionTypeId:
Category: Deploy
Owner: AWS
Provider: S3
Version: "1"
Configuration:
BucketName: !Ref SiteBucketName
Extract: true
InputArtifacts:
- Name: BuildOutput
BuildRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service:
- codebuild.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: ServiceRole
PolicyDocument:
Version: "2012-10-17"
Statement:
- Sid: CloudWatchLogsPolicy
Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: "*"
- Sid: S3PolicyArtifactStore
Effect: Allow
Action:
- s3:GetObject
- s3:GetObjectVersion
- s3:PutObject
Resource:
- !Sub ${Bucket.Arn}/*
- Sid: S3PolicySiteBucket
Effect: Allow
Action:
- s3:GetObject
- s3:GetObjectVersion
- s3:PutObject
Resource:
- !Sub ${SiteBucketArn}/*
- Sid: SSMParameters
Effect: Allow
Action:
- ssm:GetParameters
Resource:
- !Sub
arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/boc/updates/*
Project:
Type: AWS::CodeBuild::Project
Properties:
Artifacts:
Type: CODEPIPELINE
Environment:
ComputeType: BUILD_GENERAL1_SMALL
Image: aws/codebuild/amazonlinux2-x86_64-standard:5.0
Type: LINUX_CONTAINER
Name: !Sub ${AWS::StackName}-project
ServiceRole: !GetAtt BuildRole.Arn
Source:
Type: CODEPIPELINE