-
Notifications
You must be signed in to change notification settings - Fork 480
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 WithBindMount method #2245
Add WithBindMount method #2245
Conversation
.WithVolumeMount(Path.GetTempFileName(), "/etc/phpmyadmin/config.user.inc.php") | ||
.WithBindMount(Path.GetTempFileName(), "/etc/phpmyadmin/config.user.inc.php") |
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.
What was the intended volume mount type here? The previous WithVolumeMount
usage would have created a bind mount (unintentionally?), but it looks like what was desired was a volume mount with a random name.
Can someone who knows this code confirm?
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.
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.
IMO in this, and the other case, a volume mount makes more sense, both for "I do not care about the data being deleted at the end of the run" scenario, as well as for "I want the data to be preserved" scenario.
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.
If there isn't a decision made either way by someone who knows this code before this PR is ready to merge, then I'll create an issue to look into it.
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.
So in the code highlighted the file that is there is produced by the app model and injected into the container, so i think that bind mount is what is preferred - although it is an internal implementation detail.
@@ -85,7 +85,7 @@ public static IResourceBuilder<PostgresDatabaseResource> AddDatabase(this IResou | |||
.WithAnnotation(new ContainerImageAnnotation { Image = "dpage/pgadmin4", Tag = "latest" }) | |||
.WithHttpEndpoint(containerPort: 80, hostPort: hostPort, name: containerName) | |||
.WithEnvironment(SetPgAdminEnviromentVariables) | |||
.WithVolumeMount(Path.GetTempFileName(), "/pgadmin4/servers.json") | |||
.WithBindMount(Path.GetTempFileName(), "/pgadmin4/servers.json") |
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.
Same as previous comment. What mount type should this be?
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 should be a bind mount as well.
The DCP unification of bind mounts and volume mounts is loosely based on the syntax of the I do not think we support anonymous volume mounts today, but that could be added if desired |
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.
LGTM. I like how it makes the API clearer.
.WithVolumeMount(Path.GetTempFileName(), "/etc/phpmyadmin/config.user.inc.php") | ||
.WithBindMount(Path.GetTempFileName(), "/etc/phpmyadmin/config.user.inc.php") |
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.
IMO in this, and the other case, a volume mount makes more sense, both for "I do not care about the data being deleted at the end of the run" scenario, as well as for "I want the data to be preserved" scenario.
Ok. IMO it's confusing that there is a volume mount of bind. Volume vs bind are exclusive, at least in Docker. But it's not a big deal in DCP's data model if volumeMount has a weird name (just mount would be less confusing) because no one will see it.
Ok, I'll remove nullable option from volume mount source. If someone requests anonymous volumes in the future, then we can add support then. |
I think separating the concepts is the right thing to do. In the future we want to add volume mount support for resources when they are deployed so that an appropriate cloud-backed storage provider can be plugged in (it's essential for some containerization scenarios). Bind mounts wouldn't make sense in this context so separating the concepts works well. I think it also leaves room for things like secret mounts etc. |
This came up in the workshop as well (many questions about how local volumes get mapped to cloud). |
One thought ... should we introduce separate annotations entirely? We can merge them together for the bridge to DCP but we can keep the concepts isolated in the app model side. |
If you think it’s a good idea, then I’ll do it. Edit: What is the benefit? Right now, the data on the annotation is exactly the same for both mount types. What would change if we moved to two attributes? (other than the type disappearing). I'm guessing you're thinking about a public static IResourceBuilder<T> WithVolumeMount<T>(
this IResourceBuilder<T> builder, Volume source, string target, bool isReadOnly = false) where T : ContainerResource
{
var annotation = new VolumeMountAnnotation(source, target, ContainerMountType.Named, isReadOnly);
return builder.WithAnnotation(annotation);
} var data = builder.AddVolume("data");
var catalogDb = builder.AddPostgres("postgres")
.WithPgAdmin()
.AddDatabase("catalogdb")
.WithVolumeMount(data, "/etc/data"); ...would end up with the volume on the annotation. Why would that be better than setting whatever name is on the volume ( public static IResourceBuilder<T> WithVolumeMount<T>(
this IResourceBuilder<T> builder, Volume source, string target, bool isReadOnly = false) where T : ContainerResource
{
var annotation = new ContainerMountAnnotation(source.Name, target, ContainerMountType.Named, isReadOnly);
return builder.WithAnnotation(annotation);
} |
When we tackle volume support at deployment time in the future, we'll probably need to have some kind of concept of where the source for the volume is. For Azure-based deployments this might be either Azure Files (assuming an ACA compute) or something else. None of these options align to a bind mount which is why I thought splitting them out made sense. |
.. in short though, yes I think we'll have something like |
I have one change to request since we're touching this code. Can you make the default path relative to the apphost directory?
|
But won't it just involve setting the existing source property to whatever value the volume has? What is the scenario where a volume mount needs something other than |
So remove the |
Yes. Move the GetFullPath to the underlying path resolution. |
I'm going to merge this as is, and follow up stuff (maybe splitting up annotation, azure path change) can be follow up PRs. |
Fixes #1437
The
WithVolumeMount
method today confuses two container concepts:I noticed that DCP does the same thing. I'm not sure who influenced who, but while it doesn't matter to a user's experience what things are called in DCP data, the Aspire.Hosting model should use the right terminology.
Changes:
WithBindMount
WithVolumeMount
. Now you must either useWithVolumeMount
orWithBindMount
to get the mount you want. IMPORTANT: The mount type onWithVolumeMount
previously defaulted to binding mount. IMO this was confusing. However, with the change to split the method in two,WithVolumeMount
now always creates a volume mount. This is a breaking change.WithVolumeMount(@"c:\data", @"/etc/data")
creates a binding mount withc:\data
as source pathWithVolumeMount(@"c:\data", @"/etc/data")
creates a volume mount with the namec:\data
.WithVolumeMount
'ssource
parameter to be nullable. A volume can have a name or be anonymous. I haven't tested that DCP is cool with anonymous volumes yet. @karolz-ms Do you know?VolumeMountXXX
toContainerMountXXX
.New API:
There are experiments with making volumes a first-class concept: #1521. If this is implemented, then I expect
WithVolumeMount
will have an overload that takes the volume as source instead of a string:Microsoft Reviewers: Open in CodeFlow