fix(s3-assets): cannot publish a file without extension#30597
fix(s3-assets): cannot publish a file without extension#30597mergify[bot] merged 8 commits intoaws:mainfrom
Conversation
|
@Mergifyio update |
❌ Mergify doesn't have permission to updateDetailsFor security reasons, Mergify can't update this pull request. Try updating locally. |
rix0rrr
left a comment
There was a problem hiding this comment.
Thanks for the deep dive!
I wonder if we can simplify this a bit, but apart from that looks good!
| private renderStagedPath(sourcePath: string, targetPath: string): string { | ||
| // Add a suffix to the asset file name | ||
| // because when a file without extension is specified, the source directory name is the same as the staged asset file name. | ||
| if (this.hashType === AssetHashType.SOURCE && path.dirname(sourcePath) === targetPath) { |
There was a problem hiding this comment.
Does this even on the hashType? It seems that if dirname(sourcePath) === targetPath we always have a problem?
There was a problem hiding this comment.
Changed the conditional to this.hashType !== AssetHashType.OUTPUT and added the reason to the comment.
9f5adb5
| // Add a suffix to the asset file name | ||
| // because when a file without extension is specified, the source directory name is the same as the staged asset file name. | ||
| if (this.hashType === AssetHashType.SOURCE && path.dirname(sourcePath) === targetPath) { | ||
| targetPath = targetPath + 'noext'; |
There was a problem hiding this comment.
| targetPath = targetPath + 'noext'; | |
| targetPath = targetPath + '_noext'; |
| // If the fileName begins with 'asset.', remove it here | ||
| // because when a file without extension is added to the manifest, the path.extension() will return an file hash. | ||
| // ex) path.extension('asset.dc5ce447844') => 'dc5ce447844' |
There was a problem hiding this comment.
This comment seems to not match what the code is doing? Or does it?
There was a problem hiding this comment.
Deleted comment.
I forgot to delete it.
69889ec
|
@rix0rrr |
|
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
|
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
|
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
|
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
|
Comments on closed issues and PRs are hard for our team to see. |
Issue # (if applicable)
Closes #30471
Reason for this change
Publishing a file with no extension using the
Assetclass withBundlingOutput.SINGLE_FILEandAssetHashType.SOURCE(default), as shown below, will result in an errorfail: EISDIR: illegal operation on a directory, read, and publishing will fail.This is because the path in
*.asset.jsonis different from the actual file path.The
*.asset.jsonexpects the file to be inasset.bead5b2c0d128650228f146d2326d5f3cbfb36738a9383fc6a09b1e9278803f0, but when I check thecdk.outdirectory, I see thatasset.bead5b2c0d128650228f146d2326d5f3cbfb36738a9383fc6a09b1e9278803f0is a directory, not a file.{ "version": "36.0.0", "files": { "bead5b2c0d128650228f146d2326d5f3cbfb36738a9383fc6a09b1e9278803f0": { "source": { "path": "asset.bead5b2c0d128650228f146d2326d5f3cbfb36738a9383fc6a09b1e9278803f0", "packaging": "file" }, "destinations": { "current_account-us-east-1": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1", "objectKey": "bead5b2c0d128650228f146d2326d5f3cbfb36738a9383fc6a09b1e9278803f0.bead5b2c0d128650228f146d2326d5f3cbfb36738a9383fc6a09b1e9278803f0", "region": "us-east-1", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-us-east-1" } } } }If I change it to a file with an extension, as shown below, I see that the file with the extension is staged under
cdk.outdir, and the asset is published successfully.cdk.out ├── SampleStack.assets.json ├── SampleStack.template.json ├── asset.dc5ce447844d7490834e46df016edc7f671b4fae19ab55b6c78973dcb5af98f8 │ └── main.bin ├── asset.dc5ce447844d7490834e46df016edc7f671b4fae19ab55b6c78973dcb5af98f8.bin # !! staged file here !! ├── cdk.out ├── manifest.json └── tree.json{ "version": "36.0.0", "files": { "dc5ce447844d7490834e46df016edc7f671b4fae19ab55b6c78973dcb5af98f8": { "source": { "path": "asset.dc5ce447844d7490834e46df016edc7f671b4fae19ab55b6c78973dcb5af98f8.bin", "packaging": "file" }, "destinations": { "current_account-us-east-1": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1", "objectKey": "dc5ce447844d7490834e46df016edc7f671b4fae19ab55b6c78973dcb5af98f8.bin", "region": "us-east-1", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-us-east-1" } } } }Files without extensions must be staged correctly in order to be published correctly.
Description of changes
The directory to write the bundling output is usually
cdk.out/asset.{asset hash}.If the extension exists, it will be renamed from
cdk.out/asset.{asset hash}/{asset file name}tocdk.out/{asset hash}.{asset file extension}.aws-cdk/packages/aws-cdk-lib/core/lib/asset-staging.ts
Line 392 in c826d8f
If the extension does not exist, the file name
cdk.out/asset.{asset hash}(without extension) will be the same as the directory where bundling output is written.Therefore, the file is already considered staged and will not be staged correctly.
aws-cdk/packages/aws-cdk-lib/core/lib/asset-staging.ts
Line 383 in c826d8f
Therefore, in such cases, I fix to change the file name by adding a suffix such as
noextafter the file name so that the file is correctly renamed.Description of how you validated changes
unit tests and integ test.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license