Skip to content

Commit cda6601

Browse files
authoredNov 24, 2021
fix(core): bundling skipped with --exclusively option and stacks under stage (#17210)
We were comparing bundling stacks of the form `Stage/Stack` with stack names of the form `Stage-Stack`. For stacks with `NodejsFunction`s this leads to assets containing the whole CDK project because when bundling is skipped the asset references the source directory which is the project root. Closes #12898 Closes #15346 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 29b379c commit cda6601

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed
 

‎packages/@aws-cdk/core/lib/asset-staging.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ export class AssetStaging extends CoreConstruct {
189189
if (props.bundling) {
190190
// Check if we actually have to bundle for this stack
191191
const bundlingStacks: string[] = this.node.tryGetContext(cxapi.BUNDLING_STACKS) ?? ['*'];
192-
skip = !bundlingStacks.find(pattern => minimatch(Stack.of(this).stackName, pattern));
192+
// bundlingStacks is of the form `Stage/Stack`, convert it to `Stage-Stack` before comparing to stack name
193+
skip = !bundlingStacks.find(pattern => minimatch(Stack.of(this).stackName, pattern.replace('/', '-')));
193194
const bundling = props.bundling;
194195
stageThisAsset = () => this.stageByBundling(bundling, skip);
195196
} else {

‎packages/@aws-cdk/core/test/staging.test.ts

+34
Original file line numberDiff line numberDiff line change
@@ -859,8 +859,42 @@ describe('staging', () => {
859859
expect(asset.stagedPath).toEqual(directory);
860860
expect(asset.relativeStagedPath(stack)).toEqual(directory);
861861
expect(asset.assetHash).toEqual('f66d7421aa2d044a6c1f60ddfc76dc78571fcd8bd228eb48eb394e2dbad94a5c');
862+
});
863+
864+
test('correctly skips bundling with stack under stage', () => {
865+
// GIVEN
866+
const app = new App();
867+
868+
const stage = new Stage(app, 'Stage');
869+
stage.node.setContext(cxapi.BUNDLING_STACKS, ['Stage/Stack1']);
870+
871+
const stack1 = new Stack(stage, 'Stack1');
872+
const stack2 = new Stack(stage, 'Stack2');
873+
const directory = path.join(__dirname, 'fs', 'fixtures', 'test1');
862874

875+
new AssetStaging(stack1, 'Asset', {
876+
sourcePath: directory,
877+
assetHashType: AssetHashType.OUTPUT,
878+
bundling: {
879+
image: DockerImage.fromRegistry('alpine'),
880+
command: [DockerStubCommand.SUCCESS],
881+
},
882+
});
883+
884+
new AssetStaging(stack2, 'Asset', {
885+
sourcePath: directory,
886+
assetHashType: AssetHashType.OUTPUT,
887+
bundling: {
888+
image: DockerImage.fromRegistry('alpine'),
889+
command: [DockerStubCommand.MULTIPLE_FILES],
890+
},
891+
});
863892

893+
const dockerStubInput = readDockerStubInputConcat();
894+
// Docker ran for the asset in Stack1
895+
expect(dockerStubInput).toMatch(DockerStubCommand.SUCCESS);
896+
// DOcker did not run for the asset in Stack2
897+
expect(dockerStubInput).not.toMatch(DockerStubCommand.MULTIPLE_FILES);
864898
});
865899

866900
test('bundling still occurs with partial wildcard', () => {

0 commit comments

Comments
 (0)
Please sign in to comment.