Skip to content

Commit

Permalink
feat(wip): replace deprecated apis
Browse files Browse the repository at this point in the history
  • Loading branch information
stekern committed Jan 14, 2022
1 parent 894a54f commit 462150c
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 209 deletions.
252 changes: 95 additions & 157 deletions __snapshots__/app/cdk-pipeline-cdk-source.template.json

Large diffs are not rendered by default.

23 changes: 5 additions & 18 deletions __snapshots__/app/cdk-pipeline-cloud-assembly.template.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions __snapshots__/app/manifest.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples/cdk-pipelines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class LifligCdkPipelineCdkSourceStack extends Stack {
sourceType: "cdk-source",
})

pipeline.cdkPipeline.addApplicationStage(new ExampleStage(this, "example"))
pipeline.cdkPipeline.addStage(new ExampleStage(this, "example"))
}
}

Expand All @@ -48,6 +48,6 @@ export class LifligCdkPipelineCloudAssemblyStack extends Stack {
sourceType: "cloud-assembly",
})

pipeline.cdkPipeline.addApplicationStage(new ExampleStage(this, "example"))
pipeline.cdkPipeline.addStage(new ExampleStage(this, "example"))
}
}
4 changes: 2 additions & 2 deletions src/alarms/service-alarms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class ServiceAlarms extends cdk.Construct {
namespace: "AWS/ApplicationELB",
statistic: "Average",
period: cdk.Duration.seconds(60),
dimensions: {
dimensionsMap: {
TargetGroup: props.targetGroupFullName,
LoadBalancer: props.loadBalancerFullName,
},
Expand All @@ -108,7 +108,7 @@ export class ServiceAlarms extends cdk.Construct {
namespace: "AWS/ApplicationELB",
statistic: "Sum",
period: cdk.Duration.seconds(60),
dimensions: {
dimensionsMap: {
TargetGroup: props.targetGroupFullName,
LoadBalancer: props.loadBalancerFullName,
},
Expand Down
2 changes: 1 addition & 1 deletion src/cdk-pipelines/__tests__/slack-notification.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test("slack-notification", () => {
sourceType: "cloud-assembly",
})

pipeline.cdkPipeline.addApplicationStage(stage)
pipeline.cdkPipeline.addStage(stage)

pipeline.addSlackNotification({
slackWebhookUrl: "https://hooks.slack.com/services/abc",
Expand Down
43 changes: 25 additions & 18 deletions src/cdk-pipelines/liflig-cdk-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class LifligCdkPipeline extends cdk.Construct {
return `pipelines/${pipelineName}/trigger`
}

public readonly cdkPipeline: pipelines.CdkPipeline
public readonly cdkPipeline: pipelines.CodePipeline
public readonly codePipeline: codepipeline.Pipeline

constructor(scope: cdk.Construct, id: string, props: LifligCdkPipelineProps) {
Expand All @@ -127,23 +127,28 @@ export class LifligCdkPipeline extends cdk.Construct {

const cloudAssemblyArtifact = new codepipeline.Artifact()

let synth: pipelines.IFileSetProducer
let stages: codepipeline.StageProps[]

switch (props.sourceType) {
case "cloud-assembly":
stages = this.cloudAssemblyStage(
const cloudAssembly = this.cloudAssemblyStage(
cloudAssemblyArtifact,
artifactsBucket,
props.pipelineName,
)
synth = cloudAssembly.synth
stages = cloudAssembly.stages
break
case "cdk-source":
stages = this.cdkSourceStage(
const cdkSource = this.cdkSourceStage(
cloudAssemblyArtifact,
artifactsBucket,
props.pipelineName,
props.parametersNamespace ?? "default",
)
synth = cdkSource.synth
stages = cdkSource.stages
break
}

Expand All @@ -170,8 +175,8 @@ export class LifligCdkPipeline extends cdk.Construct {
restartExecutionOnUpdate: true,
})

this.cdkPipeline = new pipelines.CdkPipeline(this, "CdkPipeline", {
cloudAssemblyArtifact: cloudAssemblyArtifact,
this.cdkPipeline = new pipelines.CodePipeline(this, "CdkPipeline", {
synth,
codePipeline: this.codePipeline,
})
}
Expand All @@ -198,7 +203,7 @@ export class LifligCdkPipeline extends cdk.Construct {
cloudAssemblyArtifact: codepipeline.Artifact,
cdkBucket: s3.IBucket,
pipelineName: string,
): codepipeline.StageProps[] {
): { stages: codepipeline.StageProps[]; synth: pipelines.IFileSetProducer } {
const cloudAssemblyLookupFn = new lambda.Function(
this,
"CloudAssemblyLookupFn",
Expand All @@ -220,7 +225,11 @@ export class LifligCdkPipeline extends cdk.Construct {
objectKey: `pipelines/${pipelineName}/cloud-assembly.json`,
}

return [
const synth = pipelines.CodePipelineFileSet.fromArtifact(
cloudAssemblyArtifact,
)

const stages = [
{
stageName: "PrepareCloudAssembly",
actions: [
Expand All @@ -233,14 +242,15 @@ export class LifligCdkPipeline extends cdk.Construct {
],
},
]
return { stages, synth }
}

private cdkSourceStage(
cloudAssemblyArtifact: codepipeline.Artifact,
cdkBucket: s3.IBucket,
pipelineName: string,
parametersNamespace: string,
): codepipeline.StageProps[] {
): { stages: codepipeline.StageProps[]; synth: pipelines.IFileSetProducer } {
const prepareCdkSourceFn = new lambda.Function(this, "PrepareCdkSourceFn", {
code: lambda.Code.fromAsset(
path.join(__dirname, "../../assets/prepare-cdk-source-lambda"),
Expand Down Expand Up @@ -274,7 +284,12 @@ export class LifligCdkPipeline extends cdk.Construct {
parametersNamespace: parametersNamespace,
}

return [
const synth = new pipelines.ShellStep("GenerateCloudAssembly", {
input: pipelines.CodePipelineFileSet.fromArtifact(cdkSourceArtifact),
installCommands: ["npm ci"],
commands: ["npx cdk synth"],
})
const stages = [
{
stageName: "PrepareCdkSource",
actions: [
Expand All @@ -286,16 +301,8 @@ export class LifligCdkPipeline extends cdk.Construct {
}),
],
},
{
stageName: "GenerateCloudAssembly",
actions: [
pipelines.SimpleSynthAction.standardNpmSynth({
cloudAssemblyArtifact,
sourceArtifact: cdkSourceArtifact,
}),
],
},
]
return { stages, synth }
}

addSlackNotification(props: Omit<SlackNotificationProps, "pipeline">): void {
Expand Down
2 changes: 1 addition & 1 deletion src/ecs/fargate-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class FargateService extends cdk.Construct {
healthCheckGracePeriod: props.healthCheckGracePeriod,
desiredCount: props.desiredCount,
assignPublicIp: true,
securityGroup: this.securityGroup,
securityGroups: [this.securityGroup],
platformVersion: ecs.FargatePlatformVersion.VERSION1_4,
enableExecuteCommand: true,
...props.overrideFargateServiceProps,
Expand Down

0 comments on commit 462150c

Please sign in to comment.