-
Notifications
You must be signed in to change notification settings - Fork 38
feat(toolkit-lib)!: parameterize context storage #534
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
Conversation
Previously, context was always being written to `cdk.context.json` in some directory, even for `fromAssemblyBuilder()` or `fromAssemblyDirectory()` which should probably both not write context anywhere. In this PR, we replace the context parameter to the toolkit with the concept of a `contextStore`, which has two operations: `read()` and `update()`. There are simple file and in-memory implementations for simple cases, as well as the more complex CDK app case which is implemented as `CdkAppMultiContext`. That last one is the default for `fromCdkApp()`. The complex one is implemented in terms of the prior `Context/ContextBag/Settings` classes, which are probably overly complex for the job this class is doing but keeping the old classes is an easy way to make sure that the behavior stays compatible.
TODO: Write tests for the new classes, verify that none of them persist transient errors. |
packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/context-store.ts
Outdated
Show resolved
Hide resolved
packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/context-store.ts
Outdated
Show resolved
Hide resolved
private projectContextFile: string; | ||
private userConfigFile: string; | ||
|
||
constructor(appDirectory: string, private readonly initialContext?: Record<string, unknown>) { |
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.
Only FileContext
does not get initialContext
?
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.
Yes. The name is probably bad here.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #534 +/- ##
==========================================
+ Coverage 79.01% 79.09% +0.08%
==========================================
Files 47 47
Lines 7032 7035 +3
Branches 786 786
==========================================
+ Hits 5556 5564 +8
+ Misses 1458 1453 -5
Partials 18 18
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@@ -125,7 +131,7 @@ export abstract class CloudAssemblySourceBuilder { | |||
const services: ToolkitServices = await this.sourceBuilderServices(); | |||
const contextAssemblyProps: ContextAwareCloudAssemblyProps = { | |||
services, | |||
context: new Context(), // @todo there is probably a difference between contextaware and contextlookup sources | |||
contextStore: new MemoryContext(), // FIXME: We shouldn't be using a `ContextAwareCloudAssemblySource` at all. |
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.
lol. are we fighting over what the best todo/fixme marker is?
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.
Oh, sorry. Not on purpose. Deleted this line without looking, then rewrote it 🤣
packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/private/source-builder.ts
Outdated
Show resolved
Hide resolved
…tore.ts Co-authored-by: Momo Kornher <[email protected]>
…tore.ts Co-authored-by: Momo Kornher <[email protected]>
…ource-builder.ts Co-authored-by: Momo Kornher <[email protected]>
Previously, context was always being written to
cdk.context.json
in some directory, even forfromAssemblyBuilder()
orfromAssemblyDirectory()
which should probably both not write context anywhere.In this PR, we replace the context parameter to the toolkit with the concept of a
contextStore
, which has two operations:read()
andupdate()
.There are simple file and in-memory implementations for simple cases, as well as the more complex CDK app case which is implemented as
CdkAppMultiContext
. That last one is the default forfromCdkApp()
.The complex one is implemented in terms of the prior
Context/ContextBag/Settings
classes, which are probably overly complex for the job this class is doing but keeping the old classes is an easy way to make sure that the behavior stays compatible.BREAKING CHANGES:
context
is now calledcontextStore
. MessageCDK_ASSEMBLY_I0042
no longer knows about the filename where changes get written.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license