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

Commit f0767a5

Browse files
mabreuortegaMiguel Abreu
andauthored
feat: add new secure build action to pipeline (#846)
Co-authored-by: Miguel Abreu <miabreu@amazon.com>
1 parent 53f5a98 commit f0767a5

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

buildspec.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ phases:
1919
build:
2020
commands:
2121
# Deploy
22-
./deploy.sh $ENVIRONMENT
22+
./deploy.sh $ENVIRONMENT $LANGUAGE $AUTH
2323

2424
artifacts:
2525
base-directory: cdk/cdk.out

cdk/lib/pipeline-stack.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export class PipelineStack extends cdk.Stack {
4343

4444
const sourceOutput = new codepipeline.Artifact();
4545
const buildOutput = new codepipeline.Artifact();
46+
const secureBuildOutput = new codepipeline.Artifact();
4647
const sourceAction = createSourceAction(scope, props, sourceOutput);
4748

4849
pipeline.addStage({
@@ -62,6 +63,33 @@ export class PipelineStack extends cdk.Stack {
6263
ENVIRONMENT: {
6364
value: "Gamma",
6465
},
66+
LANGUAGE: {
67+
value: "english",
68+
},
69+
AUTH: {
70+
value: "false",
71+
},
72+
},
73+
});
74+
75+
const buildSecure = new codebuild.PipelineProject(this, "Build-Secure", {
76+
environment: {
77+
buildImage: codebuild.LinuxBuildImage.AMAZON_LINUX_2_2,
78+
computeType: codebuild.ComputeType.LARGE,
79+
},
80+
environmentVariables: {
81+
CDK_ADMIN_EMAIL: {
82+
value: "johndoe@example.com",
83+
},
84+
ENVIRONMENT: {
85+
value: "GammaSecure",
86+
},
87+
LANGUAGE: {
88+
value: "english",
89+
},
90+
AUTH: {
91+
value: "true",
92+
},
6593
},
6694
});
6795

@@ -72,6 +100,13 @@ export class PipelineStack extends cdk.Stack {
72100
resources: ["*"],
73101
})
74102
);
103+
buildSecure.addToRolePolicy(
104+
new iam.PolicyStatement({
105+
effect: iam.Effect.ALLOW,
106+
actions: ["*"],
107+
resources: ["*"],
108+
})
109+
);
75110

76111
pipeline.addStage({
77112
stageName: "Gamma",
@@ -83,6 +118,13 @@ export class PipelineStack extends cdk.Stack {
83118
outputs: [buildOutput],
84119
runOrder: 1,
85120
}),
121+
new CodeBuildAction({
122+
actionName: "Build.and.Deploy.Secure",
123+
project: buildSecure,
124+
input: sourceOutput,
125+
outputs: [secureBuildOutput],
126+
runOrder: 2,
127+
}),
86128
],
87129
});
88130

@@ -106,6 +148,22 @@ export class PipelineStack extends cdk.Stack {
106148
],
107149
}
108150
);
151+
new codestarnotifications.CfnNotificationRule(
152+
this,
153+
"BuildNotificationRuleSecure",
154+
{
155+
detailType: "BASIC",
156+
resource: buildSecure.projectArn,
157+
name: "BuildNotificationsSecure",
158+
eventTypeIds: ["codebuild-project-build-state-failed"],
159+
targets: [
160+
{
161+
targetType: "SNS",
162+
targetAddress: notificationsTopic.topicArn,
163+
},
164+
],
165+
}
166+
);
109167
}
110168
}
111169

0 commit comments

Comments
 (0)