-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(core): allow the bundler to re-use pre-existing bundler output #8916
Conversation
Title does not follow the guidelines of Conventional Commits. Please adjust title before merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
Co-authored-by: Jonathan Goldwasser <jogold@users.noreply.github.com>
@jogold After your review, I was thinking about the failure modes and looking closely at the |
One more thing that comes to mind: what if the Shouldn't we hash those options together with the custom or source hash and use this final hash in the cc @eladb |
Makes sense |
@@ -179,6 +200,7 @@ export class AssetStaging extends Construct { | |||
workingDirectory: options.workingDirectory ?? AssetStaging.BUNDLING_INPUT_DIR, | |||
}); | |||
} catch (err) { | |||
fs.removeSync(bundleDir); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unrelated to this PR, right?
I am also not sure we actually want to delete the bundleDir for diagnosability (I would even include it in the error message).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is, see #8916 (comment)
Otherwise, subsequent runs may falsely believe that the
bundleDir
can be re-used.
Rename it in case of failure instead (e.g. append -error
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename it in case of failure instead (e.g. append
-error
)?
This seems good to me. But, if we go this route, we might consider when to remove -error
directories if they already exist, such as if docker fails twice for the same bundleDir.
Alternatively, is there a unique number or code I can access for each CDK run? If there were, I could append that number and the error output can be held indefinitely for diagnosability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now I've implemented the -error
suffix. I'm happy to circle back around.
Co-authored-by: Elad Ben-Israel <benisrae@amazon.com>
@jogold Any idea why the test |
It passed because hash calculation always occurred after bundling, it can be safely removed from the expectations. Looks like it was wrongly introduced here #8481. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To fix the build error you can run the integ tests in s3-assets
and aws-lambda
(the failing tests will be integ.assets.bundling.lit.js
and integ.bundling.js
respectively) or merge from master (see #8969).
@eladb LGTM
We should maybe add a note about this new "behavior" here?
aws-cdk/packages/@aws-cdk/core/lib/assets.ts
Lines 35 to 44 in 0a3ae47
/** | |
* Specifies the type of hash to calculate for this asset. | |
* | |
* If `assetHash` is configured, this option must be `undefined` or | |
* `AssetHashType.CUSTOM`. | |
* | |
* @default - the default is `AssetHashType.SOURCE`, but if `assetHash` is | |
* explicitly specified this value defaults to `AssetHashType.CUSTOM`. | |
*/ | |
readonly assetHashType?: AssetHashType; |
@jogold I merged from master but the integration tests still failed. I looked at #8969 and added the new pragma to the top of each offending test file to enable the feature. I butchered my commit message, but in any case, those tests seem to work now. I hope that was the right move. |
Thank you for contributing! Your pull request will be updated from master 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 master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Hey @misterjoshua @jogold, we are reverting this PR through #9037 - please revisit. |
… output (#8916)" (#9037) This logic to reuse bundler output is faulty. Once an asset is bundled, the bundle directory is moved into the cloud assembly (cdk.out) and therefore the logic that attempts to reuse the bundle directory only materializes in the case where moveSync decides to copy the directory and not just move it. This reverts commit 31d6e65.
@misterjoshua see #9037 (comment) I suggest waiting for #8962 before revisiting this. Actually I think it will be easier to implement if the assembly dir is know at construction time. |
@misterjoshua do you want to give this another try? We can now do everything in Let me know. |
Hey @jogold. Thanks for letting me know. I'll open a new PR and mention you in it after I've made some progress. |
…ws#8916) This PR changes `AssetStaging` so that the bundler will re-use pre-existing output. Before, the bundler would re-run Docker without considering pre-existing assets, which was slow. Now, when handling a `SOURCE` hash type, the bundler detects and returns pre-existing asset output without re-running Docker. For all other hash types, the bundler outputs to a temp directory before calculating asset hashes. Closes aws#8882 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
… output (aws#8916)" (aws#9037) This logic to reuse bundler output is faulty. Once an asset is bundled, the bundle directory is moved into the cloud assembly (cdk.out) and therefore the logic that attempts to reuse the bundle directory only materializes in the case where moveSync decides to copy the directory and not just move it. This reverts commit 31d6e65.
…(revisited) (#9576) This PR changes `AssetStaging` so that the bundler will re-use pre-existing output. Before, the bundler would re-run Docker without considering pre-existing assets, which was slow. Now, when handling a `SOURCE` hash type, the bundler detects and returns pre-existing asset output without re-running Docker. For all other hash types, the bundler outputs to an intermediate directory before calculating asset hashes, then renames the intermediate directory into its final location. This PR revisits #8916 which originally closed #8882. Here are some details from the previous PR which have been addressed in this PR: - The bundler now outputs directly into the assembly directory - The bundler's assets can be reused between multiple syntheses - The bundler keeps output from failed bundling attempts for diagnosability purposes (renamed with an `-error` suffix) - Bundler options are hashed together with custom and source hashes - Removed the check for a docker run from `throws with assetHash and not CUSTOM hash type` as docker is no longer run before the AssetStaging props are validated. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
This PR changes
AssetStaging
so that the bundler will re-use pre-existing output. Before, the bundler would re-run Docker without considering pre-existing assets, which was slow. Now, when handling aSOURCE
hash type, the bundler detects and returns pre-existing asset output without re-running Docker. For all other hash types, the bundler outputs to a temp directory before calculating asset hashes.Closes #8882
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license