-
Notifications
You must be signed in to change notification settings - Fork 752
Add RelativeSource and BasePath to ContainerMountAnnotation for bind mount source resolution #13443
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
base: main
Are you sure you want to change the base?
Conversation
- Add new `ContainerMountAnnotation` constructor with `isSourceRelative` parameter - Add `IsSourceRelative` property to track when paths are intentionally relative - Add new `WithBindMount` overload that accepts `Action<BindMountOptions>` - Create `BindMountOptions` class with `ResolveSourcePath` and `IsReadOnly` properties - Add tests for new functionality Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 13443Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 13443" |
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.
Pull request overview
This PR adds a new WithBindMount overload with an options callback that allows control over source path resolution behavior. This is specifically designed for Docker Compose scenarios where bind mount paths should remain relative to the compose file rather than being resolved to absolute paths.
- Introduces
BindMountOptionsclass withResolveSourcePath(default:true) andIsReadOnlyproperties - Adds
IsSourceRelativeproperty toContainerMountAnnotationto track whether paths are intentionally relative - Provides new
WithBindMountoverload acceptingAction<BindMountOptions>for configuration
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Aspire.Hosting/ApplicationModel/BindMountOptions.cs | New options class for configuring bind mount behavior with path resolution and read-only settings |
| src/Aspire.Hosting/ApplicationModel/ContainerMountAnnotation.cs | Added constructor overload with isSourceRelative parameter and corresponding property to track unresolved paths |
| src/Aspire.Hosting/ContainerResourceBuilderExtensions.cs | New WithBindMount overload with options callback that conditionally resolves paths based on settings |
| tests/Aspire.Hosting.Containers.Tests/ContainerMountAnnotationTests.cs | Tests for new constructor overload validating relative path handling and parameter combinations |
| tests/Aspire.Hosting.Containers.Tests/ContainerResourceTests.cs | Integration tests verifying the new WithBindMount overload behavior with various path resolution scenarios |
| /// paths should remain relative to the compose file location rather than being resolved to absolute paths. | ||
| /// </para> | ||
| /// </remarks> | ||
| public bool ResolveSourcePath { get; set; } = true; |
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.
Can we add a work item to make the default false in the next major Aspire release? That feels like it'd be the less surprising behavior in most cases, even though it'd be a breaking change.
|
@copilot Instead of bool isSourceRelative on ContainerMountAnnotation, we should store the BasePath to the source as a property on ContainerMountAnnotation. This way the source field is always relative to the base path. Consumers can choose to use both the base path and the source DcpExecutor.BuildContainerMounts, while others will ignore the base path (like docker compose assumes relative to the compose file). |
Per reviewer feedback, instead of bool isSourceRelative, the ContainerMountAnnotation now stores a BasePath property. The Source field is always stored as-is, and consumers can use BasePath + Source to resolve the full path, or ignore BasePath for Docker Compose scenarios where paths should remain relative to the compose file. Changes: - ContainerMountAnnotation: Added BasePath property, new constructor - ContainerResourceBuilderExtensions: Store source and basePath separately - DcpExecutor.BuildContainerMounts: Resolve path using BasePath - ManifestPublishingContext: Resolve path using BasePath - Updated tests to use BasePath property Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Implemented in 3b9d6d4. Changed the design to store
|
|
@copilot We no longer need BindMountOptions |
Replace Action<BindMountOptions> overload with simpler parameters: WithBindMount(source, target, isReadOnly, resolveSourcePath) This simplifies the API while maintaining the same functionality. When resolveSourcePath is false, no BasePath is stored, so Docker Compose can use relative paths directly. Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
|
@copilot Bring back Action and use put |
Per feedback, WithBindMount now always sets BasePath for relative paths. No new overload is needed - consumers can use BasePath to resolve paths or ignore it (like Docker Compose which uses paths relative to compose file). Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
|
@copilot To make this less breaking, leave Source alone and introduce a nwe RelativeSource and BasePath. |
Per feedback, this makes the change less breaking: - Source remains the resolved absolute path (backward compatible) - RelativeSource stores the original relative path as specified by user - BasePath stores the base path (app host directory) for the relative source Consumers can use RelativeSource and BasePath for Docker Compose scenarios where paths should remain relative to the compose file. Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
|
@copilot Update docker compose to use the RelativeSource and fallback to Source |
Docker Compose now uses RelativeSource (the original relative path) when available, falling back to Source (resolved absolute path) if RelativeSource is null. This keeps paths relative to the compose file for Docker Compose scenarios. Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
| /// <param name="isReadOnly">A value indicating whether the mount is read-only.</param> | ||
| /// <param name="relativeSource">The original relative source path before resolution. This is the path as specified by the user.</param> | ||
| /// <param name="basePath">The base path that <paramref name="relativeSource"/> is relative to. Typically the app host directory.</param> | ||
| public ContainerMountAnnotation(string? source, string target, ContainerMountType type, bool isReadOnly, string? relativeSource, string? basePath) |
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.
(nit) should the new properties just be get; init; and then we don't need a whole new constructor copying code?
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.
Yep
|
|
||
| /// <summary> | ||
| /// Gets the base path that <see cref="RelativeSource"/> is relative to. Typically the app host directory. | ||
| /// Consumers can use <see cref="RelativeSource"/> with <see cref="BasePath"/> for scenarios like Docker Compose |
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.
Consumers can use with for scenarios like Docker Compose
This feels like it should go in a remarks instead of a summary.
| var name = mount.Source; | ||
| // For Docker Compose, use RelativeSource if available (keeps paths relative to compose file), | ||
| // otherwise fallback to Source (resolved absolute path) | ||
| var sourceForCompose = mount.RelativeSource ?? mount.Source; |
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.
Why is this "forCompose"?
It might be simpler if we just have:
var source = mount.RelativeSource ?? mount.Source;
var name = source;
eerhardt
left a comment
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.
![]()
| else | ||
| { | ||
| // Relative path - resolve to absolute and store relative source with base path | ||
| basePath = builder.ApplicationBuilder.AppHostDirectory; |
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.
Feels like tracking the run time specific base path isn't necessary; at run time this would be implicit and at deploy time it wouldn't be used.
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.
We need it to calculate the absolute path here, but we don't really need to track it in the annotation.
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 see, so we just need a way to flow the AppHostDirectory to other places in the code.
Description
For Docker Compose scenarios, bind mount source paths need to stay relative to the compose file rather than being resolved to absolute paths. This adds
RelativeSourceandBasePathproperties toContainerMountAnnotationthat store the original relative path and app host directory, allowing consumers to use the relative path for scenarios like Docker Compose while maintaining backward compatibility with the existingSourceproperty.Changes
ContainerMountAnnotation: New constructor overload withrelativeSourceandbasePathparameters; newRelativeSourceproperty to store the original relative path andBasePathproperty to store the base path (app host directory). The existingSourceproperty remains unchanged as the resolved absolute path for backward compatibility.WithBindMount: Now setsSourceto the resolved absolute path,RelativeSourceto the original relative path, andBasePathto the app host directory for relative paths. For absolute paths,RelativeSourceandBasePatharenull.DockerComposeEnvironmentContext: Updated to useRelativeSourcewhen available, falling back toSourceifRelativeSourceisnull. This keeps paths relative to the compose file for Docker Compose scenarios.Usage
Existing consumers that use
Sourcewill continue to work without changes. Docker Compose usesRelativeSourcewhen available to keep paths relative to the compose file, falling back toSourcefor absolute paths.Checklist
<remarks />and<code />elements on your triple slash comments?doc-ideatemplatebreaking-changetemplatediagnostictemplateOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.