Skip to content

Commit 302ec79

Browse files
committed
fix(pipelines): propagate CodeBuild fleet and certificate
These properties were simply overlooked. I added a TypeScript `satisfies` assertion to ensure that newly added properties are not missed here.
1 parent a02c656 commit 302ec79

File tree

7 files changed

+134
-9
lines changed

7 files changed

+134
-9
lines changed

packages/@aws-cdk-testing/framework-integ/test/pipelines/test/integ.pipeline-with-variables.js.snapshot/VariablePipelineStack.assets.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/pipelines/test/integ.pipeline-with-variables.js.snapshot/VariablePipelineStack.template.json

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@
150150
"CustomS3AutoDeleteObjectsCustomResourceProviderRole3B1BD092"
151151
]
152152
},
153+
"Fleet30813DF3": {
154+
"Type": "AWS::CodeBuild::Fleet",
155+
"Properties": {
156+
"BaseCapacity": 1,
157+
"ComputeType": "BUILD_GENERAL1_SMALL",
158+
"EnvironmentType": "LINUX_CONTAINER"
159+
}
160+
},
153161
"PipelineArtifactsBucketAEA9A052": {
154162
"Type": "AWS::S3::Bucket",
155163
"Properties": {
@@ -736,7 +744,29 @@
736744
"Description": "Pipeline step VariablePipelineStack/Pipeline/Build/Synth",
737745
"EncryptionKey": "alias/aws/s3",
738746
"Environment": {
747+
"Certificate": {
748+
"Fn::Join": [
749+
"",
750+
[
751+
{
752+
"Fn::GetAtt": [
753+
"SourceBucketDDD2130A",
754+
"Arn"
755+
]
756+
},
757+
"/my-certificate.pem"
758+
]
759+
]
760+
},
739761
"ComputeType": "BUILD_GENERAL1_SMALL",
762+
"Fleet": {
763+
"FleetArn": {
764+
"Fn::GetAtt": [
765+
"Fleet30813DF3",
766+
"Arn"
767+
]
768+
}
769+
},
740770
"Image": "aws/codebuild/standard:7.0",
741771
"ImagePullCredentialsType": "CODEBUILD",
742772
"PrivilegedMode": false,
@@ -970,7 +1000,29 @@
9701000
"Description": "Pipeline step VariablePipelineStack/Pipeline/MyWave/Produce",
9711001
"EncryptionKey": "alias/aws/s3",
9721002
"Environment": {
1003+
"Certificate": {
1004+
"Fn::Join": [
1005+
"",
1006+
[
1007+
{
1008+
"Fn::GetAtt": [
1009+
"SourceBucketDDD2130A",
1010+
"Arn"
1011+
]
1012+
},
1013+
"/my-certificate.pem"
1014+
]
1015+
]
1016+
},
9731017
"ComputeType": "BUILD_GENERAL1_SMALL",
1018+
"Fleet": {
1019+
"FleetArn": {
1020+
"Fn::GetAtt": [
1021+
"Fleet30813DF3",
1022+
"Arn"
1023+
]
1024+
}
1025+
},
9741026
"Image": "aws/codebuild/standard:7.0",
9751027
"ImagePullCredentialsType": "CODEBUILD",
9761028
"PrivilegedMode": false,
@@ -1204,7 +1256,29 @@
12041256
"Description": "Pipeline step VariablePipelineStack/Pipeline/MyWave/Consume",
12051257
"EncryptionKey": "alias/aws/s3",
12061258
"Environment": {
1259+
"Certificate": {
1260+
"Fn::Join": [
1261+
"",
1262+
[
1263+
{
1264+
"Fn::GetAtt": [
1265+
"SourceBucketDDD2130A",
1266+
"Arn"
1267+
]
1268+
},
1269+
"/my-certificate.pem"
1270+
]
1271+
]
1272+
},
12071273
"ComputeType": "BUILD_GENERAL1_SMALL",
1274+
"Fleet": {
1275+
"FleetArn": {
1276+
"Fn::GetAtt": [
1277+
"Fleet30813DF3",
1278+
"Arn"
1279+
]
1280+
}
1281+
},
12081282
"Image": "aws/codebuild/standard:7.0",
12091283
"ImagePullCredentialsType": "CODEBUILD",
12101284
"PrivilegedMode": false,

packages/@aws-cdk-testing/framework-integ/test/pipelines/test/integ.pipeline-with-variables.js.snapshot/manifest.json

Lines changed: 17 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/pipelines/test/integ.pipeline-with-variables.js.snapshot/tree.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/pipelines/test/integ.pipeline-with-variables.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ class PipelineStack extends Stack {
2323
// }),
2424
commands: ['mkdir cdk.out', 'touch cdk.out/dummy'],
2525
}),
26+
codeBuildDefaults: {
27+
buildEnvironment: {
28+
fleet: new codebuild.Fleet(this, 'Fleet', {
29+
baseCapacity: 1,
30+
computeType: codebuild.FleetComputeType.SMALL,
31+
environmentType: codebuild.EnvironmentType.LINUX_CONTAINER,
32+
}),
33+
certificate: {
34+
bucket: sourceBucket,
35+
objectKey: 'my-certificate.pem',
36+
},
37+
},
38+
},
2639
selfMutation: false,
2740
});
2841

packages/aws-cdk-lib/pipelines/lib/codepipeline/private/codebuild-factory.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ export function mergeCodeBuildOptions(...opts: Array<CodeBuildOptions | undefine
440440
cache: b.cache ?? a.cache,
441441
fileSystemLocations: definedArray([...a.fileSystemLocations ?? [], ...b.fileSystemLocations ?? []]),
442442
logging: b.logging ?? a.logging,
443-
};
443+
} satisfies OptionalToUndefined<CodeBuildOptions>;
444444
}
445445
}
446446

@@ -453,13 +453,23 @@ function mergeBuildEnvironments(a?: codebuild.BuildEnvironment, b?: codebuild.Bu
453453
return {
454454
buildImage: b.buildImage ?? a.buildImage,
455455
computeType: b.computeType ?? a.computeType,
456+
dockerServer: b.dockerServer ?? a.dockerServer,
457+
fleet: b.fleet ?? a.fleet,
458+
privileged: b.privileged ?? a.privileged,
459+
certificate: b.certificate ?? a.certificate,
456460
environmentVariables: {
457461
...a.environmentVariables,
458462
...b.environmentVariables,
459463
},
460-
privileged: b.privileged ?? a.privileged,
461-
dockerServer: b.dockerServer ?? a.dockerServer,
462-
};
464+
} satisfies OptionalToUndefined<codebuild.BuildEnvironment>;
465+
}
466+
467+
// Turns `{ foo?: boolean, bar: number }` into `{ foo: boolean | undefined, bar:
468+
// number }`. Lets us assert that we are enumerating all properties on a type.
469+
//
470+
// Ref: https://stackoverflow.com/a/52973675
471+
type OptionalToUndefined<T> = {
472+
[K in keyof Required<T>]: T[K];
463473
}
464474

465475
function isDefined<A>(x: A | undefined): x is NonNullable<A> {

packages/aws-cdk-lib/pipelines/test/compliance/synths.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ test('CodeBuild: environment variables specified in multiple places are correctl
164164
const securityGroup = new ec2.SecurityGroup(pipelineStack, 'SecurityGroup', {
165165
vpc,
166166
});
167+
const bucket = s3.Bucket.fromBucketArn(pipelineStack, 'Bucket', 'arn:aws:s3:::this-particular-bucket');
168+
const fleet = new cbuild.Fleet(pipelineStack, 'Fleet', {
169+
baseCapacity: 1,
170+
computeType: cbuild.FleetComputeType.SMALL,
171+
environmentType: cbuild.EnvironmentType.LINUX_CONTAINER,
172+
});
167173

168174
new ModernTestGitHubNpmPipeline(pipelineStack, 'Cdk-1', {
169175
synth: new CodeBuildStep('Synth', {
@@ -186,6 +192,8 @@ test('CodeBuild: environment variables specified in multiple places are correctl
186192
computeType: cbuild.DockerServerComputeType.SMALL,
187193
securityGroups: [securityGroup],
188194
},
195+
certificate: { bucket, objectKey: 'my-certificate' },
196+
fleet,
189197
},
190198
}),
191199
});
@@ -233,6 +241,10 @@ test('CodeBuild: environment variables specified in multiple places are correctl
233241
'Fn::GetAtt': ['SecurityGroupDD263621', 'GroupId'],
234242
}],
235243
},
244+
Certificate: 'arn:aws:s3:::this-particular-bucket/my-certificate',
245+
Fleet: {
246+
FleetArn: { 'Fn::GetAtt': [Match.stringLikeRegexp('Fleet.*'), 'Arn'] },
247+
},
236248
}),
237249
Source: {
238250
BuildSpec: Match.serializedJson(Match.objectLike({

0 commit comments

Comments
 (0)