diff --git a/packages/aws-cdk-lib/core/lib/nested-stack.ts b/packages/aws-cdk-lib/core/lib/nested-stack.ts index a542b8d3bfaa4..3f69ea31e9906 100644 --- a/packages/aws-cdk-lib/core/lib/nested-stack.ts +++ b/packages/aws-cdk-lib/core/lib/nested-stack.ts @@ -260,6 +260,11 @@ export class NestedStack extends Stack { resource.cfnOptions.metadata[cxapi.ASSET_RESOURCE_METADATA_PATH_KEY] = this.templateFile; resource.cfnOptions.metadata[cxapi.ASSET_RESOURCE_METADATA_PROPERTY_KEY] = resourceProperty; } + + public get bundlingRequired() { + + return this._parentStack.bundlingRequired; + } } /** diff --git a/packages/aws-cdk-lib/core/test/staging.test.ts b/packages/aws-cdk-lib/core/test/staging.test.ts index dff63c09a76f8..96df87cac51c1 100644 --- a/packages/aws-cdk-lib/core/test/staging.test.ts +++ b/packages/aws-cdk-lib/core/test/staging.test.ts @@ -5,7 +5,7 @@ import * as fs from 'fs-extra'; import * as sinon from 'sinon'; import { FileAssetPackaging } from '../../cloud-assembly-schema'; import * as cxapi from '../../cx-api'; -import { App, AssetHashType, AssetStaging, DockerImage, BundlingOptions, BundlingOutput, FileSystem, Stack, Stage, BundlingFileAccess } from '../lib'; +import { App, AssetHashType, AssetStaging, DockerImage, BundlingOptions, BundlingOutput, FileSystem, Stack, NestedStack, Stage, BundlingFileAccess } from '../lib'; const STUB_INPUT_FILE = '/tmp/docker-stub.input'; const STUB_INPUT_CONCAT_FILE = '/tmp/docker-stub.input.concat'; @@ -1106,6 +1106,48 @@ describe('staging', () => { expect(dockerStubInput).not.toMatch(DockerStubCommand.MULTIPLE_FILES); }); + test('correctly skips bundling with stack under stage and nested stack', () => { + // GIVEN + const app = new App(); + + const stage = new Stage(app, 'Stage'); + stage.node.setContext(cxapi.BUNDLING_STACKS, ['Stage/Stack1']); + + const stack1 = new Stack(stage, 'Stack1', { stackName: 'unrelated-stack1-name' }); + const stack1_nested = new NestedStack(stack1, "Stack1Nest"); + + const stack2 = new Stack(stage, 'Stack2', { stackName: 'unrelated-stack2-name' }); + const stack2_nested = new NestedStack(stack2, "Stack2Nest"); + + const directory = path.join(__dirname, 'fs', 'fixtures', 'test1'); + + // WHEN + new AssetStaging(stack1_nested, 'Asset', { + sourcePath: directory, + assetHashType: AssetHashType.OUTPUT, + bundling: { + image: DockerImage.fromRegistry('alpine'), + command: [DockerStubCommand.SUCCESS], + }, + }); + + new AssetStaging(stack2_nested, '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('correctly bundles with stack under stage and the default stack pattern', () => { // GIVEN const app = new App();