Skip to content
This repository was archived by the owner on Feb 15, 2024. It is now read-only.

Commit aeebb29

Browse files
srijitmSrijit Mitra
and
Srijit Mitra
authored
Fixes and updates (#55)
Co-authored-by: Srijit Mitra <[email protected]>
1 parent 437f0fc commit aeebb29

File tree

11 files changed

+63
-25
lines changed

11 files changed

+63
-25
lines changed

bin/cicd.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ let cicdRoleName = config.deployment['cicdRoleName']
3232

3333
const app = new cdk.App()
3434

35-
new S3Stack(app, 'AWS-Simple-CICD-S3', { prefix, ssmRoot })
36-
new EmailHandlerStack(app, 'AWS-Simple-CICD-EmailHandler', { prefix, ssmRoot })
37-
new SemverHandlerStack(app, 'AWS-Simple-CICD-SemverHandler', { prefix, ssmRoot })
38-
new CicdStack(app, 'AWS-Simple-CICD', { prefix, ssmRoot, cicdRoleName, repos: config.simpleCicd})
35+
new S3Stack(app, 'AWS-Simple-CICD-01-S3', { prefix, ssmRoot })
36+
new EmailHandlerStack(app, 'AWS-Simple-CICD-02-EmailHandler', { prefix, ssmRoot })
37+
new SemverHandlerStack(app, 'AWS-Simple-CICD-03-SemverHandler', { prefix, ssmRoot })
38+
new CicdStack(app, 'AWS-Simple-CICD-04-SeedPipeline', { prefix, ssmRoot, cicdRoleName, repos: config.seedPipeline})
3939
new CicdStack(app, 'AWS-Simple-CICD-TeamOne', { prefix, ssmRoot, cicdRoleName, repos: config.teamOne})
4040
//new CicdStack(app, 'TeamTWo-CICD', { prefix, ssmRoot, repos: config.teamTwo})

config/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export interface ProjectConfig {
7272
test: string,
7373
prod: string
7474
},
75-
simpleCicd: Array<ProjectRepo>,
75+
seedPipeline: Array<ProjectRepo>,
7676
teamOne: Array<ProjectRepo>
7777
}
7878

lib/cicd-stack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class CicdStack extends cdk.Stack {
6767
const pipelineName = `${props.prefix}-${repo.pipelineName}-${repo.branch}`.replace(/\/|_/g, '-')
6868
const modulePipelineRole = new PipelineRole(this, `${pipelineName}PipelineRole`)
6969

70-
new SimpleCicdPipeline(this, `${pipelineName}-pipeline`, {
70+
new SimpleCicdPipeline(this, `${pipelineName}`, {
7171
artifactsBucket,
7272
prefix: props.prefix,
7373
ssmRoot: props.ssmRoot,

lib/iam/code-build-role.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ export default class CodeBuildRole extends iam.Role {
6666
'ecr:UploadLayerPart',
6767
'ecr:InitiateLayerUpload',
6868
'ecr:CompleteLayerUpload',
69-
'ecr:BatchCheckLayerAvailability'
69+
'ecr:BatchCheckLayerAvailability',
70+
'ssm:GetParameters'
7071
],
7172
resources: ['*']
7273
})

lib/pipelines/simple-cicd-pipeline.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ export class SimpleCicdPipeline extends Pipeline {
7878

7979
// Provision SNS Topic for notifications
8080
const notificationTopic = new sns.Topic(this, 'Topic', {
81-
displayName: `${prefix}-${repoName}-${repoBranch}-cicd-topic` ,
82-
topicName: `${prefix}-${repoName}-${repoBranch}-cicd-topic`
81+
displayName: `${pipelineName}-cicd-topic` ,
82+
topicName: `${pipelineName}-cicd-topic`
8383
})
8484

8585
new ssm.StringParameter(this, 'SnsTopicArn', {
@@ -141,14 +141,14 @@ export class SimpleCicdPipeline extends Pipeline {
141141
const buildOutputArtifact = new Artifact('BuildArtifact')
142142
const buildRole = new CodeBuildRole(this, 'buildRole')
143143

144-
const buildProject = new BuildProject(this, `${prefix}-${repoName}-${repoBranch}-build`, {
144+
const buildProject = new BuildProject(this, `${pipelineName}-build`, {
145145
repoName: repoName,
146146
role: buildRole,
147147
bucketArn: artifactsBucket.bucketArn,
148148
bucketName: artifactsBucket.bucketName
149149
})
150150

151-
buildProject.onStateChange('buildStatus', {
151+
buildProject.onStateChange('build', {
152152
target: new targets.LambdaFunction(emailHandler)
153153
})
154154

@@ -174,18 +174,27 @@ export class SimpleCicdPipeline extends Pipeline {
174174
actions: [buildAction, semverAction]
175175
})
176176

177+
// Push SemVer to Parameter Store
178+
let semverParam = `${ssmRoot}/simple-cicd/${repoName}/${repoBranch}/version`
179+
new ssm.StringParameter(this, `${repoName}${repoBranch}Version`, {
180+
description: `Version number of ${repoName}/${repoBranch}`,
181+
parameterName: semverParam,
182+
stringValue: '0.1.0'
183+
})
184+
177185
// Testing Stage
178186
const testOutputArtifact = new Artifact('TestArtifact')
179187
const testRole = new CodeBuildRole(this, 'testRole')
180188

181-
const testProject = new TestProject(this, `${prefix}-${repoName}-${repoBranch}-test`, {
189+
const testProject = new TestProject(this, `${pipelineName}-test`, {
182190
repoName: repoName,
183191
role: testRole,
184192
bucketArn: artifactsBucket.bucketArn,
185-
bucketName: artifactsBucket.bucketName
193+
bucketName: artifactsBucket.bucketName,
194+
semverParameter: semverParam
186195
})
187196

188-
testProject.onStateChange('testStatus', {
197+
testProject.onStateChange('test', {
189198
target: new targets.LambdaFunction(emailHandler)
190199
})
191200

@@ -216,16 +225,17 @@ export class SimpleCicdPipeline extends Pipeline {
216225
const deployRole = new CodeBuildRole(this, `${stageName}DeployRole`, { stageName })
217226
const deployProject = new DeployProject(
218227
this,
219-
`${prefix}-${repoName}-${repoBranch}-${stageName}-deploy`,
228+
`${pipelineName}-${stageName}-deploy`,
220229
{
221230
repoName: repoName,
222231
stageName: stageName,
223232
role: deployRole,
224233
bucketArn: artifactsBucket.bucketArn,
225-
bucketName: artifactsBucket.bucketName
234+
bucketName: artifactsBucket.bucketName,
235+
semverParameter: semverParam
226236
}
227237
)
228-
deployProject.onStateChange('deploymentStatus', {
238+
deployProject.onStateChange('deploy', {
229239
target: new targets.LambdaFunction(emailHandler)
230240
})
231241

@@ -262,10 +272,5 @@ export class SimpleCicdPipeline extends Pipeline {
262272
cwRule.addTarget(new targets.CodePipeline(this))
263273
}
264274

265-
new ssm.StringParameter(this, `${repoName}${repoBranch}Version`, {
266-
description: `Version number of ${repoName}/${repoBranch}`,
267-
parameterName: `${ssmRoot}/codecommit/${repoName}/${repoBranch}/version`,
268-
stringValue: '0.1.0'
269-
})
270275
}
271276
}

lib/projects/deploy-project.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface DeployProjectProps {
3030
bucketName: string
3131
bucketArn: string
3232
role: Role
33+
semverParameter: string
3334
}
3435

3536
export class DeployProject extends PipelineProject {
@@ -43,7 +44,10 @@ export class DeployProject extends PipelineProject {
4344
buildSpec: BuildSpec.fromObject({
4445
version: '0.2',
4546
env: {
46-
shell: 'bash'
47+
shell: 'bash',
48+
'parameter-store': {
49+
SEMVER: props.semverParameter
50+
}
4751
},
4852
phases: {
4953
install: {

lib/projects/test-project.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export interface BuildProjectProps extends ProjectProps {
2828
bucketName: string
2929
bucketArn: string
3030
role: Role
31+
semverParameter: string
3132
}
3233

3334
export class TestProject extends PipelineProject {
@@ -41,7 +42,10 @@ export class TestProject extends PipelineProject {
4142
buildSpec: BuildSpec.fromObject({
4243
version: '0.2',
4344
env: {
44-
shell: 'bash'
45+
shell: 'bash',
46+
'parameter-store': {
47+
SEMVER: props.semverParameter
48+
}
4549
},
4650
phases: {
4751
install: {

project-config.sample.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"test": "ca-central-1",
2525
"prod": "ca-central-1"
2626
},
27-
"simpleCicd": [
27+
"seedPipeline": [
2828
{
2929
"pipelineName": "simple-cicd",
3030
"repository": "aws-simple-cicd",

scripts/build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#! /bin/bash
2+
3+
echo "Nothing to build"

scripts/deploy.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#! /bin/bash
2+
3+
set -e
4+
set -u
5+
set -o pipefail
6+
7+
# Running CDK Project
8+
9+
# Install CDK
10+
npm install -g aws-cdk
11+
12+
# Install Dependencies
13+
npm install
14+
npm run build
15+
16+
# Deploy
17+
cdk bootstrap
18+
cdk deploy --all --require-approval never

scripts/test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#! /bin/bash
2+
3+
echo "Nothing to test"

0 commit comments

Comments
 (0)