Skip to content

Commit

Permalink
fix(core): bundling with staging disabled returns a relative path
Browse files Browse the repository at this point in the history
The change introduced in aws#9576 did not handle the "staging disabled"
case. As a consequence, when bundling the staged path was always
relative.

Revert to the behavior that was present before this change: when staging
is disabled the staged path is absolute (whether bundling or not).

Closes aws#10367
  • Loading branch information
jogold committed Sep 24, 2020
1 parent 451200e commit 4c4e90f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
14 changes: 7 additions & 7 deletions packages/@aws-cdk/core/lib/asset-staging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ export class AssetStaging extends Construct {
}
} else {
this.assetHash = this.calculateHash(hashType, props.assetHash);
this.relativePath = renderAssetFilename(this.assetHash, path.extname(this.sourcePath));
this.stagedPath = this.relativePath;
}

const stagingDisabled = this.node.tryGetContext(cxapi.DISABLE_ASSET_STAGING_CONTEXT);
if (stagingDisabled) {
this.stagedPath = this.sourcePath;
} else {
this.relativePath = renderAssetFilename(this.assetHash, path.extname(this.sourcePath));
this.stagedPath = this.relativePath;
}
const stagingDisabled = this.node.tryGetContext(cxapi.DISABLE_ASSET_STAGING_CONTEXT);
if (stagingDisabled) {
this.relativePath = undefined;
this.stagedPath = this.bundleDir ?? this.sourcePath;
}

this.sourceHash = this.assetHash;
Expand Down
12 changes: 10 additions & 2 deletions packages/@aws-cdk/core/test/test.staging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ export = {
// GIVEN
const app = new App();
const stack = new Stack(app, 'stack');
stack.node.setContext(cxapi.DISABLE_ASSET_STAGING_CONTEXT, true);
stack.node.setContext(cxapi.DISABLE_ASSET_STAGING_CONTEXT, false);
const directory = path.join(__dirname, 'fs', 'fixtures', 'test1');

// WHEN
new AssetStaging(stack, 'Asset', {
const asset = new AssetStaging(stack, 'Asset', {
sourcePath: directory,
bundling: {
image: BundlingDockerImage.fromRegistry('alpine'),
Expand All @@ -167,6 +167,14 @@ export = {
'tree.json',
]);

test.equal(asset.sourceHash, 'b1e32e86b3523f2fa512eb99180ee2975a50a4439e63e8badd153f2a68d61aa4');
test.equal(asset.sourcePath, directory);

const resolvedStagePath = stack.resolve(asset.stagedPath);
// absolute path ending with bundling dir
test.ok(path.isAbsolute(resolvedStagePath));
test.ok(new RegExp('asset.b1e32e86b3523f2fa512eb99180ee2975a50a4439e63e8badd153f2a68d61aa4$').test(resolvedStagePath));

test.done();
},

Expand Down

0 comments on commit 4c4e90f

Please sign in to comment.