Skip to content

Commit 310e375

Browse files
committed
Update cdk instructions
1 parent 45a1b91 commit 310e375

File tree

2 files changed

+123
-18
lines changed

2 files changed

+123
-18
lines changed

tests/ci/cdk/README.md

Lines changed: 69 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,26 @@
22

33
AWS-LC CI uses AWS CDK to define and deploy AWS resources (e.g. AWS CodeBuild, ECR).
44

5-
## CI Setup
5+
## Table of Contents
6+
- [CI Setup](#ci-setup)
7+
- [Before running CDK command](#before-running-cdk-command)
8+
- [Minimal permissions](#minimal-permissions)
9+
- [Pipeline Commands](#pipeline-commands)
10+
- [CI Commands](#ci-commands)
11+
- [AWS-LC Benchmarking Framework](#aws-lc-benchmarking-framework)
12+
- [Framework Setup](#framework-setup)
13+
- [How to Use](#how-to-use)
14+
- [Start from Pull Request](#start-from-pull-request)
15+
- [Start Locally](#start-locally)
16+
- [Examine Output](#examine-output)
17+
- [Files](#files)
18+
- [Development Reference](#development-reference)
19+
- [Useful commands](#useful-commands)
20+
- [Useful Docker image build commands](#useful-docker-image-build-commands)
21+
- [Linux Docker image build](#linux-docker-image-build)
22+
- [Windows Docker image build (DEPRECATED)](#windows-docker-image-build-deprecated)
23+
24+
## CDK Setup
625

726
### Before running CDK command:
827

@@ -64,7 +83,36 @@ To setup or update the CI in your account you will need the following IAM permis
6483
* secretsmanager:GetSecretValue
6584

6685
### Pipeline Commands
67-
Bootstrap pipeline account
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+
If not done previously, bootstrap cdk for the pipeline account before running the next commands.
91+
```
92+
cdk bootstrap aws://${PIPELINE_ACCOUNT_ID}/us-west-2
93+
```
94+
95+
[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.
96+
```
97+
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
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-acount ${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+
```
114+
115+
<!-- Bootstrap pipeline account
68116
```
69117
AWS_ACCOUNT_ID=183295444613
70118
PIPELINE_ACCOUNT_ID=774305600158
@@ -81,19 +129,22 @@ Deploy pipeline
81129
GITHUB_REPO_OWNER=nhatnghiho
82130
GITHUB_SOURCE_VERSION=ci-pipeline
83131
./run-cdk.sh --github-repo-owner ${GITHUB_REPO_OWNER} --github-source-version ${GITHUB_SOURCE_VERSION} --aws-account ${AWS_ACCOUNT_ID} --action invoke --command "cdk deploy AwsLcCiPipeline --require-approval never"
84-
```
132+
``` -->
133+
134+
### CI Commands
135+
Use these commands if you wish to deploy individual stacks instead of the entire pipeline.
136+
137+
These commands are run from `aws-lc/tests/ci/cdk`.
85138

86-
### Commands
139+
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.
87140

88-
These commands are run from `aws-lc/tests/ci/cdk`. \
89-
If not done previously, bootstrap cdk before running the commands below:
90141
```shell
91142
cdk bootstrap aws://${AWS_ACCOUNT_ID}/us-west-2
92143
```
93144

94145
You may also need to request an increase to certain account quotas:
95146
```shell
96-
open https://${CDK_DEPLOY_REGION}.console.aws.amazon.com/servicequotas/home/services/ec2/quotas
147+
open https://${DEPLOY_REGION}.console.aws.amazon.com/servicequotas/home/services/ec2/quotas
97148
```
98149
* **EC2-VPC Elastic IPs** = 20
99150

@@ -102,23 +153,23 @@ Note: `GITHUB_REPO_OWNER` specifies the GitHub repo targeted by this CI setup.
102153

103154
To set up AWS-LC CI, run command:
104155
```
105-
./run-cdk.sh --github-repo-owner ${GITHUB_REPO_OWNER} --action deploy-ci --aws-account ${AWS_ACCOUNT_ID}
156+
./run-cdk.sh --github-repo-owner ${GITHUB_REPO_OWNER} --action deploy-ci --deploy-account ${AWS_ACCOUNT_ID}
106157
```
107158

108159
To update AWS-LC CI, run command:
109160
```
110-
./run-cdk.sh --github-repo-owner ${GITHUB_REPO_OWNER} --action update-ci --aws-account ${AWS_ACCOUNT_ID}
161+
./run-cdk.sh --github-repo-owner ${GITHUB_REPO_OWNER} --action update-ci --deploy-account ${AWS_ACCOUNT_ID}
111162
```
112163

113164
To create/update Linux Docker images, run command:
114165
```
115-
./run-cdk.sh --github-repo-owner ${GITHUB_REPO_OWNER} --action build-linux-img --aws-account ${AWS_ACCOUNT_ID}
166+
./run-cdk.sh --github-repo-owner ${GITHUB_REPO_OWNER} --action build-linux-img --deploy-account ${AWS_ACCOUNT_ID}
116167
```
117168

118169
To destroy AWS-LC CI resources created above, run command:
119170
```
120171
# NOTE: this command will destroy all resources (AWS CodeBuild and ECR).
121-
./run-cdk.sh --github-repo-owner ${GITHUB_REPO_OWNER} --action destroy-ci --aws-account ${AWS_ACCOUNT_ID}
172+
./run-cdk.sh --github-repo-owner ${GITHUB_REPO_OWNER} --action destroy-ci --deploy-account ${AWS_ACCOUNT_ID}
122173
```
123174

124175
For help, run command:
@@ -175,6 +226,10 @@ Below is CI file structure.
175226
│   ├── __init__.py
176227
│   ├── ecr_stack.py
177228
│   ├── ...
229+
├── pipeline
230+
│   ├── __init__.py
231+
│   ├── pipeline_stack.py
232+
│   ├── ...
178233
├── cdk.json
179234
├── requirements.txt
180235
├── run-cdk.sh
@@ -187,7 +242,8 @@ Below is CI file structure.
187242
* `README.md` — The introductory README for this project.
188243
* `app.py` — The “main” for this sample application.
189244
* `cdk.json` — A configuration file for CDK that defines what executable CDK should run to generate the CDK construct tree.
190-
* `cdk` — A CDK module directory
245+
* `cdk` — A module directory that contains all CI-related stacks and utilities
246+
* `pipeline` - A module directory that defines a continuous deployment pipeline for the CI.
191247
* `requirements.txt` — This file is used by pip to install all of the dependencies for your application. In this case, it contains only -e . This tells pip to install the requirements specified in setup.py. It also tells pip to run python setup.py develop to install the code in the cdk module so that it can be edited in place.
192248
* `setup.py` — Defines how this Python package would be constructed and what the dependencies are.
193249

@@ -264,7 +320,7 @@ aws codebuild start-build-batch --project-name aws-lc-docker-image-build-linux
264320
# Go to AWS console, you can check CodeBuild by clicking "Developer Tools > CodeBuild > Build projects".
265321
```
266322

267-
#### Windows Docker image build
323+
#### Windows Docker image build (DEPRECATED)
268324
Windows docker image build requires more resources (like EC2 host, S3, SSM and so on) set up because DIND (Docker in Docker) is not supported by Windows.
269325
Below are some commands specific to windows docker image build.
270326

tests/ci/cdk/run-cdk.sh

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,33 @@ function setup_ci() {
225225
create_android_resources
226226
}
227227

228+
function deploy_production_pipeline() {
229+
cdk deploy AwsLcCiPipeline --require-approval never
230+
}
231+
232+
function deploy_dev_pipeline() {
233+
if [[ -z "${DEPLOY_ACCOUNT:+x}" || -z "${PIPELINE_ACCOUNT}" ]]; then
234+
echo "The pipeline needs a deployment acount to know where to deploy the CI to."
235+
exit 1
236+
fi
237+
238+
if [[ ${DEPLOY_ACCOUNT} == '620771051181' ]]; then
239+
echo "Dev pipeline cannot deploy to production account."
240+
exit 1
241+
fi
242+
243+
if [[ -z "${PIPELINE_ACCOUNT+x}" || -z "${PIPELINE_ACCOUNT}" ]]; then
244+
export PIPELINE_ACCOUNT=DEPLOY_ACCOUNT
245+
fi
246+
247+
if [[ ${PIPELINE_ACCOUNT+x} == '774305600158' ]]; then
248+
echo "Cannot deploy. The production pipeline is hosted with the same name in this pipeline account."
249+
exit 1
250+
fi
251+
252+
cdk deploy AwsLcCiPipeline --require-approval never
253+
}
254+
228255
function create_android_resources() {
229256
# Use aws cli to create Device Farm project and get project arn to create device pools.
230257
# TODO: Move resource creation to aws cdk when cdk has support for device form resource constructs.
@@ -285,6 +312,7 @@ Options:
285312
'diff': compares the specified stack with the deployed stack.
286313
'synth': synthesizes and prints the CloudFormation template for the stacks.
287314
'bootstrap': Bootstraps the CDK stack. This is needed before deployment or updating the CI.
315+
'invoke': invoke a custom command. Provide the custom command through '--command <YOUR_CUSTOM_COMMAND>'
288316
EOF
289317
}
290318

@@ -311,11 +339,12 @@ function export_global_variables() {
311339
export ECR_WINDOWS_X86_REPO_NAME='aws-lc-docker-images-windows-x86'
312340
export AWS_LC_S3_BUCKET_PREFIX='aws-lc-windows-docker-image-build-s3'
313341
export WIN_EC2_TAG_KEY='aws-lc'
314-
export WIN_EC2_TAG_VALUE="aws-lc-windows-docker-image-build"
315-
export WIN_DOCKER_BUILD_SSM_DOCUMENT="AWSLC-BuildWindowsDockerImagesTEST"
342+
export WIN_EC2_TAG_VALUE='aws-lc-windows-docker-image-build'
343+
export WIN_DOCKER_BUILD_SSM_DOCUMENT='AWSLC-BuildWindowsDockerImages'
344+
export MAX_TEST_RETRY=2
316345
export IMG_BUILD_STATUS='unknown'
317346
# 620771051181 and 351119683581 is AWS-LC team AWS account.
318-
if [[ "${DEPLOY_ACCOUNT}" != "620771051181" && "${DEPLOY_ACCOUNT}" != "351119683581" ]] && [[ "${GITHUB_REPO_OWNER}" == 'aws' ]]; then
347+
if [[ "${DEPLOY_ACCOUNT}" != "620771051181" && "${DEPLOY_ACCOUNT}" != '351119683581' ]] && [[ "${GITHUB_REPO_OWNER}" == 'aws' ]]; then
319348
echo "Only team account is allowed to create CI stacks on aws repo."
320349
exit 1
321350
fi
@@ -329,15 +358,23 @@ function main() {
329358
script_helper
330359
exit 0
331360
;;
332-
--aws-account)
361+
--deploy-account)
333362
export DEPLOY_ACCOUNT="${2}"
334363
shift
335364
;;
336-
--aws-region)
365+
--deploy-region)
337366
export DEPLOY_REGION="${2}"
338367
export AWS_DEFAULT_REGION="${DEPLOY_REGION}"
339368
shift
340369
;;
370+
--pipeline-account)
371+
export PIPELINE_ACCOUNT="${2}"
372+
shift
373+
;;
374+
--pipeline-region)
375+
export PIPELINE_REGION="${2}"
376+
shift
377+
;;
341378
--github-repo-owner)
342379
export GITHUB_REPO_OWNER="${2}"
343380
shift
@@ -374,6 +411,14 @@ function main() {
374411

375412
# Execute the action.
376413
case ${ACTION} in
414+
deploy-production-pipeline)
415+
export IS_DEV="False"
416+
deploy_production_pipeline
417+
;;
418+
deploy-dev-pipeline)
419+
export IS_DEV="True"
420+
deploy_dev_pipeline
421+
;;
377422
deploy-ci)
378423
setup_ci
379424
;;
@@ -405,6 +450,10 @@ function main() {
405450
cdk bootstrap
406451
;;
407452
invoke)
453+
if [[ -z "${COMMAND+x}" || -z "${COMMAND}" ]]; then
454+
echo "--action invoke requires a command."
455+
exit 1
456+
fi
408457
${COMMAND:?}
409458
;;
410459
*)

0 commit comments

Comments
 (0)