Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): correctly skip asset bundling #21962

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions packages/@aws-cdk/core/lib/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1172,12 +1172,7 @@ export class Stack extends Construct implements ITaggable {
*/
public get bundlingRequired() {
const bundlingStacks: string[] = this.node.tryGetContext(cxapi.BUNDLING_STACKS) ?? ['*'];

// bundlingStacks is of the form `Stage/Stack`, convert it to `Stage-Stack` before comparing to stack name
return bundlingStacks.some(pattern => minimatch(
this.stackName,
pattern.replace('/', '-'),
));
return bundlingStacks.some(pattern => minimatch(this.node.path, pattern));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to add a link here to something that documents cxapi.BUNDLING_STACKS.

}
}

Expand Down
48 changes: 48 additions & 0 deletions packages/@aws-cdk/core/test/staging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,54 @@ describe('staging', () => {
expect(dockerStubInput).not.toMatch(DockerStubCommand.MULTIPLE_FILES);
});

test('correctly bundles selected stacks with custom names', () => {
// GIVEN
const app = new App();

const stack = new Stack(app, 'Stack', {
stackName: 'MyStackName',
});
stack.node.setContext(cxapi.BUNDLING_STACKS, ['Stack']);
const directory = path.join(__dirname, 'fs', 'fixtures', 'test1');

new AssetStaging(stack, 'Asset', {
sourcePath: directory,
assetHashType: AssetHashType.OUTPUT,
bundling: {
image: DockerImage.fromRegistry('alpine'),
command: [DockerStubCommand.SUCCESS],
},
});

const dockerStubInput = readDockerStubInputConcat();
// Docker ran for the asset in the Stack
expect(dockerStubInput).toMatch(DockerStubCommand.SUCCESS);
});

test('correctly bundles selected stacks nested in Stack/Stage/Stack', () => {
// GIVEN
const app = new App();

const topStack = new Stack(app, 'TopStack');
topStack.node.setContext(cxapi.BUNDLING_STACKS, ['TopStack/MiddleStage/BottomStack']);
const middleStage = new Stage(topStack, 'MiddleStage');
const bottomStack = new Stack(middleStage, 'BottomStack');
const directory = path.join(__dirname, 'fs', 'fixtures', 'test1');

new AssetStaging(bottomStack, 'Asset', {
sourcePath: directory,
assetHashType: AssetHashType.OUTPUT,
bundling: {
image: DockerImage.fromRegistry('alpine'),
command: [DockerStubCommand.SUCCESS],
},
});

const dockerStubInput = readDockerStubInputConcat();
// Docker ran for the asset in the Stack
expect(dockerStubInput).toMatch(DockerStubCommand.SUCCESS);
});

test('bundling still occurs with partial wildcard', () => {
// GIVEN
const app = new App();
Expand Down