Skip to content
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

Add a hosting helper method for adding a persistent volume mount to containers #1132

Closed
Tracked by #1899
DamianEdwards opened this issue Nov 30, 2023 · 9 comments
Closed
Tracked by #1899
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication good first issue Good for newcomers

Comments

@DamianEdwards
Copy link
Member

Related #974

As part of putting together the sample in dotnet/aspire-samples#52 it was suggested a new helper method could be added to Aspire.Hosting to make this scenario simpler, e.g.:

var database = builder.AddSqlServerContainer("sqlserver", "abcdefg123_78")
    .WithPersistentVolume("/var/opt/mssql")
    .AddDatabase("appdb");

The method WithPersistentVolume would be a shortcut to WithVolumeMount(string source, string target, VolumeMountType type, bool isReadOnly) with source being generated from the application name and resource name, e.g. $"{builder.Environment.ApplicationName}.{resourceName}.data", and type being VolumeMountType.Named and isReadOnly being false.

@DamianEdwards DamianEdwards added area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication enhancement labels Nov 30, 2023
@mitchdenny
Copy link
Member

Where would the volume mount be rooted? I like the idea generally, just need to figure out a few details.

@DamianEdwards
Copy link
Member Author

DamianEdwards commented Nov 30, 2023

When the volume mount is named, you don't specify where it's rooted AFAICT, it just becomes a named volume that's managed by the Docker host. See https://docs.docker.com/storage/volumes/

@DamianEdwards
Copy link
Member Author

It makes me wonder whether the current shape of WithVolumeMount is actually confusing and conflating "Bind mounts" with "Volumes". Perhaps we should be revisiting that.

@davidfowl davidfowl added the good first issue Good for newcomers label Dec 1, 2023
@davidfowl davidfowl added this to the preview TBD (but in 8.0) milestone Dec 1, 2023
@josephaw1022
Copy link

Similar to #837 (comment)

@mitchdenny
Copy link
Member

I think that there is an argument that volumes should be their own resource. In k8s volumes are a discrete resource often with a specific provider to get away from host specific volume mounts (e.g. ceph). In the cloud (using Azure as an example) you might use Azure Files or Azure Container Storage.

@DamianEdwards
Copy link
Member Author

@mitchdenny as long as it doesn't complicate the really simple scenarios like the one this issue relates to.

@stbau04
Copy link
Contributor

stbau04 commented Dec 16, 2023

I created a seperate issure for splitting the current WithVolumeMount into two methods (one for bind mounts and one for named volumes): #1437

@DamianEdwards
Copy link
Member Author

Now that #1437 is complete and we have separate WithBindMount and WithVolumeMount methods, I'm not sure there's anything left to do here. Folks who want a persistent volume on a container resource now do something like this:

var database = builder.AddSqlServerContainer("sqlserver", "abcdefg123_78")
    .WithVolumeMount("data", "/var/opt/mssql")
    .AddDatabase("appdb");

The only thing I can think that might be worth adding is that right now it's hard to name the volume based on the application/resource names, but that might be better left to more domain-specific helper methods like #837.

Thoughts @davidfowl @JamesNK?

@davidfowl
Copy link
Member

Agreed, I think we follow the model that @mitchdenny introduced for emulators (UsePersistence()) though maybe we rename it 😄

@github-actions github-actions bot locked and limited conversation to collaborators Apr 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

5 participants