Skip to content

Commit cd51a5d

Browse files
authored
fix(codebuild): setting Cache.none() renders nothing in the template (#18194)
When implementing caching in CodeBuild, we made the default cache `Cache.none()`, and, for that reason, do not render anything in the template for that type of cache. However, that does not work well with the CodeBuild API, which interprets the lack of a property as the signal to leave it unchanged. Which means it's not possible currently to disable caching on a Project once it has been enabled once. Fix this by differentiating between the case of "no Cache has been provided", and "the none() Cache has been provided". Closes #18165 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 884d3a8 commit cd51a5d

File tree

33 files changed

+262
-83
lines changed

33 files changed

+262
-83
lines changed

packages/@aws-cdk/aws-codebuild/lib/cache.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ export enum LocalCacheMode {
3737
*/
3838
export abstract class Cache {
3939
public static none(): Cache {
40-
return { _toCloudFormation: () => undefined, _bind: () => { return; } };
40+
return {
41+
_toCloudFormation(): CfnProject.ProjectCacheProperty | undefined {
42+
return { type: 'NO_CACHE' };
43+
},
44+
_bind(): void {
45+
},
46+
};
4147
}
4248

4349
/**

packages/@aws-cdk/aws-codebuild/test/codebuild.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ describe('default properties', () => {
155155
'ComputeType': 'BUILD_GENERAL1_SMALL',
156156
},
157157
'EncryptionKey': 'alias/aws/s3',
158+
'Cache': {
159+
'Type': 'NO_CACHE',
160+
},
158161
},
159162
},
160163
},
@@ -335,6 +338,9 @@ describe('default properties', () => {
335338
'Type': 'CODECOMMIT',
336339
},
337340
'EncryptionKey': 'alias/aws/s3',
341+
'Cache': {
342+
'Type': 'NO_CACHE',
343+
},
338344
},
339345
},
340346
},
@@ -539,6 +545,9 @@ describe('default properties', () => {
539545
'Type': 'S3',
540546
},
541547
'EncryptionKey': 'alias/aws/s3',
548+
'Cache': {
549+
'Type': 'NO_CACHE',
550+
},
542551
},
543552
},
544553
},

packages/@aws-cdk/aws-codebuild/test/integ.aws-deep-learning-container-build-image.expected.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@
210210
"BuildSpec": "{\n \"version\": \"0.2\",\n \"phases\": {\n \"build\": {\n \"commands\": [\n \"ls\"\n ]\n }\n }\n}",
211211
"Type": "NO_SOURCE"
212212
},
213+
"Cache": {
214+
"Type": "NO_CACHE"
215+
},
213216
"EncryptionKey": "alias/aws/s3"
214217
}
215218
}

packages/@aws-cdk/aws-codebuild/test/integ.defaults.lit.expected.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@
147147
"BuildSpec": "{\n \"version\": \"0.2\",\n \"phases\": {\n \"build\": {\n \"commands\": [\n \"echo \\\"Hello, CodeBuild!\\\"\"\n ]\n }\n }\n}",
148148
"Type": "NO_SOURCE"
149149
},
150+
"Cache": {
151+
"Type": "NO_CACHE"
152+
},
150153
"EncryptionKey": "alias/aws/s3"
151154
}
152155
}

packages/@aws-cdk/aws-codebuild/test/integ.docker-asset.lit.expected.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@
164164
"BuildSpec": "{\n \"version\": \"0.2\",\n \"phases\": {\n \"build\": {\n \"commands\": [\n \"ls\"\n ]\n }\n }\n}",
165165
"Type": "NO_SOURCE"
166166
},
167+
"Cache": {
168+
"Type": "NO_CACHE"
169+
},
167170
"EncryptionKey": "alias/aws/s3"
168171
}
169172
}

packages/@aws-cdk/aws-codebuild/test/integ.docker-registry.lit.expected.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@
155155
"BuildSpec": "{\n \"version\": \"0.2\",\n \"phases\": {\n \"build\": {\n \"commands\": [\n \"ls\"\n ]\n }\n }\n}",
156156
"Type": "NO_SOURCE"
157157
},
158+
"Cache": {
159+
"Type": "NO_CACHE"
160+
},
158161
"EncryptionKey": "alias/aws/s3"
159162
}
160163
}

packages/@aws-cdk/aws-codebuild/test/integ.ecr.lit.expected.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@
185185
"BuildSpec": "{\n \"version\": \"0.2\",\n \"phases\": {\n \"build\": {\n \"commands\": [\n \"ls\"\n ]\n }\n }\n}",
186186
"Type": "NO_SOURCE"
187187
},
188+
"Cache": {
189+
"Type": "NO_CACHE"
190+
},
188191
"EncryptionKey": "alias/aws/s3"
189192
}
190193
}

packages/@aws-cdk/aws-codebuild/test/integ.github-webhook-batch.expected.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@
169169
]
170170
}
171171
},
172+
"Cache": {
173+
"Type": "NO_CACHE"
174+
},
172175
"EncryptionKey": "alias/aws/s3",
173176
"Triggers": {
174177
"BuildType": "BUILD_BATCH",

packages/@aws-cdk/aws-codebuild/test/integ.github.expected.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@
114114
"ReportBuildStatus": false,
115115
"Type": "GITHUB"
116116
},
117+
"Cache": {
118+
"Type": "NO_CACHE"
119+
},
117120
"EncryptionKey": "alias/aws/s3"
118121
}
119122
}

packages/@aws-cdk/aws-codebuild/test/integ.project-bucket.expected.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@
158158
},
159159
"Type": "S3"
160160
},
161+
"Cache": {
162+
"Type": "NO_CACHE"
163+
},
161164
"EncryptionKey": "alias/aws/s3"
162165
}
163166
}

0 commit comments

Comments
 (0)