Skip to content

Instantly share code, notes, and snippets.

@SlootSantos
Last active May 22, 2022 22:27
Show Gist options
  • Save SlootSantos/c8472521c3ef43f775c2360b1f315bb3 to your computer and use it in GitHub Desktop.
Save SlootSantos/c8472521c3ef43f775c2360b1f315bb3 to your computer and use it in GitHub Desktop.
// 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,
}),
});
}
}
// ... 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