-
Notifications
You must be signed in to change notification settings - Fork 685
Persistent container support #5354
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
src/Aspire.Hosting/ApplicationModel/ContainerLifetimeAnnotation.cs
Outdated
Show resolved
Hide resolved
var nameSuffix = GetRandomNameSuffix(); | ||
var nameSuffix = string.Empty; | ||
|
||
if (container.GetContainerLifetimeType() == ContainerLifetimeType.Default) |
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.
@ReubenBond we need to make sure this doesn't regress testing scenarios right?
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.
I've been hesitant to add tests to this PR for persistent resources as I don't want to introduce any test instability by leaving resources behind after a test run.
@mitchdenny how do you feel about merging this so we can start kicking the tires? |
Let's get it in. Would be good to socialise this with some of the other changes for 9.0 |
Description
Adds a new annotation and API to support marking container resources with a persistent lifetime. This will allow Aspire to use container resources with a longer lifetime than the AppHost (in addition to the current behavior that creates and tears down all container resources with the AppHost). Opening this as a draft PR as there is additional work to finalize the API and add tests required.
This PR adds a new
ContainerLifetimeAnnotation
annotation andWithContainerLifetime
resource builder API to allow configuring the expected lifetime of container resources. With this initial implementation, a container would be able to have one of two lifetime settings,Default
orPersistent
.Container Lifetime Modes
Default Lifetime
This lifetime mode is the same as the existing behavior for container resources. Default lifetime resources will be created when the AppHost starts based on the resource builder configuration and shut down when the AppHost terminates.
Persistent Lifetime
This is a new optional lifetime mode for container resources. A persistent container resource is identified by the assigned container/resource name. When the AppHost is started, if no running containers are found that match the specified service name, a new container resource will be created, just like for AppHost lifetime resources. However, if a container is found with the specified service name, Aspire will use that resource instead of creating a new one. When the AppHost shuts down, this container resource will not be terminated. This will allow a container to be re-used across multiple runs of the AppHost.
Example
Caveats
With this initial design, a persistent container resource will never be recreated if a matching container is found, even if the resource builder definition has been modified in such a way that the existing container is no longer compatible with the new configuration. Users will need to manually terminate their existing container via the Docker/Podman CLI or management GUI to trigger a recreation of the resource matching the new configuration.
Granularity of container lifetime is limited to matching that of the AppHost or running as a globally persistent resource; we don't yet have a mechanism to spin up or tear down longer running sets of container services as part of a development session, this means that users that want longer running resources, but not constantly running resources will have to implement their own scripts or manually cleanup individual resources when they're not longer needed.
Both of these scenarios are cases that we'd like to improve on in future PRs, but we still feel this initial design should help reduce pain points related to container startup that we've heard from users of Aspire.
Finally, this initial API is marked as
Experimental
as we may need to revisit the design as we look to improve some of the identified limitations of the experience in future PRs.Fixes # (issue)
Checklist
<remarks />
and<code />
elements on your triple slash comments?Microsoft Reviewers: Open in CodeFlow