Skip to content

Commit 0019f62

Browse files
Merge branch 'main' into sanchit/add-unhealthy-containers-table
2 parents 16dc6fa + 898096f commit 0019f62

File tree

28 files changed

+349
-80
lines changed

28 files changed

+349
-80
lines changed

cicd/1-setup/deploy-cicd-dependencies.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ then
2121
--stack-name javabuilder-cicd-deps \
2222
--template-file ${TEMPLATE_FILE} \
2323
--capabilities CAPABILITY_IAM \
24+
--tags EnvType=infrastructure \
2425
"$@"
2526

2627
echo Complete!

cicd/2-cicd/cicd.template.yml

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ Parameters:
2626
Type: String
2727
Description: The Resource Id component of the CodeStar connection ARN for the code-dot-org GitHub repository
2828
Default: 9e27ebd6-de25-495c-9a2d-b24077376de8
29-
Mode:
29+
EnvironmentType:
3030
Type: String
31-
Description: Whether this should create a pipeline for an 'adhoc' deployment or 'standard' pipeline.
32-
Default: standard
33-
AllowedValues: [adhoc, standard]
31+
Description: A 'production' cicd stack includes automated tests in the pipeline and deploys 'test' and 'production' environments. Whereas a 'development' type will only deploy a development environment.
32+
Default: production
33+
AllowedValues: [development, production]
3434

3535
Conditions:
3636
TargetsMainBranch: !Equals [ !Ref GitHubBranch, main ]
37-
DeployToAdhoc: !Equals [!Ref Mode, adhoc ]
38-
DeployToTestAndProd: !Equals [!Ref Mode, standard ]
37+
DeployForDevelopment: !Equals [!Ref EnvironmentType, development ]
38+
DeployForProduction: !Equals [!Ref EnvironmentType, production ]
3939

4040

4141
Resources:
@@ -296,8 +296,8 @@ Resources:
296296
- Name: appBuildResults
297297

298298
- !If
299-
- DeployToAdhoc
300-
- Name: Deploy_To_Adhoc
299+
- DeployForDevelopment
300+
- Name: Deploy_To_Development
301301
Actions:
302302
- Name: app-deploy
303303
ActionTypeId:
@@ -308,21 +308,21 @@ Resources:
308308
InputArtifacts:
309309
- Name: appBuildResults
310310
Configuration:
311-
StackName: !Sub "javabuilder-adhoc-${GitHubBranch}"
311+
StackName: !Sub "javabuilder-dev-${GitHubBranch}"
312312
ActionMode: CREATE_UPDATE
313313
TemplatePath: appBuildResults::packaged-app-template.yml
314-
TemplateConfiguration: appBuildResults::cicd/3-app/javabuilder/adhoc.config.json
314+
TemplateConfiguration: appBuildResults::cicd/3-app/javabuilder/dev.config.json
315315
ParameterOverrides: !Join
316316
- ''
317317
- - '{ "SubDomainName": "'
318-
- !Sub "javabuilder-adhoc-${GitHubBranch}"
318+
- !Sub "javabuilder-dev-${GitHubBranch}"
319319
- '" }'
320320
Capabilities: CAPABILITY_AUTO_EXPAND
321321
RoleArn: !Sub arn:aws:iam::${AWS::AccountId}:role/admin/CloudFormationService
322322
- !Ref AWS::NoValue
323323

324324
- !If
325-
- DeployToTestAndProd
325+
- DeployForProduction
326326
- Name: Deploy_To_Test
327327
Actions:
328328
- Name: app-deploy
@@ -348,7 +348,7 @@ Resources:
348348
- !Ref AWS::NoValue
349349

350350
- !If
351-
- DeployToTestAndProd
351+
- DeployForProduction
352352
- Name: Integration_Test
353353
Actions:
354354
- Name: integration-test
@@ -370,7 +370,7 @@ Resources:
370370
- !Ref AWS::NoValue
371371

372372
- !If
373-
- DeployToTestAndProd
373+
- DeployForProduction
374374
- Name: Deploy_To_Production
375375
Actions:
376376
- Name: app-deploy
@@ -395,6 +395,28 @@ Resources:
395395
Capabilities: CAPABILITY_AUTO_EXPAND
396396
RoleArn: !Sub arn:aws:iam::${AWS::AccountId}:role/admin/CloudFormationService
397397
- !Ref AWS::NoValue
398+
399+
- !If
400+
- DeployForProduction
401+
- Name: Smoke_Test
402+
Actions:
403+
- Name: smoke-test
404+
ActionTypeId:
405+
Category: Build
406+
Owner: AWS
407+
Provider: CodeBuild
408+
Version: 1
409+
InputArtifacts:
410+
- Name: sourceCode
411+
Configuration:
412+
ProjectName: !Ref IntegrationTestBuildProject
413+
EnvironmentVariables: !Sub
414+
- '[{"name":"APP_SUBDOMAIN","value":"${SUBDOMAIN}","type":"PLAINTEXT"},{"name":"APP_BASE_DOMAIN","value":"${BASE_DOMAIN}","type":"PLAINTEXT"}]'
415+
- BASE_DOMAIN: code.org
416+
SUBDOMAIN: !If [TargetsMainBranch, "javabuilder", !Sub "javabuilder-${GitHubBranch}"]
417+
OutputArtifacts:
418+
- Name: smokeTestResults
419+
- !Ref AWS::NoValue
398420

399421
# Send pipeline events to an SNS topic.
400422
# Note:

cicd/2-cicd/deploy-cicd.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ echo Deploying Javabuilder CICD Pipeline
55
# Create/Update the Javabuilder build/deploy pipeline stack. This is manually created and maintained, but should not require elevated permissions.
66
# Options include:
77
# - TARGET_BRANCH: Defaults to `main`, passed as a Parameter for "cicd/2-cicd/cicd.template.yml"
8-
# - MODE: Can be 'standard' (default) or 'adhoc', passed as a Parameter for "cicd/2-cicd/cicd.template.yml"
8+
# - ENVIRONMENT_TYPE: Can be 'production' (default) or 'development', passed as a Parameter for "cicd/2-cicd/cicd.template.yml"
99
# - GITHUB_BADGE_ENABLED: defaults to true, passed as a Parameter for "cicd/2-cicd/cicd.template.yml"
1010

1111
# 'Developer' role requires a specific service role for all CloudFormation operations.
@@ -16,14 +16,22 @@ fi
1616

1717
# Default to main branch, but support pipelines using other branches
1818
TARGET_BRANCH=${TARGET_BRANCH-'main'}
19+
1920
if [ "$TARGET_BRANCH" == "main" ]
2021
then
2122
STACK_NAME="javabuilder-cicd"
2223
else
23-
STACK_NAME="javabuilder-${TARGET_BRANCH}-cicd"
24+
# only allow alphanumeric branch names that may contain an internal hyphen.
25+
# to avoid complicated logic elsewhere, we're constraining it here.
26+
if [[ "$TARGET_BRANCH" =~ ^[a-z0-9]([-a-z0-9]*[a-z0-9])$ ]]; then
27+
STACK_NAME="javabuilder-${TARGET_BRANCH}-cicd"
28+
else
29+
echo "Invalid branch name '${TARGET_BRANCH}', branches must be alphanumeric and may contain hyphens."
30+
exit
31+
fi
2432
fi
2533

26-
MODE=${MODE-'standard'}
34+
ENVIRONMENT_TYPE=${ENVIRONMENT_TYPE-'production'}
2735
GITHUB_BADGE_ENABLED=${GITHUB_BADGE_ENABLED-'true'}
2836

2937
TEMPLATE_FILE=cicd/2-cicd/cicd.template.yml
@@ -42,8 +50,9 @@ then
4250
aws cloudformation deploy \
4351
--stack-name $STACK_NAME \
4452
--template-file $TEMPLATE_FILE \
45-
--parameter-overrides GitHubBranch=$TARGET_BRANCH GitHubBadgeEnabled=$GITHUB_BADGE_ENABLED Mode=$MODE \
53+
--parameter-overrides GitHubBranch=$TARGET_BRANCH GitHubBadgeEnabled=$GITHUB_BADGE_ENABLED EnvironmentType=$ENVIRONMENT_TYPE \
4654
--capabilities CAPABILITY_IAM \
55+
--tags EnvType=${ENVIRONMENT_TYPE} \
4756
"$@"
4857

4958
echo Complete!

cicd/3-app/deploy-load-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ aws cloudformation deploy \
2626
--template-file $TEMPLATE_FILE \
2727
--parameter-overrides LoadTestImage=$LOAD_TEST_IMAGE \
2828
--capabilities CAPABILITY_IAM \
29-
--tags javabuilder-mode=load-test \
29+
--tags javabuilder-mode=load-test EnvType=load-test \
3030
"$@"
3131

3232
echo Complete!

cicd/3-app/javabuilder/config/adhoc.config.json renamed to cicd/3-app/javabuilder/config/dev.config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@
77
"LimitPerHour": "50",
88
"LimitPerDay": "150",
99
"SilenceAlerts": "true"
10+
},
11+
"Tags" : {
12+
"EnvType" : "development"
1013
}
1114
}

cicd/3-app/javabuilder/config/production.config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@
77
"LimitPerHour": "150",
88
"LimitPerDay": "300",
99
"SilenceAlerts": "false"
10+
},
11+
"Tags" : {
12+
"EnvType" : "production"
1013
}
1114
}

cicd/3-app/javabuilder/config/test.config.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
"Parameters": {
33
"BaseDomainName": "code.org",
44
"BaseDomainNameHostedZonedID": "Z2LCOI49SCXUGU",
5-
"ProvisionedConcurrentExecutions": "1",
6-
"ReservedConcurrentExecutions": "3",
7-
"LimitPerHour": "15",
8-
"LimitPerDay": "40",
5+
"ProvisionedConcurrentExecutions": "5",
6+
"ReservedConcurrentExecutions": "25",
7+
"LimitPerHour": "50",
8+
"LimitPerDay": "150",
99
"SilenceAlerts": "false"
10+
},
11+
"Tags" : {
12+
"EnvType" : "test"
1013
}
1114
}

cicd/3-app/javabuilder/template.yml.erb

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -645,25 +645,26 @@ Resources:
645645
HighUsageCompositeAlarm:
646646
Type: AWS::CloudWatch::CompositeAlarm
647647
DependsOn:
648+
- ConsoleHighInvocationsAlarm
648649
- HighHttpRequestsAlarm
649-
- HighWebsocketConnectionsAlarm
650-
- NeighborhoodHighInvocationsAlarm
651-
- TheaterHighInvocationsAlarm
650+
- HighWebsocketConnectionsAlarm
651+
- NeighborhoodHighInvocationsAlarm
652+
- TheaterHighInvocationsAlarm
652653
Properties:
653654
ActionsEnabled: true
654655
AlarmActions:
655-
# TODO: after we have run at high usage for a while, consider re-enabling this alarm. Right now it is too noisy
656-
# - !If [SilenceAlertsCondition, !Ref AWS::NoValue, !Sub "arn:aws:sns:${AWS::Region}:${AWS::AccountId}:javabuilder-high-usage"]
657-
- !Ref AWS::NoValue
656+
# TODO: after we have run at high usage for a while, consider re-enabling this alarm. Right now it is too noisy
657+
# - !If [SilenceAlertsCondition, !Ref AWS::NoValue, !Sub "arn:aws:sns:${AWS::Region}:${AWS::AccountId}:javabuilder-high-usage"]
658+
- !Ref AWS::NoValue
658659
AlarmDescription: Send message if abnormally high Javabuilder usage detected.
659-
Monitors usage across the HTTP API, WebSocket API, and all Build and Run
660-
Lambdas.
660+
Monitors usage across the HTTP API, WebSocket API, and all Build and Run
661+
Lambdas.
661662
AlarmName: !Sub "${SubDomainName}_high_usage_composite"
662663
AlarmRule: !Sub "ALARM(${SubDomainName}_console_high_invocations) OR
663-
ALARM(${SubDomainName}_high_http_requests) OR
664-
ALARM(${SubDomainName}_high_websocket_connections) OR
665-
ALARM(${SubDomainName}_neighborhood_high_invocations) OR
666-
ALARM(${SubDomainName}_theater_high_invocations)"
664+
ALARM(${SubDomainName}_high_http_requests) OR
665+
ALARM(${SubDomainName}_high_websocket_connections) OR
666+
ALARM(${SubDomainName}_neighborhood_high_invocations) OR
667+
ALARM(${SubDomainName}_theater_high_invocations)"
667668
InsufficientDataActions: []
668669
OKActions: []
669670

cicd/README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ We also keep some CodeBuild configuration here, as this code tends to be more co
2020

2121
### 2 - CI/CD
2222

23-
In order to trigger the application resources to be updated upon changes to the source code, we need CI/CD resources. This is accomplished by a CloudFormation template that defines a stack of resources, primarily including a CodeBuild project and a CodePipeline pipeline which update the [App Stack](#3---app). These CI/CD resources only need to be deployed once per deployable branch, `main` in our case (we might choose to create adhoc environments by launching a new CI/CD stack targeting a different branch).
23+
In order to trigger the application resources to be updated upon changes to the source code, we need CI/CD resources. This is accomplished by a CloudFormation template that defines a stack of resources, primarily including a CodeBuild project and a CodePipeline pipeline which update the [App Stack](#3---app). These CI/CD resources only need to be deployed once per deployable branch, `main` in our case (we might choose to create development environments by launching a new CI/CD stack targeting a different branch).
2424

2525
These resources are deployed manually when changes occur. We could make yet another CodePipeline resource in the [Setup](#1---setup) section, but not today.
2626

@@ -47,19 +47,23 @@ Finally, all of the above need some Roles to exist in the AWS accounts before we
4747
2. Push a commit to `main`
4848
3. Press the "Release Change" button on the Pipeline overview page in the AWS Console.
4949

50-
### Deploying a CI/CD pipeline for a different branch
50+
### Deploying an Development environment
5151

52-
By setting the `TARGET_BRANCH` you can create a new CI/CD pipeline that watches for PR's and changes to the specified branch, deploying a Test and Production environment just like the standard pipeline.
52+
You can create an Development (aka 'adhoc') environment by setting the `ENVIRONMENT_TYPE` flag on the cicd deploy script. This will create a CI/CD pipeline that will watch for updates to your `TARGET_BRANCH`. The difference between a production and a development pipeline can be seen in "cicd.template.yml" by following where the `Conditions` are used. In short, an development pipeline creates a single environment using "dev.config.yml", while a production deployment will create a Test environment and a Prod environment using the relevent config files, running automated tests between them.
53+
54+
Notes:
55+
56+
* your branch name cannot contain the character `/`, as this causes issues in AWS. Note that resources will be deployed with the tags `{EnvType = development}`.
57+
* for now, these must deployed to the production AWS account. There is planned work to enable these to be deployed to the Dev AWS account.
5358

5459
```
55-
TARGET_BRANCH=mybranch cicd/2-cicd/deploy-cicd.sh
60+
TARGET_BRANCH=mybranch ENVIRONMENT_TYPE=development cicd/2-cicd/deploy-cicd.sh
5661
```
5762

58-
### Deploying an Adhoc environment
63+
### Deploying a full CI/CD pipeline for a different branch
5964

60-
You can create an Adhoc environment by setting the `MODE` flag on the cicd deploy script. This will create a CI/CD pipeline that will watch for updates to your `TARGET_BRANCH`. The difference between a standard deployment and an adhoc pipeline can be seen in "cicd.template.yml" by following where the `Conditions` are used. In short, an adhoc creates an adhoc environment using "adhoc.config.yml", while a standard deployment will create a Test environment and a Prod environment using the relevent config files.
61-
Note: your branch name cannot contain the character `\`, as this causes issues in AWS.
65+
By setting the `TARGET_BRANCH` you can create a new CI/CD pipeline that watches for PR's and changes to the specified branch, deploying a Test and Production environment just like the standard pipeline. Note that resources will be deployed with the tags `{EnvType = production}` or `{EnvType = test}`.
6266

6367
```
64-
TARGET_BRANCH=mybranch MODE=adhoc cicd/2-cicd/deploy-cicd.sh
68+
TARGET_BRANCH=mybranch cicd/2-cicd/deploy-cicd.sh
6569
```

deploy-beta.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,5 @@ aws cloudformation deploy \
6060
ProvisionedConcurrentExecutions=$PROVISIONED_CONCURRENT_EXECUTIONS ReservedConcurrentExecutions=$RESERVED_CONCURRENT_EXECUTIONS \
6161
LimitPerHour=$LIMIT_PER_HOUR LimitPerDay=$LIMIT_PER_DAY TeacherLimitPerHour=$TEACHER_LIMIT_PER_HOUR SilenceAlerts=$SILENCE_ALERTS \
6262
--stack-name ${STACK} \
63+
--tags EnvType=beta \
6364
"$@"

0 commit comments

Comments
 (0)