Skip to content

Commit

Permalink
default to ** when a value isn't provided
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehodgkiss committed Aug 22, 2022
1 parent 5556b60 commit 9f5c66d
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 14 deletions.
6 changes: 1 addition & 5 deletions packages/@aws-cdk/core/lib/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1166,11 +1166,7 @@ export class Stack extends Construct implements ITaggable {
* Indicates whether the stack requires bundling or not
*/
public get bundlingRequired() {
const bundlingStacks: string[] = this.node.tryGetContext(cxapi.BUNDLING_STACKS) ?? ['*'];

if (bundlingStacks.length === 1 && bundlingStacks[0] === '*') {
return true; // bundle all stacks if a stack pattern isn't supplied on the CLI
}
const bundlingStacks: string[] = this.node.tryGetContext(cxapi.BUNDLING_STACKS) ?? ['**'];

return bundlingStacks.some(pattern => minimatch(
this.node.path, // use the same value for pattern matching as the aws-cdk CLI (displayName / hierarchicalId)
Expand Down
40 changes: 39 additions & 1 deletion packages/@aws-cdk/core/test/staging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,44 @@ describe('staging', () => {
expect(dockerStubInput).toMatch(DockerStubCommand.MULTIPLE_FILES);
});

test('correctly bundles with stack under stage and partial globstar wildcard', () => {
// GIVEN
const app = new App();

const stage = new Stage(app, 'Stage');
stage.node.setContext(cxapi.BUNDLING_STACKS, ['**/Stack1']); // a single wildcard prefix ('*Stack1') won't match

const stack1 = new Stack(stage, 'Stack1');
const stack2 = new Stack(stage, 'Stack2');
const directory = path.join(__dirname, 'fs', 'fixtures', 'test1');

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

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

// THEN
const dockerStubInput = readDockerStubInputConcat();
// Docker ran for the asset in Stack1
expect(dockerStubInput).toMatch(DockerStubCommand.SUCCESS);
// Docker did not run for the asset in Stack2
expect(dockerStubInput).not.toMatch(DockerStubCommand.MULTIPLE_FILES);
});

test('bundling still occurs with partial wildcard', () => {
// GIVEN
const app = new App();
Expand All @@ -1011,7 +1049,7 @@ describe('staging', () => {
expect(asset.assetHash).toEqual('33cbf2cae5432438e0f046bc45ba8c3cef7b6afcf47b59d1c183775c1918fb1f'); // hash of MyStack/Asset
});

test('bundling still occurs with full wildcard', () => {
test('bundling still occurs with a single wildcard', () => {
// GIVEN
const app = new App();
const stack = new Stack(app, 'MyStack');
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-cdk/lib/api/cxapp/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function execProgram(aws: SdkProvider, config: Configuration): Prom
context[cxapi.DISABLE_ASSET_STAGING_CONTEXT] = true;
}

const bundlingStacks = config.settings.get(['bundlingStacks']) ?? ['*'];
const bundlingStacks = config.settings.get(['bundlingStacks']) ?? ['**'];
context[cxapi.BUNDLING_STACKS] = bundlingStacks;

debug('context:', context);
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-cdk/lib/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ export class Settings {
// If we deploy, diff, synth or watch a list of stacks exclusively we skip
// bundling for all other stacks.
bundlingStacks = argv.exclusively
? argv.STACKS ?? ['*']
: ['*'];
? argv.STACKS ?? ['**']
: ['**'];
} else { // Skip bundling for all stacks
bundlingStacks = [];
}
Expand Down
10 changes: 5 additions & 5 deletions packages/aws-cdk/test/settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,24 @@ test('bundling stacks defaults to an empty list', () => {
expect(settings.get(['bundlingStacks'])).toEqual([]);
});

test('bundling stacks defaults to * for deploy', () => {
test('bundling stacks defaults to ** for deploy', () => {
// GIVEN
const settings = Settings.fromCommandLineArguments({
_: [Command.DEPLOY],
});

// THEN
expect(settings.get(['bundlingStacks'])).toEqual(['*']);
expect(settings.get(['bundlingStacks'])).toEqual(['**']);
});

test('bundling stacks defaults to * for watch', () => {
test('bundling stacks defaults to ** for watch', () => {
// GIVEN
const settings = Settings.fromCommandLineArguments({
_: [Command.WATCH],
});

// THEN
expect(settings.get(['bundlingStacks'])).toEqual(['*']);
expect(settings.get(['bundlingStacks'])).toEqual(['**']);
});

test('bundling stacks with deploy exclusively', () => {
Expand Down Expand Up @@ -154,4 +154,4 @@ test('providing a build arg', () => {

// THEN
expect(settings.get(['build'])).toEqual('mvn package');
});
});

0 comments on commit 9f5c66d

Please sign in to comment.