Skip to content

Commit 775eeed

Browse files
committed
Add step to auto-sync private repo
1 parent 7ec6289 commit 775eeed

File tree

5 files changed

+52
-8
lines changed

5 files changed

+52
-8
lines changed

tests/ci/cdk/pipeline/ci_stage.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import re
55
import typing
66

7-
from aws_cdk import Stage, Environment, Duration, pipelines, aws_iam as iam, Stack
7+
from aws_cdk import Stage, Environment, Duration, Stack, pipelines, aws_iam as iam, aws_codebuild as codebuild
88
from constructs import Construct
99

1010
from cdk.aws_lc_analytics_stack import AwsLcGitHubAnalyticsStack
@@ -13,6 +13,7 @@
1313
from cdk.aws_lc_github_ci_stack import AwsLcGitHubCIStack
1414
from cdk.aws_lc_github_fuzz_ci_stack import AwsLcGitHubFuzzCIStack
1515
from pipeline.codebuild_batch_step import CodeBuildBatchStep
16+
from util.metadata import PRE_PROD_ACCOUNT
1617

1718

1819
class CiStage(Stage):
@@ -173,6 +174,37 @@ def add_stage_to_pipeline(
173174
):
174175
stack_names = [stack.stack_name for stack in self.stacks]
175176

177+
private_repo_sync_step=None
178+
179+
if self.stacks[0].account == PRE_PROD_ACCOUNT:
180+
private_repo_sync_step = pipelines.CodeBuildStep(
181+
"PrivateRepoSync",
182+
build_environment=codebuild.BuildEnvironment(
183+
environment_variables={
184+
"GITHUB_PAT": codebuild.BuildEnvironmentVariable(
185+
type=codebuild.BuildEnvironmentVariableType.SECRETS_MANAGER,
186+
value="aws-lc/ci/github/token",
187+
),
188+
}
189+
),
190+
commands=[
191+
"env",
192+
"curl -H \"Authorization: token ${GITHUB_PAT}\" https://api.github.com/user",
193+
"git clone https://${GITHUB_PAT}@github.com/${STAGING_GITHUB_REPO_OWNER}/${STAGING_GITHUB_REPO_NAME}.git",
194+
"git remote add upstream https://github.com/aws/aws-lc.git",
195+
"git fetch upstream",
196+
"git checkout main",
197+
"git merge upstream/main",
198+
# "git push origin main",
199+
],
200+
env={
201+
"STAGING_GITHUB_REPO_OWNER": "aws",
202+
"STAGING_GITHUB_REPO_NAME": "private-aws-lc-staging",
203+
},
204+
role=role,
205+
timeout=Duration.minutes(60),
206+
)
207+
176208
env = env or {}
177209

178210
prebuild_check_step = pipelines.CodeBuildStep(
@@ -220,6 +252,7 @@ def add_stage_to_pipeline(
220252
],
221253
role=role,
222254
timeout=300,
255+
project_description=f"Pipeline step AwsLcCiPipeline/{self.stage_name}/StartWait",
223256
partial_batch_build_spec=batch_build_jobs,
224257
env={
225258
**env,
@@ -230,7 +263,11 @@ def add_stage_to_pipeline(
230263

231264
ci_run_step.add_step_dependency(prebuild_check_step)
232265

233-
pipeline.add_stage(self, post=[prebuild_check_step, ci_run_step])
266+
pipeline.add_stage(
267+
self,
268+
pre=[private_repo_sync_step] if private_repo_sync_step else None,
269+
post=[prebuild_check_step, ci_run_step]
270+
)
234271

235272

236273
class BatchBuildOptions:

tests/ci/cdk/pipeline/codebuild_batch_step.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def __init__(
4242
partial_batch_build_spec: typing.Mapping[builtins.str, typing.Any],
4343
role: iam.Role,
4444
timeout: int = 300,
45+
project_description: str = None,
4546
env: typing.Optional[typing.Mapping[str, str]] = None,
4647
):
4748
super().__init__(id)
@@ -54,6 +55,7 @@ def __init__(
5455
self.partial_batch_build_spec = partial_batch_build_spec
5556
self.role = role
5657
self.timeout = timeout
58+
self.project_description = project_description
5759
self.env = (
5860
{
5961
key: codebuild.BuildEnvironmentVariable(value=value)
@@ -80,6 +82,7 @@ def produce_action(
8082
}
8183
),
8284
role=self.role,
85+
description=self.project_description,
8386
timeout=Duration.minutes(self.timeout),
8487
)
8588

tests/ci/cdk/pipeline/pipeline_stack.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ def __init__(
5757
iam.PolicyStatement(
5858
effect=iam.Effect.ALLOW,
5959
resources=["*"],
60-
actions=["codepipeline:GetPipelineExecution"],
60+
actions=[
61+
"codepipeline:GetPipelineExecution",
62+
"secretsmanager:GetSecretValue",
63+
"kms:Decrypt"
64+
],
6165
)
6266
)
6367

tests/ci/cdk/pipeline/scripts/build_target.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ fi
165165

166166
if [[ ${BUILD_TYPE} == "docker" ]]; then
167167
if [[ -z "${PLATFORM+x}" || -z "${PLATFORM}" ]]; then
168-
echo "When building Docker images, a platform must be specified"
168+
echo "When building Docker images, a platform must be specified."
169169
exit 1
170170
fi
171171

@@ -179,7 +179,7 @@ fi
179179

180180
if [[ ${BUILD_TYPE} == "ci" ]]; then
181181
if [[ -z "${PROJECT+x}" || -z "${PROJECT}" ]]; then
182-
echo "When building CI tests, a project name must be specified"
182+
echo "When building CI tests, a project name must be specified."
183183
exit 1
184184
fi
185185

tests/ci/cdk/pipeline/setup_stage.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ def __init__(
5656

5757
cross_account_role = iam.Role(
5858
self,
59-
"CrossAccountCodeBuildRole",
60-
role_name="CrossAccountCodeBuildRole",
59+
"CrossAccountBuildRole",
60+
role_name="CrossAccountBuildRole",
6161
assumed_by=iam.ArnPrincipal(
6262
f"arn:aws:iam::{pipeline_environment.account}:role/CrossAccountPipelineRole"
63-
), # TODO: add a conditional to exclude this in dev env
63+
),
6464
)
6565

6666
# Grant access to all CodeBuild projects

0 commit comments

Comments
 (0)