Skip to content

Commit dc77eb2

Browse files
committed
Incorporate comments
1 parent e1dd55f commit dc77eb2

11 files changed

+91
-90
lines changed

tests/ci/cdk/README.md

Lines changed: 82 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ AWS-LC CI uses AWS CDK to define and deploy AWS resources (e.g. AWS CodeBuild, E
3636
* step 4: click **Connect using OAuth** and **Connect to GitHub**.
3737
* step 5: follow the OAuth app to grant access.
3838
* Setup Python environment:
39+
3940
* From `aws-lc/tests/ci` run:
4041
```shell
4142
python -m pip install -r requirements.txt
@@ -83,75 +84,91 @@ To setup or update the CI in your account you will need the following IAM permis
8384
* secretsmanager:GetSecretValue
8485

8586
### Pipeline Commands
86-
Use these commands to deploy the CI pipeline. Any changes to the CI or Docker images will be updated automatically after the pipeline is deployed.
87-
88-
These commands are run from `aws-lc/tests/ci/cdk`.
89-
90-
[SKIP IF NO CROSS-ACCOUNT DEPLOYMENT] Give the pipeline account administrator access to the deployment account's CloudFormation. Repeat this step depending on how many deployment environment there are. You only need to run this step once when the pipeline is deploying to a new account for the first time.
91-
```
92-
cdk bootstrap aws://${DEPLOY_ACCOUNT_ID}/us-west-2 --trust ${PIPELINE_ACCOUNT_ID} --trust-for-lookup ${PIPELINE_ACCOUNT_ID} --cloudformation-execution-policies arn:aws:iam::aws:policy/AdministratorAccess
93-
```
94-
95-
If not done previously, bootstrap cdk for the pipeline account before running the next commands.
96-
```
97-
cdk bootstrap aws://${PIPELINE_ACCOUNT_ID}/us-west-2
98-
```
99-
100-
To deploy dev pipeline to the same account as your CI:
101-
```
102-
./run-cdk.sh --github-repo-owner ${GITHUB_REPO_OWNER} --github-source-version ${GITHUB_SOURCE_VERSION} --deploy-account ${DEPLOY_ACCOUNT_ID} --action deploy-dev-pipeline
103-
```
104-
105-
To deploy dev pipeline but pipeline is hosted in a separate account:
106-
```
107-
./run-cdk.sh --github-repo-owner ${GITHUB_REPO_OWNER} --github-source-version ${GITHUB_SOURCE_VERSION} --pipeline-account ${PIPELINE_ACCOUNT_ID} --deploy-account ${DEPLOY_ACCOUNT_ID} --action deploy-dev-pipeline
108-
```
109-
110-
To deploy production pipeline using default parameters:
111-
```
112-
./run-cdk.sh --action deploy-production-pipeline
113-
```
87+
Use the following commands to deploy the CI pipeline. Any changes to the CI or Docker images will be updated automatically after the pipeline is deployed.
88+
89+
1. Ensure you are in `aws-lc/tests/ci/cdk`
90+
2. Export the relevant environment variables:
91+
- `PIPELINE_ACCOUNT_ID`: the AWS account to host your pipeline
92+
- `DEPLOY_ACCOUNT_ID`: the AWS account to deploy Docker images and CodeBuild CI tests to.
93+
- `GITHUB_REPO_OWNER`: GitHub repo targeted by the pipeline (i.e, your personal Github account)
94+
- `GITHUB_SOURCE_VERSION`: Git branch holding the latest pipeline code (default: main)
95+
96+
3. [SKIP IF NO CROSS-ACCOUNT DEPLOYMENT] Give the pipeline account administrator access to the deployment account's CloudFormation. Repeat this step depending on how many deployment environment there are. You only need to run this step once when the pipeline is deploying to a new account for the first time.
97+
```shell
98+
cdk bootstrap aws://${DEPLOY_ACCOUNT_ID}/us-west-2 --trust ${PIPELINE_ACCOUNT_ID} --trust-for-lookup ${PIPELINE_ACCOUNT_ID} --cloudformation-execution-policies arn:aws:iam::aws:policy/AdministratorAccess
99+
```
100+
4. If not done previously, bootstrap cdk for the pipeline account before running the next commands.
101+
```shell
102+
cdk bootstrap aws://${PIPELINE_ACCOUNT_ID}/us-west-2
103+
```
104+
5. You may also need to request an increase to certain account quotas:
105+
```shell
106+
open https://${DEPLOY_REGION}.console.aws.amazon.com/servicequotas/home/services/ec2/quotas
107+
```
108+
Set EC2-VPC Elastic IPs = 20 (default is only 5)
109+
110+
111+
6. Choose 1 of the following options to deploy the pipeline:
112+
- To deploy dev pipeline to the same account as your CI
113+
```shell
114+
./run-cdk.sh --github-repo-owner ${GITHUB_REPO_OWNER} --github-source-version ${GITHUB_SOURCE_VERSION} --deploy-account ${PIPELINE_ACCOUNT_ID} --action deploy-dev-pipeline
115+
```
116+
- To deploy dev pipeline but pipeline is hosted in a separate account:
117+
```shell
118+
./run-cdk.sh --github-repo-owner ${GITHUB_REPO_OWNER} --github-source-version ${GITHUB_SOURCE_VERSION} --pipeline-account ${PIPELINE_ACCOUNT_ID} --deploy-account ${DEPLOY_ACCOUNT_ID} --action deploy-dev-pipeline
119+
```
120+
- To deploy production pipeline using default parameters:
121+
```shell
122+
./run-cdk.sh --action deploy-production-pipeline
123+
```
124+
125+
**Note**: If this is your first time deploying the pipeline and it's failing on the Source stage, this is normal and expected, since you haven't given CodePipeline access to your repo.
126+
To fix this:
127+
1. Go to your Console > CodePipeline > Settings > Connections. You should see a pending connection named `AwsLcCiPipelineGitHubConnection`. Click on it.
128+
2. Click on `Update Pending Connection.`
129+
3. On the pop up, you would see an `App Installation - optional`. Click on `Install a new app` (or choose an existing app if you have one). This step is REQUIRED to allow CodePipeline to detect new events from your repo.
130+
4. Click `Connect`. The connection status should become `Available` now
114131

115132
### CI Commands
116133
Use these commands if you wish to deploy individual stacks instead of the entire pipeline.
117134

118-
These commands are run from `aws-lc/tests/ci/cdk`.
119-
120-
If not done previously, bootstrap cdk before running the commands below. Make sure that AWS_ACCOUNT_ID is the AWS account you wish to deploy the CI stacks to.
121-
122-
```shell
123-
cdk bootstrap aws://${AWS_ACCOUNT_ID}/us-west-2
124-
```
125-
126-
You may also need to request an increase to certain account quotas:
127-
```shell
128-
open https://${DEPLOY_REGION}.console.aws.amazon.com/servicequotas/home/services/ec2/quotas
129-
```
130-
* **EC2-VPC Elastic IPs** = 20
131-
132-
Note: `GITHUB_REPO_OWNER` specifies the GitHub repo targeted by this CI setup.
133-
* https://github.com/${GITHUB_REPO_OWNER}/aws-lc.git
134-
135-
To set up AWS-LC CI, run command:
136-
```
137-
./run-cdk.sh --github-repo-owner ${GITHUB_REPO_OWNER} --action deploy-ci --deploy-account ${AWS_ACCOUNT_ID}
138-
```
139-
140-
To update AWS-LC CI, run command:
141-
```
142-
./run-cdk.sh --github-repo-owner ${GITHUB_REPO_OWNER} --action update-ci --deploy-account ${AWS_ACCOUNT_ID}
143-
```
144-
145-
To create/update Linux Docker images, run command:
146-
```
147-
./run-cdk.sh --github-repo-owner ${GITHUB_REPO_OWNER} --action build-linux-img --deploy-account ${AWS_ACCOUNT_ID}
148-
```
149-
150-
To destroy AWS-LC CI resources created above, run command:
151-
```
152-
# NOTE: this command will destroy all resources (AWS CodeBuild and ECR).
153-
./run-cdk.sh --github-repo-owner ${GITHUB_REPO_OWNER} --action destroy-ci --deploy-account ${AWS_ACCOUNT_ID}
154-
```
135+
1. Ensure you are in `aws-lc/tests/ci/cdk`
136+
2. Export the relevant environment variables:
137+
- `DEPLOY_ACCOUNT_ID`: AWS account you wish to deploy the CI stacks to
138+
- `GITHUB_REPO_OWNER`: the GitHub repo targeted by this CI setup.
139+
140+
2. If not done previously, bootstrap cdk before running the commands below.
141+
```shell
142+
cdk bootstrap aws://${DEPLOY_ACCOUNT_ID}/us-west-2
143+
```
144+
145+
3. You may also need to request an increase to certain account quotas:
146+
```shell
147+
open https://${DEPLOY_REGION}.console.aws.amazon.com/servicequotas/home/services/ec2/quotas
148+
```
149+
Set EC2-VPC Elastic IPs = 20 (default is only 5)
150+
151+
152+
4. Choose 1 of the following command options:
153+
- To set up AWS-LC CI, run command:
154+
```shell
155+
./run-cdk.sh --github-repo-owner ${GITHUB_REPO_OWNER} --action deploy-ci --deploy-account ${DEPLOY_ACCOUNT_ID}
156+
```
157+
158+
- To update AWS-LC CI, run command:
159+
```shell
160+
./run-cdk.sh --github-repo-owner ${GITHUB_REPO_OWNER} --action update-ci --deploy-account ${DEPLOY_ACCOUNT_ID}
161+
```
162+
- To create/update Linux Docker images, run command:
163+
```shell
164+
./run-cdk.sh --github-repo-owner ${GITHUB_REPO_OWNER} --action build-linux-img --deploy-account ${DEPLOY_ACCOUNT_ID}
165+
```
166+
167+
- To destroy AWS-LC CI resources created above, run command:
168+
```shell
169+
./run-cdk.sh --github-repo-owner ${GITHUB_REPO_OWNER} --action destroy-ci --deploy-account ${DEPLOY_ACCOUNT_ID}
170+
```
171+
NOTE: this command will destroy all resources (AWS CodeBuild and ECR).
155172

156173
For help, run command:
157174
```

tests/ci/cdk/pipeline/ci_stage.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ def add_stage_to_pipeline(
8080
"git remote add upstream https://github.com/aws/aws-lc.git",
8181
"git fetch upstream",
8282
"git checkout main",
83-
"git merge upstream/main",
84-
# "git push origin main",
83+
"git merge --ff-only upstream/main",
84+
"git push origin main",
8585
],
8686
env={
8787
"STAGING_GITHUB_REPO_OWNER": STAGING_GITHUB_REPO_OWNER,
@@ -98,7 +98,6 @@ def add_stage_to_pipeline(
9898
input=input,
9999
commands=[
100100
"cd tests/ci/cdk/pipeline/scripts",
101-
"chmod +x check_trigger_conditions.sh",
102101
'trigger_conditions=$(./check_trigger_conditions.sh --build-type ci --stacks "${STACKS}")',
103102
"export NEED_REBUILD=$(echo $trigger_conditions | sed -n 's/.*\(NEED_REBUILD=[0-9]*\).*/\\1/p' | cut -d'=' -f2 )",
104103
],
@@ -133,7 +132,6 @@ def add_stage_to_pipeline(
133132
input=input,
134133
commands=[
135134
"cd tests/ci/cdk/pipeline/scripts",
136-
"chmod +x build_target.sh",
137135
"./build_target.sh --build-type ci --project ${PROJECT} --max-retry ${MAX_RETRY} --timeout ${TIMEOUT}",
138136
],
139137
role=role,

tests/ci/cdk/pipeline/linux_docker_image_build_stage.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ def add_stage_to_wave(
8181
input=input,
8282
commands=[
8383
"cd tests/ci/cdk/pipeline/scripts",
84-
"chmod +x cleanup_orphaned_images.sh check_trigger_conditions.sh build_target.sh",
8584
'./cleanup_orphaned_images.sh --repos "${ECR_REPOS}"',
8685
'trigger_conditions=$(./check_trigger_conditions.sh --build-type docker --platform linux --stacks "${STACKS}")',
8786
"export NEED_REBUILD=$(echo $trigger_conditions | sed -n -e 's/.*\(NEED_REBUILD=[0-9]*\).*/\\1/p' | cut -d'=' -f2 )",

tests/ci/cdk/pipeline/pipeline_stack.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ def deploy_to_environment(
285285
input=source,
286286
commands=[
287287
"cd tests/ci/cdk/pipeline/scripts",
288-
"chmod +x finalize_images.sh",
289288
'./finalize_images.sh --repos "${ECR_REPOS}"',
290289
],
291290
env={

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

100644100755
File mode changed.

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

100644100755
File mode changed.

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

100644100755
File mode changed.

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

100644100755
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ else
1111
fi
1212

1313
function assume_role() {
14+
set +x
1415
if [[ -z ${CROSS_ACCOUNT_BUILD_ROLE_ARN} ]]; then
1516
echo "No role arn provided"
1617
return 1
@@ -21,6 +22,7 @@ function assume_role() {
2122
export AWS_ACCESS_KEY_ID=$(echo $CREDENTIALS | jq -r .Credentials.AccessKeyId)
2223
export AWS_SECRET_ACCESS_KEY=$(echo $CREDENTIALS | jq -r .Credentials.SecretAccessKey)
2324
export AWS_SESSION_TOKEN=$(echo $CREDENTIALS | jq -r .Credentials.SessionToken)
25+
set -x
2426
}
2527

2628
function refresh_session() {

tests/ci/cdk/pipeline/windows_docker_image_build_stage.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ def add_stage_to_wave(
7777
input=input,
7878
commands=[
7979
"cd tests/ci/cdk/pipeline/scripts",
80-
"chmod +x cleanup_orphaned_images.sh check_trigger_conditions.sh build_target.sh",
8180
'./cleanup_orphaned_images.sh --repos "${ECR_REPOS}"',
8281
'trigger_conditions=$(./check_trigger_conditions.sh --build-type docker --platform windows --stacks "${STACKS}")',
8382
"export NEED_REBUILD=$(echo $trigger_conditions | sed -n -e 's/.*\(NEED_REBUILD=[0-9]*\).*/\\1/p' | cut -d'=' -f2 )",

tests/ci/cdk/run-cdk.sh

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ function delete_s3_buckets() {
1616
aws s3api list-buckets --query "Buckets[].Name" | jq '.[]' | while read -r i; do
1717
bucket_name=$(echo "${i}" | tr -d '"')
1818
# Delete the bucket if its name uses AWS_LC_S3_BUCKET_PREFIX.
19-
# if [[ "${bucket_name}" == *"${AWS_LC_S3_BUCKET_PREFIX}"* ]]; then
20-
# aws s3 rm "s3://${bucket_name}" --recursive
21-
# aws s3api delete-bucket --bucket "${bucket_name}"
22-
# Delete bm-framework buckets if we're not on the team account
23-
if [[ "${DEPLOY_ACCOUNT}" != "620771051181" ]] && [[ "${bucket_name}" == *"${aws-lc-ci-bm-framework}"* ]]; then
19+
if [[ "${bucket_name}" == *"${S3_FOR_WIN_DOCKER_IMG_BUILD}"* ]]; then
2420
aws s3 rm "s3://${bucket_name}" --recursive
2521
aws s3api delete-bucket --bucket "${bucket_name}"
2622
fi
@@ -41,15 +37,15 @@ function delete_container_repositories() {
4137
}
4238

4339
function destroy_ci() {
44-
if [[ "${DEPLOY_ACCOUNT}" == "620771051181" ]]; then
40+
if [[ "${DEPLOY_ACCOUNT}" == "620771051181" || "${DEPLOY_ACCOUNT}" == "351119683581" ]]; then
4541
echo "destroy_ci should not be executed on team account."
4642
exit 1
4743
fi
4844
cdk destroy 'aws-lc-*' --force
4945
# CDK stack destroy does not delete s3 bucket automatically.
50-
# delete_s3_buckets
46+
delete_s3_buckets
5147
# CDK stack destroy does not delete ecr automatically.
52-
# delete_container_repositories
48+
delete_container_repositories
5349
}
5450

5551
function destroy_docker_img_build_stack() {
@@ -115,7 +111,7 @@ function run_windows_img_build() {
115111
--document-name "${WIN_DOCKER_BUILD_SSM_DOCUMENT}" \
116112
--output-s3-bucket-name "${S3_FOR_WIN_DOCKER_IMG_BUILD}" \
117113
--output-s3-key-prefix 'runcommand' \
118-
--parameters "TriggerType=[\"pipeline\"]" | \
114+
--parameters "TriggerType=[\"manual\"]" | \
119115
jq -r '.Command.CommandId')
120116
# Export for checking command run status.
121117
export WINDOWS_DOCKER_IMG_BUILD_COMMAND_ID="${command_id}"
@@ -177,9 +173,6 @@ function win_docker_img_build_status_check() {
177173
}
178174

179175
function build_linux_docker_images() {
180-
# Always destroy docker build stacks (which include EC2 instance) on EXIT.
181-
# trap destroy_docker_img_build_stack EXIT
182-
183176
# Create/update aws-ecr repo.
184177
cdk deploy 'aws-lc-ecr-linux-*' --require-approval never
185178

@@ -195,9 +188,6 @@ function build_linux_docker_images() {
195188
}
196189

197190
function build_win_docker_images() {
198-
# Always destroy docker build stacks (which include EC2 instance) on EXIT.
199-
# trap destroy_docker_img_build_stack EXIT
200-
201191
# Create/update aws-ecr repo.
202192
cdk deploy 'aws-lc-ecr-windows-*' --require-approval never
203193

tests/ci/cdk/util/metadata.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
# SPDX-License-Identifier: Apache-2.0 OR ISC
55

66
from util.env_util import EnvUtil
7-
from datetime import datetime
8-
9-
# timestamp = datetime.now().strftime('%Y-%m-%d-%H-%M')
107

118
# Used when AWS CDK defines AWS resources.
129
PROD_ACCOUNT = "620771051181"

0 commit comments

Comments
 (0)