1
1
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
# SPDX-License-Identifier: Apache-2.0 OR ISC
3
+ import builtins
4
+ import re
5
+ import typing
3
6
4
7
from aws_cdk import Stage , Environment , Duration , pipelines , aws_iam as iam , Stack
5
8
from constructs import Construct
9
12
from cdk .aws_lc_ec2_test_framework_ci_stack import AwsLcEC2TestingCIStack
10
13
from cdk .aws_lc_github_ci_stack import AwsLcGitHubCIStack
11
14
from cdk .aws_lc_github_fuzz_ci_stack import AwsLcGitHubFuzzCIStack
12
- from pipeline .codebuild_batch_step import BatchBuildTargetOptions , CodeBuildBatchStep
13
-
15
+ from pipeline .codebuild_batch_step import CodeBuildBatchStep
14
16
15
17
class CiStage (Stage ):
16
18
def __init__ (
17
19
self ,
18
20
scope : Construct ,
19
- id ,
20
- pipeline_environment ,
21
- deploy_environment ,
21
+ id : str ,
22
+ pipeline_environment : typing . Union [ Environment , typing . Dict [ str , typing . Any ]] ,
23
+ deploy_environment : typing . Union [ Environment , typing . Dict [ str , typing . Any ]] ,
22
24
** kwargs
23
25
):
24
26
super ().__init__ (
@@ -28,7 +30,7 @@ def __init__(
28
30
** kwargs ,
29
31
)
30
32
31
- self .build_targets = []
33
+ self .build_options = []
32
34
33
35
# Define CodeBuild Batch job for testing code.
34
36
x86_build_spec_file = "cdk/codebuild/github_ci_linux_x86_omnibus.yaml"
@@ -39,8 +41,8 @@ def __init__(
39
41
env = deploy_environment ,
40
42
stack_name = "aws-lc-ci-linux-x86" ,
41
43
)
42
- self .build_targets .append (BatchBuildTargetOptions (
43
- target = "aws-lc-ci-linux-x86" ,
44
+ self .build_options .append (BatchBuildOptions (
45
+ project = "aws-lc-ci-linux-x86" ,
44
46
ignore_failure = False ,
45
47
))
46
48
@@ -53,8 +55,8 @@ def __init__(
53
55
env = deploy_environment ,
54
56
stack_name = arm_stack_name ,
55
57
)
56
- self .build_targets .append (BatchBuildTargetOptions (
57
- target = "aws-lc-ci-linux-arm" ,
58
+ self .build_options .append (BatchBuildOptions (
59
+ project = "aws-lc-ci-linux-arm" ,
58
60
ignore_failure = False ,
59
61
))
60
62
@@ -66,8 +68,8 @@ def __init__(
66
68
env = deploy_environment ,
67
69
stack_name = "aws-lc-ci-integration" ,
68
70
)
69
- self .build_targets .append (BatchBuildTargetOptions (
70
- target = "aws-lc-ci-integration" ,
71
+ self .build_options .append (BatchBuildOptions (
72
+ project = "aws-lc-ci-integration" ,
71
73
ignore_failure = True ,
72
74
))
73
75
@@ -79,8 +81,8 @@ def __init__(
79
81
env = deploy_environment ,
80
82
stack_name = "aws-lc-ci-fuzzing" ,
81
83
)
82
- self .build_targets .append (BatchBuildTargetOptions (
83
- target = "aws-lc-ci-fuzzing" ,
84
+ self .build_options .append (BatchBuildOptions (
85
+ project = "aws-lc-ci-fuzzing" ,
84
86
ignore_failure = False ,
85
87
))
86
88
@@ -92,8 +94,8 @@ def __init__(
92
94
env = deploy_environment ,
93
95
stack_name = "aws-lc-ci-analytics" ,
94
96
)
95
- self .build_targets .append (BatchBuildTargetOptions (
96
- target = "aws-lc-ci-analytics" ,
97
+ self .build_options .append (BatchBuildOptions (
98
+ project = "aws-lc-ci-analytics" ,
97
99
ignore_failure = True ,
98
100
))
99
101
@@ -109,8 +111,8 @@ def __init__(
109
111
env = deploy_environment ,
110
112
stack_name = "aws-lc-ci-ec2-test-framework" ,
111
113
)
112
- self .build_targets .append (BatchBuildTargetOptions (
113
- target = "aws-lc-ci-ec2-test-framework" ,
114
+ self .build_options .append (BatchBuildOptions (
115
+ project = "aws-lc-ci-ec2-test-framework" ,
114
116
ignore_failure = True ,
115
117
))
116
118
@@ -122,8 +124,8 @@ def __init__(
122
124
env = deploy_environment ,
123
125
stack_name = "aws-lc-ci-devicefarm-android" ,
124
126
)
125
- self .build_targets .append (BatchBuildTargetOptions (
126
- target = "aws-lc-ci-devicefarm-android" ,
127
+ self .build_options .append (BatchBuildOptions (
128
+ project = "aws-lc-ci-devicefarm-android" ,
127
129
ignore_failure = False ,
128
130
))
129
131
@@ -135,25 +137,27 @@ def __init__(
135
137
env = deploy_environment ,
136
138
stack_name = "aws-lc-ci-windows-x86" ,
137
139
)
138
- self .build_targets .append (BatchBuildTargetOptions (
139
- target = "aws-lc-ci-windows-x86" ,
140
+ self .build_options .append (BatchBuildOptions (
141
+ project = "aws-lc-ci-windows-x86" ,
140
142
ignore_failure = False ,
141
143
))
142
144
143
145
@property
144
- def stacks (self ):
146
+ def stacks (self ) -> typing . List [ Stack ] :
145
147
return [child for child in self .node .children if isinstance (child , Stack )]
146
148
147
149
def add_stage_to_pipeline (
148
150
self ,
149
151
pipeline : pipelines .CodePipeline ,
150
152
input : pipelines .FileSet ,
151
153
role : iam .Role ,
152
- max_retry : int = 2 ,
153
- env = {} ,
154
+ max_retry : typing . Optional [ int ] = 2 ,
155
+ env : typing . Optional [ typing . Mapping [ str , str ]] = None ,
154
156
):
155
157
stack_names = [stack .stack_name for stack in self .stacks ]
156
158
159
+ env = env or {}
160
+
157
161
prebuild_check_step = pipelines .CodeBuildStep (
158
162
"PrebuildCheck" ,
159
163
input = input ,
@@ -168,8 +172,7 @@ def add_stage_to_pipeline(
168
172
"STACKS" : " " .join (stack_names ),
169
173
},
170
174
role = role ,
171
- timeout = Duration .minutes (180 )
172
- # project_name=f"{self.stage_name}-PrebuildCheck"
175
+ timeout = Duration .minutes (60 )
173
176
)
174
177
175
178
batch_build_jobs = {
@@ -179,13 +182,13 @@ def add_stage_to_pipeline(
179
182
"ignore-failure" : options .ignore_failure ,
180
183
"env" : {
181
184
"variables" : {
182
- "PROJECT" : options .target ,
183
- "TIMEOUT" : options .timeout ,
185
+ "PROJECT" : options .project ,
186
+ "TIMEOUT" : str ( max_retry * options .timeout ) ,
184
187
** options .env ,
185
188
}
186
189
}
187
190
}
188
- for options in self .build_targets
191
+ for options in self .build_options
189
192
]
190
193
}
191
194
@@ -199,32 +202,17 @@ def add_stage_to_pipeline(
199
202
"./build_target.sh --build-type ci --project ${PROJECT} --max-retry ${MAX_RETRY} --timeout ${TIMEOUT}"
200
203
],
201
204
role = role ,
205
+ timeout = 300 ,
202
206
partial_batch_buildspec = batch_build_jobs ,
203
207
env = {
204
208
** env ,
205
209
"MAX_RETRY" : max_retry ,
206
- "NEED_REBUILD" : prebuild_check_step .exported_variable ("NEED_REBUILD" )
210
+ "NEED_REBUILD" : prebuild_check_step .exported_variable ("NEED_REBUILD" ),
207
211
},
208
212
)
209
213
210
214
ci_run_step .add_step_dependency (prebuild_check_step )
211
215
212
- # pipeline.add_stage(
213
- # self,
214
- # post=[
215
- # CodeBuildRunStep(
216
- # f"{self.stage_name}-BuildStep",
217
- # name_prefix=self.stage_name,
218
- # input=input,
219
- # role=role,
220
- # stacks=[stack.stack_name for stack in self.stacks],
221
- # build_targets=self.build_targets,
222
- # max_retry=max_retry,
223
- # env=env,
224
- # )
225
- # ]
226
- # )
227
-
228
216
pipeline .add_stage (
229
217
self ,
230
218
post = [
@@ -233,6 +221,17 @@ def add_stage_to_pipeline(
233
221
]
234
222
)
235
223
236
-
237
-
238
-
224
+ class BatchBuildOptions :
225
+ def __init__ (
226
+ self ,
227
+ project : str ,
228
+ identifier : str = None ,
229
+ ignore_failure : bool = False ,
230
+ timeout : int = 120 ,
231
+ env : typing .Optional [typing .Mapping [str , str ]] = None
232
+ ):
233
+ self .project = project
234
+ self .identifier = identifier or re .sub (r'[^a-zA-Z0-9]' , '_' , project )
235
+ self .ignore_failure = ignore_failure
236
+ self .timeout = timeout
237
+ self .env = env
0 commit comments