Skip to content

Commit 71cfd60

Browse files
authored
fix(pipelines): propagate CodeBuild fleet and certificate (#35673)
### Issue # (if applicable) Closes #35664. ### Reason for this change You can't use Fleets or certificates currently in CDK pipelines. ### Description of changes These properties were simply overlooked. I added a TypeScript `satisfies` assertion to ensure that newly added properties are not missed here. ### Describe any new or updated permissions being added N/A ### Description of how you validated changes Unit and integration tests. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent fec94a6 commit 71cfd60

File tree

8 files changed

+154
-48
lines changed

8 files changed

+154
-48
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
@@ -142,6 +142,14 @@
142142
"CustomS3AutoDeleteObjectsCustomResourceProviderRole3B1BD092"
143143
]
144144
},
145+
"Fleet30813DF3": {
146+
"Type": "AWS::CodeBuild::Fleet",
147+
"Properties": {
148+
"BaseCapacity": 1,
149+
"ComputeType": "BUILD_GENERAL1_SMALL",
150+
"EnvironmentType": "LINUX_CONTAINER"
151+
}
152+
},
145153
"PipelineArtifactsBucketAEA9A052": {
146154
"Type": "AWS::S3::Bucket",
147155
"Properties": {
@@ -728,7 +736,29 @@
728736
"Description": "Pipeline step VariablePipelineStack/Pipeline/Build/Synth",
729737
"EncryptionKey": "alias/aws/s3",
730738
"Environment": {
739+
"Certificate": {
740+
"Fn::Join": [
741+
"",
742+
[
743+
{
744+
"Fn::GetAtt": [
745+
"SourceBucketDDD2130A",
746+
"Arn"
747+
]
748+
},
749+
"/my-certificate.pem"
750+
]
751+
]
752+
},
731753
"ComputeType": "BUILD_GENERAL1_SMALL",
754+
"Fleet": {
755+
"FleetArn": {
756+
"Fn::GetAtt": [
757+
"Fleet30813DF3",
758+
"Arn"
759+
]
760+
}
761+
},
732762
"Image": "aws/codebuild/standard:7.0",
733763
"ImagePullCredentialsType": "CODEBUILD",
734764
"PrivilegedMode": false,
@@ -962,7 +992,29 @@
962992
"Description": "Pipeline step VariablePipelineStack/Pipeline/MyWave/Produce",
963993
"EncryptionKey": "alias/aws/s3",
964994
"Environment": {
995+
"Certificate": {
996+
"Fn::Join": [
997+
"",
998+
[
999+
{
1000+
"Fn::GetAtt": [
1001+
"SourceBucketDDD2130A",
1002+
"Arn"
1003+
]
1004+
},
1005+
"/my-certificate.pem"
1006+
]
1007+
]
1008+
},
9651009
"ComputeType": "BUILD_GENERAL1_SMALL",
1010+
"Fleet": {
1011+
"FleetArn": {
1012+
"Fn::GetAtt": [
1013+
"Fleet30813DF3",
1014+
"Arn"
1015+
]
1016+
}
1017+
},
9661018
"Image": "aws/codebuild/standard:7.0",
9671019
"ImagePullCredentialsType": "CODEBUILD",
9681020
"PrivilegedMode": false,
@@ -1196,7 +1248,29 @@
11961248
"Description": "Pipeline step VariablePipelineStack/Pipeline/MyWave/Consume",
11971249
"EncryptionKey": "alias/aws/s3",
11981250
"Environment": {
1251+
"Certificate": {
1252+
"Fn::Join": [
1253+
"",
1254+
[
1255+
{
1256+
"Fn::GetAtt": [
1257+
"SourceBucketDDD2130A",
1258+
"Arn"
1259+
]
1260+
},
1261+
"/my-certificate.pem"
1262+
]
1263+
]
1264+
},
11991265
"ComputeType": "BUILD_GENERAL1_SMALL",
1266+
"Fleet": {
1267+
"FleetArn": {
1268+
"Fn::GetAtt": [
1269+
"Fleet30813DF3",
1270+
"Arn"
1271+
]
1272+
}
1273+
},
12001274
"Image": "aws/codebuild/standard:7.0",
12011275
"ImagePullCredentialsType": "CODEBUILD",
12021276
"PrivilegedMode": false,

packages/@aws-cdk-testing/framework-integ/test/pipelines/test/integ.pipeline-with-variables.js.snapshot/integ.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.js.snapshot/manifest.json

Lines changed: 36 additions & 39 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/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
@@ -439,7 +439,7 @@ export function mergeCodeBuildOptions(...opts: Array<CodeBuildOptions | undefine
439439
cache: b.cache ?? a.cache,
440440
fileSystemLocations: definedArray([...a.fileSystemLocations ?? [], ...b.fileSystemLocations ?? []]),
441441
logging: b.logging ?? a.logging,
442-
};
442+
} satisfies OptionalToUndefined<CodeBuildOptions>;
443443
}
444444
}
445445

@@ -452,15 +452,25 @@ function mergeBuildEnvironments(a?: codebuild.BuildEnvironment, b?: codebuild.Bu
452452
return {
453453
buildImage: b.buildImage ?? a.buildImage,
454454
computeType: b.computeType ?? a.computeType,
455+
dockerServer: b.dockerServer ?? a.dockerServer,
456+
fleet: b.fleet ?? a.fleet,
457+
privileged: b.privileged ?? a.privileged,
458+
certificate: b.certificate ?? a.certificate,
455459
environmentVariables: {
456460
...a.environmentVariables,
457461
...b.environmentVariables,
458462
},
459-
privileged: b.privileged ?? a.privileged,
460-
dockerServer: b.dockerServer ?? a.dockerServer,
461-
};
463+
} satisfies OptionalToUndefined<codebuild.BuildEnvironment>;
462464
}
463465

466+
// Turns `{ foo?: boolean, bar: number }` into `{ foo: boolean | undefined, bar:
467+
// number }`. Lets us assert that we are enumerating all properties on a type.
468+
//
469+
// Ref: https://stackoverflow.com/a/52973675
470+
type OptionalToUndefined<T> = {
471+
[K in keyof Required<T>]: T[K];
472+
};
473+
464474
function isDefined<A>(x: A | undefined): x is NonNullable<A> {
465475
return x !== undefined;
466476
}

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)