forked from superwerker/superwerker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.yaml
190 lines (180 loc) · 6.04 KB
/
build.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
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Parameters:
OrganizationsVendingMachineEndpoint:
Type: String
RootMailDomain:
Type: String
DeploymentBucket:
Type: String
Default: superwerker-deployment
AllowedGitHubAccountIDs:
Type: CommaDelimitedList
SkipBuildCommitMessageRegExp:
Type: String
Default: \[skip ci\]
Resources:
LogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: codebuild/pr-builds/superwerker
RetentionInDays: 30
PublicReadRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service: codebuild.amazonaws.com
Action: sts:AssumeRole
Description: A role required for CodeBuild to access CloudWatch Logs for public visibility
Policies:
- PolicyName: S3CloudWatchLogs
PolicyDocument:
Version: '2012-10-17'
Statement:
- Action:
- logs:GetLogEvents
Resource: !GetAtt LogGroup.Arn
Effect: Allow
BuildAndTestProject:
Type: AWS::CodeBuild::Project
Properties:
Name: build-pull-request
TimeoutInMinutes: 180
BuildBatchConfig:
ServiceRole: !GetAtt BuildAndTestProjectRole.Arn
Environment:
ComputeType: BUILD_GENERAL1_SMALL
Image: aws/codebuild/amazonlinux2-x86_64-standard:4.0
Type: LINUX_CONTAINER
PrivilegedMode: true
EnvironmentVariables:
- Name: ROOT_MAIL_DOMAIN
Value: !Ref RootMailDomain
- Name: ORGANIZATIONS_VENDING_MACHINE_ENDPOINT
Value: !Ref OrganizationsVendingMachineEndpoint
- Name: TEMPLATE_BUCKET_NAME
Value: !Ref DeploymentBucket
- Name: TEMPLATE_REGION
Value: !Ref AWS::Region
- Name: SUPERWERKER_CLEANUP_STATE_MACHINE
Value: !ImportValue superwerker-tests-CleanupStateMachine
ServiceRole: !GetAtt BuildAndTestProjectRole.Arn
Artifacts:
Type: NO_ARTIFACTS
Source:
Type: GITHUB
Location: https://github.com/superwerker/superwerker.git
BuildSpec: tests/buildspec.yaml
Visibility: PUBLIC_READ
ResourceAccessRole: !GetAtt PublicReadRole.Arn
LogsConfig:
CloudWatchLogs:
GroupName: !Ref LogGroup
Status: ENABLED
CleanupProjectForStepFunction:
Type: AWS::CodeBuild::Project
Properties:
TimeoutInMinutes: 20
Environment:
ComputeType: BUILD_GENERAL1_SMALL
Image: aws/codebuild/amazonlinux2-x86_64-standard:4.0
Type: LINUX_CONTAINER
EnvironmentVariables:
- Name: CAPTCHA_API_KEY
Value: /superwerker/tests/2captcha_api_key
Type: SECRETS_MANAGER
ServiceRole: !GetAtt BuildAndTestProjectRole.Arn
Artifacts:
Type: NO_ARTIFACTS
Source:
Type: GITHUB
Location: https://github.com/superwerker/superwerker.git
BuildSpec: tests/buildspec-cleanup.yaml
BuildAndTestProjectRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
Effect: Allow
Principal:
Service:
- codebuild.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- !Sub arn:${AWS::Partition}:iam::aws:policy/AdministratorAccess # FIXME: least privilege
CleanupStateMachineRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service:
Fn::Join:
- ""
- - states.
- Ref: AWS::Region
- .amazonaws.com
Version: "2012-10-17"
CleanupStateMachineRoleDefaultPolicy:
Type: AWS::IAM::Policy
Properties:
PolicyDocument:
Statement:
- Action:
- codebuild:StartBuild
- codebuild:StopBuild
- codebuild:BatchGetBuilds
- codebuild:BatchGetReports
Effect: Allow
Resource:
Fn::GetAtt:
- CleanupProjectForStepFunction
- Arn
- Action:
- events:PutTargets
- events:PutRule
- events:DescribeRule
Effect: Allow
Resource:
Fn::Join:
- ""
- - 'arn:'
- Ref: AWS::Partition
- ':events:'
- Ref: AWS::Region
- ':'
- Ref: AWS::AccountId
- :rule/StepFunctionsGetEventForCodeBuildStartBuildRule
Version: "2012-10-17"
PolicyName: CleanupStateMachineRoleDefaultPolicy
Roles:
- Ref: CleanupStateMachineRole
CleanupStateMachine:
Type: AWS::StepFunctions::StateMachine
Properties:
RoleArn:
Fn::GetAtt:
- CleanupStateMachineRole
- Arn
DefinitionString:
Fn::Join:
- ""
- - '{"StartAt":"QueueCleanupViaCodeBuildStep","States":{"QueueCleanupViaCodeBuildStep":{"End":true,"Retry":[{"ErrorEquals":["States.ALL"],"IntervalSeconds":43200,"MaxAttempts":99999999,"BackoffRate":1.1}],"Type":"Task","Resource":"arn:'
- Ref: AWS::Partition
- :states:::codebuild:startBuild.sync","Parameters":{"ProjectName":"
- Ref: CleanupProjectForStepFunction
- '","EnvironmentVariablesOverride":[{"Name":"AWS_CROSS_ACCOUNT_ROLE_ARN","Type":"PLAINTEXT","Value.$":"$.AWS_CROSS_ACCOUNT_ROLE_ARN"},{"Name":"SUPERWERKER_REGION","Type":"PLAINTEXT","Value.$":"$.SUPERWERKER_REGION"},{"Name":"AWS_ACCOUNT_ID","Type":"PLAINTEXT","Value.$":"$.AWS_ACCOUNT_ID"}]}}}}'
DependsOn:
- CleanupStateMachineRoleDefaultPolicy
Outputs:
CleanupStateMachine:
Value: !Ref CleanupStateMachine
Export:
Name: superwerker-tests-CleanupStateMachine