Skip to content

Create pre-production stage for CI pipeline #2282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

nhatnghiho
Copy link
Contributor

@nhatnghiho nhatnghiho commented Mar 20, 2025

Issues:

Resolves #CryptoAlg-2983 and #CryptoAlg-2984

Description of changes:

This PR implements steps to deploy to pre-production in the CI pipeline, which will act as template for production deployment later on. The PR also sets up a dev deployment environment for testing purposes.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

@codecov-commenter
Copy link

codecov-commenter commented Mar 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.75%. Comparing base (652f7a9) to head (cf7cdeb).
Report is 38 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2282      +/-   ##
==========================================
- Coverage   79.02%   78.75%   -0.27%     
==========================================
  Files         614      620       +6     
  Lines      106934   107954    +1020     
  Branches    15145    15335     +190     
==========================================
+ Hits        84504    85023     +519     
- Misses      21777    22277     +500     
- Partials      653      654       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nhatnghiho nhatnghiho force-pushed the ci-pipeline branch 2 times, most recently from 267feb5 to b100ece Compare March 20, 2025 22:30
@nhatnghiho nhatnghiho force-pushed the ci-pipeline branch 3 times, most recently from 3f82970 to edbd376 Compare March 26, 2025 16:37
@nhatnghiho nhatnghiho marked this pull request as ready for review March 26, 2025 16:39
@nhatnghiho nhatnghiho requested a review from a team as a code owner March 26, 2025 16:39
@skmcgrail skmcgrail self-requested a review March 26, 2025 20:34
Comment on lines 63 to 65
if env.account == PRE_PROD_ACCOUNT:
github_repo_owner = STAGING_GITHUB_REPO_OWNER
github_repo_name = STAGING_GITHUB_REPO_NAME
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this work for deploying to your own personal account if you want to go through setting up the pipeline and all that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess these are correctly set to the values from the pipeline cdk_env in AwsLcCiPipeline?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's right, whenever you deploy the pipeline (using run-cdk.sh or manually with cdk deploy), the environment variables from your local terminal will passed to and retained in AwsLcCiPipeline through cdk_env

Comment on lines +115 to +120
### CI Commands
Use these commands if you wish to deploy individual stacks instead of the entire pipeline.

These commands are run from `aws-lc/tests/ci/cdk`.

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason to keep this support and documented?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is helpful if we want to deploy 1 stack at a time. Say, if I only want to deploy aws-lc-ci-integration and don't want to deal with anything else, these commands will come in handy.

Comment on lines +5 to +13
from aws_cdk import (
Duration,
Stack,
aws_codebuild as codebuild,
aws_iam as iam,
aws_s3_assets,
aws_logs as logs,
Environment,
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future it is much easier to review big changes like this if you don't reformat unrelated code. If there wasn't consistent formatting of this cdk code before your change it would much easier to review if one PR is just reformatting everything.


self.build_options = []

# Define CodeBuild Batch job for testing code.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this reuse any of the existing CDK definitions? In the future if we add a new build project to our public CI we might forget to update this spot as well.


self.build_options = []

# Define CodeBuild Batch job for testing code.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the CI that tests the code in PRs, or the CI that tests the pipeline and docker images is working?

Comment on lines 193 to 198
"curl -H \"Authorization: token ${GITHUB_PAT}\" https://api.github.com/user",
"git clone https://${GITHUB_PAT}@github.com/${STAGING_GITHUB_REPO_OWNER}/${STAGING_GITHUB_REPO_NAME}.git",
"git remote add upstream https://github.com/aws/aws-lc.git",
"git fetch upstream",
"git checkout main",
"git merge upstream/main",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you merging aws/aws-lc into the pr branch? What happens if there is a conflict?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is merging aws/aws-lc into our staging repo's main branch, not the pr branch. Since our staging repo is for testing only, it should never diverge from aws-lc. Conflicts should never happen. If they do, it means something is wrong with our staging repo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you updating the staging branch locally?

else {}
)

@jsii.member(jsii_name="produceAction")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, is there some functionality missing in the Python CDK? Have we given feedback to them about it

Comment on lines +138 to +141

self.output = {
"s3_bucket_name": f"{env.account}-{S3_FOR_WIN_DOCKER_IMG_BUILD}",
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see output member documented for Stack class. Are you intending for these to just be CfnOutputs or are you wanting them to be exported values from the stack? Would self.export_value(...) be more appropriate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried but that wouldn't work. export_values works for cross-stack dependencies. But since everything all belongs to AwsLcCiPipeline, the export won't be created by the time we need to reference in the stage's post actions

"git fetch upstream",
"git checkout main",
"git merge upstream/main",
# "git push origin main",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be uncommented?

"git remote add upstream https://github.com/aws/aws-lc.git",
"git fetch upstream",
"git checkout main",
"git merge upstream/main",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should specify --ff-only as well here.

input=input,
commands=[
"cd tests/ci/cdk/pipeline/scripts",
"chmod +x check_trigger_conditions.sh",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should just be corrected and committed to the repository with the correct permissions.

input=input,
commands=[
"cd tests/ci/cdk/pipeline/scripts",
"chmod +x build_target.sh",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto here about fixing the permissions and committing them.

input=input,
commands=[
"cd tests/ci/cdk/pipeline/scripts",
"chmod +x cleanup_orphaned_images.sh check_trigger_conditions.sh build_target.sh",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit the fixed permissions and then remove this line.

Comment on lines +21 to +23
export AWS_ACCESS_KEY_ID=$(echo $CREDENTIALS | jq -r .Credentials.AccessKeyId)
export AWS_SECRET_ACCESS_KEY=$(echo $CREDENTIALS | jq -r .Credentials.SecretAccessKey)
export AWS_SESSION_TOKEN=$(echo $CREDENTIALS | jq -r .Credentials.SessionToken)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might cause the credentials to get logged? Should we call set +x when entering this function, and then re-enabling it on exit?

Comment on lines +19 to +21
# if [[ "${bucket_name}" == *"${AWS_LC_S3_BUCKET_PREFIX}"* ]]; then
# aws s3 rm "s3://${bucket_name}" --recursive
# aws s3api delete-bucket --bucket "${bucket_name}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove the code if not needed anymore.

@@ -178,7 +178,7 @@ function win_docker_img_build_status_check() {

function build_linux_docker_images() {
# Always destroy docker build stacks (which include EC2 instance) on EXIT.
trap destroy_docker_img_build_stack EXIT
# trap destroy_docker_img_build_stack EXIT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, git keeps the history so just remove the code if not applicable anymore.

Comment on lines +7 to +9
from datetime import datetime

# timestamp = datetime.now().strftime('%Y-%m-%d-%H-%M')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment, and is import need anymore?

env=Environment(account=PIPELINE_ACCOUNT, region=PIPELINE_REGION),
)

if DEPLOY_ACCOUNT and DEPLOY_REGION:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these aren't set what happens when this calls app.synth?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants