Skip to content

Commit 497aac5

Browse files
Merge pull request #345 from code-dot-org/prod-cicd
Support adhocs and deploy to production environment.
2 parents 1106d59 + 672a4ce commit 497aac5

File tree

11 files changed

+1330
-132
lines changed

11 files changed

+1330
-132
lines changed

beta-template.yml.erb

Lines changed: 1115 additions & 0 deletions
Large diffs are not rendered by default.

cicd/2-cicd/cicd.template.yml

Lines changed: 110 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,18 @@ Parameters:
2525
CodeStarConnectionResourceId:
2626
Type: String
2727
Description: The Resource Id component of the CodeStar connection ARN for the code-dot-org GitHub repository
28-
Default: 7df08bcf-9883-42e8-8f5e-d083419d4fe9
28+
Default: 9e27ebd6-de25-495c-9a2d-b24077376de8
29+
Mode:
30+
Type: String
31+
Description: Whether this should create a pipeline for an 'adhoc' deployment or 'standard' pipeline.
32+
Default: standard
33+
AllowedValues: [adhoc, standard]
2934

3035
Conditions:
31-
TargetsMainBranch: !Equals
32-
- !Ref GitHubBranch
33-
- main
36+
TargetsMainBranch: !Equals [ !Ref GitHubBranch, main ]
37+
DeployToAdhoc: !Equals [!Ref Mode, adhoc ]
38+
DeployToTestAndProd: !Equals [!Ref Mode, standard ]
39+
3440

3541
Resources:
3642

@@ -211,7 +217,7 @@ Resources:
211217
JavabuilderRolePolicy:
212218
Type: 'AWS::IAM::Policy'
213219
Properties:
214-
PolicyName: root
220+
PolicyName: !Sub "${AWS::StackName}-codebuild-policy"
215221
PolicyDocument:
216222
Version: "2012-10-17"
217223
Statement:
@@ -261,7 +267,6 @@ Resources:
261267
ConnectionArn: !Sub arn:aws:codestar-connections:us-east-1:${AWS::AccountId}:connection/${CodeStarConnectionResourceId}
262268
FullRepositoryId: !Sub ${GitHubOwner}/${GitHubRepo}
263269
BranchName: !Ref GitHubBranch
264-
DetectChanges: true
265270

266271
- Name: Build
267272
Actions:
@@ -290,42 +295,106 @@ Resources:
290295
OutputArtifacts:
291296
- Name: appBuildResults
292297

293-
- Name: Deploy_To_Test
294-
Actions:
295-
- Name: app-deploy
296-
ActionTypeId:
297-
Category: Deploy
298-
Owner: AWS
299-
Version: 1
300-
Provider: CloudFormation
301-
InputArtifacts:
302-
- Name: appBuildResults
303-
Configuration:
304-
StackName: !If [TargetsMainBranch, "javabuilder-test", !Sub "javabuilder-${GitHubBranch}-test"]
305-
ActionMode: CREATE_UPDATE
306-
TemplatePath: appBuildResults::packaged-app-template.yml
307-
TemplateConfiguration: appBuildResults::cicd/3-app/javabuilder/test.config.json
308-
Capabilities: CAPABILITY_AUTO_EXPAND
309-
RoleArn: !Sub arn:aws:iam::${AWS::AccountId}:role/admin/CloudFormationService
298+
- !If
299+
- DeployToAdhoc
300+
- Name: Deploy_To_Adhoc
301+
Actions:
302+
- Name: app-deploy
303+
ActionTypeId:
304+
Category: Deploy
305+
Owner: AWS
306+
Version: 1
307+
Provider: CloudFormation
308+
InputArtifacts:
309+
- Name: appBuildResults
310+
Configuration:
311+
StackName: !Sub "javabuilder-adhoc-${GitHubBranch}"
312+
ActionMode: CREATE_UPDATE
313+
TemplatePath: appBuildResults::packaged-app-template.yml
314+
TemplateConfiguration: appBuildResults::cicd/3-app/javabuilder/adhoc.config.json
315+
ParameterOverrides: !Join
316+
- ''
317+
- - '{ "SubDomainName": "'
318+
- !Sub "javabuilder-adhoc-${GitHubBranch}"
319+
- '" }'
320+
Capabilities: CAPABILITY_AUTO_EXPAND
321+
RoleArn: !Sub arn:aws:iam::${AWS::AccountId}:role/admin/CloudFormationService
322+
- !Ref AWS::NoValue
310323

311-
- Name: Integration_Test
312-
Actions:
313-
- Name: integration-test
314-
ActionTypeId:
315-
Category: Build
316-
Owner: AWS
317-
Provider: CodeBuild
318-
Version: 1
319-
InputArtifacts:
320-
- Name: sourceCode
321-
Configuration:
322-
ProjectName: !Ref IntegrationTestBuildProject
323-
EnvironmentVariables: !Sub
324-
- '[{"name":"APP_SUBDOMAIN","value":"${SUBDOMAIN}","type":"PLAINTEXT"},{"name":"APP_BASE_DOMAIN","value":"${BASE_DOMAIN}","type":"PLAINTEXT"}]'
325-
- BASE_DOMAIN: code.org
326-
SUBDOMAIN: !If [TargetsMainBranch, "javabuilder-test", !Sub "javabuilder-${GitHubBranch}-test"]
327-
OutputArtifacts:
328-
- Name: integrationTestResultsPOC
324+
- !If
325+
- DeployToTestAndProd
326+
- Name: Deploy_To_Test
327+
Actions:
328+
- Name: app-deploy
329+
ActionTypeId:
330+
Category: Deploy
331+
Owner: AWS
332+
Version: 1
333+
Provider: CloudFormation
334+
InputArtifacts:
335+
- Name: appBuildResults
336+
Configuration:
337+
StackName: !If [TargetsMainBranch, "javabuilder-test", !Sub "javabuilder-${GitHubBranch}-test"]
338+
ActionMode: CREATE_UPDATE
339+
TemplatePath: appBuildResults::packaged-app-template.yml
340+
TemplateConfiguration: appBuildResults::cicd/3-app/javabuilder/test.config.json
341+
ParameterOverrides: !Join
342+
- ''
343+
- - '{ "SubDomainName": "'
344+
- !If [ TargetsMainBranch, 'javabuilder-test', !Sub 'javabuilder-${GitHubBranch}-test' ]
345+
- '" }'
346+
Capabilities: CAPABILITY_AUTO_EXPAND
347+
RoleArn: !Sub arn:aws:iam::${AWS::AccountId}:role/admin/CloudFormationService
348+
- !Ref AWS::NoValue
349+
350+
- !If
351+
- DeployToTestAndProd
352+
- Name: Integration_Test
353+
Actions:
354+
- Name: integration-test
355+
ActionTypeId:
356+
Category: Build
357+
Owner: AWS
358+
Provider: CodeBuild
359+
Version: 1
360+
InputArtifacts:
361+
- Name: sourceCode
362+
Configuration:
363+
ProjectName: !Ref IntegrationTestBuildProject
364+
EnvironmentVariables: !Sub
365+
- '[{"name":"APP_SUBDOMAIN","value":"${SUBDOMAIN}","type":"PLAINTEXT"},{"name":"APP_BASE_DOMAIN","value":"${BASE_DOMAIN}","type":"PLAINTEXT"}]'
366+
- BASE_DOMAIN: code.org
367+
SUBDOMAIN: !If [TargetsMainBranch, "javabuilder-test", !Sub "javabuilder-${GitHubBranch}-test"]
368+
OutputArtifacts:
369+
- Name: integrationTestResultsPOC
370+
- !Ref AWS::NoValue
371+
372+
- !If
373+
- DeployToTestAndProd
374+
- Name: Deploy_To_Production
375+
Actions:
376+
- Name: app-deploy
377+
ActionTypeId:
378+
Category: Deploy
379+
Owner: AWS
380+
Version: 1
381+
Provider: CloudFormation
382+
InputArtifacts:
383+
- Name: appBuildResults
384+
# The value of `Configuration` must be an object with String (or simple type) properties
385+
Configuration:
386+
StackName: !If [TargetsMainBranch, "javabuilder", !Sub "javabuilder-${GitHubBranch}"]
387+
ActionMode: CREATE_UPDATE
388+
TemplatePath: appBuildResults::packaged-app-template.yml
389+
TemplateConfiguration: appBuildResults::cicd/3-app/javabuilder/production.config.json
390+
ParameterOverrides: !Join
391+
- ''
392+
- - '{ "SubDomainName": "'
393+
- !If [ TargetsMainBranch, 'javabuilder', !Sub 'javabuilder-${GitHubBranch}' ]
394+
- '" }'
395+
Capabilities: CAPABILITY_AUTO_EXPAND
396+
RoleArn: !Sub arn:aws:iam::${AWS::AccountId}:role/admin/CloudFormationService
397+
- !Ref AWS::NoValue
329398

330399
# Send pipeline events to an SNS topic.
331400
# Note: Integration with Slack via AWS ChatBot is configured manually via AWS Console.

cicd/2-cicd/deploy-cicd.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
echo Deploying Javabuilder CICD Pipeline
44

5-
# Create/Update the Javabuilder build/deploy pipeline stack. This is manually created and maintained, but should not require elevated permissions.
5+
# Create/Update the Javabuilder build/deploy pipeline stack. This is manually created and maintained, but should not require elevated permissions.
6+
# Options include:
7+
# - 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"
9+
# - GITHUB_BADGE_ENABLED: defaults to true, passed as a Parameter for "cicd/2-cicd/cicd.template.yml"
610

711
# 'Developer' role requires a specific service role for all CloudFormation operations.
812
if [[ $(aws sts get-caller-identity --query Arn --output text) =~ "assumed-role/Developer/" ]]; then
@@ -14,11 +18,12 @@ fi
1418
TARGET_BRANCH=${TARGET_BRANCH-'main'}
1519
if [ "$TARGET_BRANCH" == "main" ]
1620
then
17-
STACK_NAME=${STACK_NAME-'javabuilder-cicd'}
21+
STACK_NAME="javabuilder-cicd"
1822
else
19-
STACK_NAME=${STACK_NAME-"javabuilder-$TARGET_BRANCH-cicd"}
23+
STACK_NAME=${"javabuilder-$TARGET_BRANCH-cicd"}
2024
fi
2125

26+
MODE=${MODE-'standard'}
2227
GITHUB_BADGE_ENABLED=${GITHUB_BADGE_ENABLED-'true'}
2328

2429
TEMPLATE_FILE=cicd/2-cicd/cicd.template.yml
@@ -37,7 +42,7 @@ then
3742
aws cloudformation deploy \
3843
--stack-name $STACK_NAME \
3944
--template-file $TEMPLATE_FILE \
40-
--parameter-overrides GitHubBranch=$TARGET_BRANCH GitHubBadgeEnabled=$GITHUB_BADGE_ENABLED \
45+
--parameter-overrides GitHubBranch=$TARGET_BRANCH GitHubBadgeEnabled=$GITHUB_BADGE_ENABLED Mode=$MODE \
4146
--capabilities CAPABILITY_IAM \
4247
"$@"
4348

cicd/3-app/javabuilder/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
*.config.json
1+
# ignore files generated by 'create-environment-config.sh'
2+
./*.config.json
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"Parameters": {
3+
"BaseDomainName": "code.org",
4+
"BaseDomainNameHostedZonedID": "Z2LCOI49SCXUGU",
5+
"ProvisionedConcurrentExecutions": "1",
6+
"ReservedConcurrentExecutions": "3",
7+
"LimitPerHour": "50",
8+
"LimitPerDay": "150",
9+
"SilenceAlerts": "true"
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"Parameters": {
3+
"BaseDomainName": "code.org",
4+
"BaseDomainNameHostedZonedID": "Z2LCOI49SCXUGU",
5+
"ProvisionedConcurrentExecutions": "150",
6+
"ReservedConcurrentExecutions": "1650",
7+
"LimitPerHour": "150",
8+
"LimitPerDay": "300",
9+
"SilenceAlerts": "false"
10+
}
11+
}

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

Lines changed: 0 additions & 12 deletions
This file was deleted.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"Parameters": {
3-
"SubDomainName": "javabuilder-test",
43
"BaseDomainName": "code.org",
54
"BaseDomainNameHostedZonedID": "Z2LCOI49SCXUGU",
65
"ProvisionedConcurrentExecutions": "1",

0 commit comments

Comments
 (0)