Skip to content

Commit

Permalink
fix(servicecatalog): wrong asset path is generated in case outdir is …
Browse files Browse the repository at this point in the history
…absolute (#24393)

In case we get an absolute path like `/tmp/foobar` then `./` is always prepended which makes the assetPath relative to the current directory.

Fixes #24392

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
bruecktech authored Mar 1, 2023
1 parent 3bd611d commit 0ebbf58
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class ProductStackSynthesizer extends cdk.StackSynthesizer {
throw new Error('An Asset Bucket must be provided to use Assets');
}
const outdir = cdk.App.of(this.boundStack)?.outdir ?? 'cdk.out';
const assetPath = `./${outdir}/${asset.fileName}`;
const assetPath = `${outdir}/${asset.fileName}`;
if (!this.bucketDeployment) {
const parentStack = (this.boundStack as ProductStack)._getParentStack();
if (!cdk.Resource.isOwnedResource(this.assetBucket)) {
Expand Down
26 changes: 26 additions & 0 deletions packages/@aws-cdk/aws-servicecatalog/test/product-stack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,32 @@ describe('ProductStack', () => {
});
});

test('Use correct assetPath when outdir is absolute', () => {
// GIVEN
const app = new cdk.App(
{ outdir: '/tmp/foobar' },
);
const mainStack = new cdk.Stack(app, 'MyStackAbsolutePath');
const testAssetBucket = new s3.Bucket(mainStack, 'TestAssetBucket', {
bucketName: 'test-asset-bucket',
});
const productStack = new servicecatalog.ProductStack(mainStack, 'MyProductStackAbsolutePath', {
assetBucket: testAssetBucket,
});

new lambda.Function(productStack, 'HelloHandler', {
runtime: lambda.Runtime.PYTHON_3_9,
code: lambda.Code.fromAsset(path.join(__dirname, 'assets')),
handler: 'index.handler',
});

// WHEN
const assembly = app.synth();

// THEN
expect(assembly.directory).toBe('/tmp/foobar');
});

test('Used defined Asset bucket in product stack with nested assets', () => {
// GIVEN
const app = new cdk.App(
Expand Down

0 comments on commit 0ebbf58

Please sign in to comment.