Last active
May 22, 2022 22:27
-
-
Save SlootSantos/c8472521c3ef43f775c2360b1f315bb3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// updated application-stack.ts class | |
// note the buildSanityCheckCodeBuild method | |
import { Construct } from "constructs"; | |
import { CfnOutput, Stage, StageProps } from "aws-cdk-lib"; | |
import { BuildSpec, ComputeType } from "aws-cdk-lib/aws-codebuild"; | |
import { CodeBuildStep, CodePipelineSource } from "aws-cdk-lib/pipelines"; | |
import { DelegatedDomainStack } from "../stacks/application-stack"; | |
interface DelegatedDomainPipelineStageProps extends StageProps { | |
stage: "dev" | "prod"; | |
} | |
export class DelegatedDomainPipelineStage extends Stage { | |
delegatedSubdomain: CfnOutput; | |
delegatedNameServers: CfnOutput; | |
constructor( | |
scope: Construct, | |
id: string, | |
props: DelegatedDomainPipelineStageProps | |
) { | |
super(scope, id, props); | |
const delegationStack = new DelegatedDomainStack( | |
this, | |
"DelegatedDomainStack", | |
{ | |
stageConfig: { | |
stage: props.stage, | |
}, | |
} | |
); | |
this.delegatedSubdomain = delegationStack.delegatedSubdomain; | |
this.delegatedNameServers = delegationStack.delegatedNameServers; | |
} | |
buildSanityCheckCodeBuild(input: CodePipelineSource) { | |
const installCommands: string[] = [ | |
"sudo apt-get update -y", | |
"sudo apt-get install dnsutils -y", | |
]; | |
const buildCommands: string[] = ["./scripts/verify_dns.sh"]; | |
const buildPhases = { | |
install: { | |
commands: installCommands, | |
}, | |
build: { | |
commands: buildCommands, | |
}, | |
}; | |
return new CodeBuildStep("SanityCheckDNS", { | |
input, | |
buildEnvironment: { | |
privileged: true, | |
computeType: ComputeType.SMALL, | |
}, | |
envFromCfnOutputs: { | |
DELEGATED_DOMAIN_NAME: this.delegatedSubdomain, | |
DELEGATED_NAME_SERVERS: this.delegatedNameServers, | |
}, | |
commands: [], | |
partialBuildSpec: BuildSpec.fromObject({ | |
version: "0.2", | |
phases: buildPhases, | |
}), | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... ommiting the rest from pipeline.ts | |
applicationStages.forEach((stage) => { | |
const applicationDomain = new DelegatedDomainPipelineStage( | |
this, | |
`${stage.stageName}-${stage.targetAccount}`, | |
{ | |
stage: stage.stageName, | |
env: { | |
region: mainRegion, | |
account: stage.targetAccount, | |
}, | |
} | |
); | |
const sanityCheck = | |
applicationDomain.buildSanityCheckCodeBuild(cdkSourceInput); | |
pipeline.addStage(applicationDomain).addPost(sanityCheck); | |
}); | |
// ... omitting the past few lines |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment