-
Couldn't load subscription status.
- Fork 712
Add ContainerFilesDestinationAnnotation support to ProjectResource #12355
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
Implement pipeline step factory for ProjectResource to support copying static files from other container resources before building docker images. Co-authored-by: eerhardt <[email protected]>
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.
@copilot - apply the following feedback
…ource build steps - Added CopyContainerFilesAsync method to IContainerRuntime interface with implementations in ContainerRuntimeBase - Changed CopyContainerFilesToProjectAsync to use IContainerRuntime instead of calling docker directly - Fixed GetPublishDirectoryAsync to use 'dotnet msbuild -c Release -getProperty:PublishDir' instead of hardcoded path - Changed source resource build step to use generic CreateBuildImageStep instead of CreateProjectBuildImageStep Co-authored-by: eerhardt <[email protected]>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12355Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12355" |
| Tags = [WellKnownPipelineTags.BuildCompute] | ||
| }; | ||
|
|
||
| private static async Task CopyContainerFilesToProjectAsync( |
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.
@copilot - change this implementation around. Instead of copying the files to the PublishDir of the project, follow this design:
- BuildImageAsync on the ProjectResource first.
- Tag the resulting image with a computed tag like
temp-{Guid.NewGuid()} - Generate a Dockerfile using the
DockerfileBuilderAPI that:FROMthe ProjectResource's image name andtemp-{GUID}tagCOPY --from:the ContainerFilesDestinationAnnotation's source- Tag that final image with the real image tag
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.
Implemented in cd9a23f and 1b0aa02. The new approach:
- Builds ProjectResource image first using normal flow
- Tags it with
temp-{GUID} - Generates Dockerfile using DockerfileBuilder API that FROMs the temp image
- Adds COPY --from: statements for each source container
- Builds final image from generated Dockerfile with real tag
This eliminates the need for CopyContainerFilesAsync and file system operations, using Docker's native multi-stage build capabilities instead.
|
@copilot - respond to the feedback |
… Dockerfile - Build ProjectResource image with normal flow first - Tag built image with temporary GUID tag - Generate Dockerfile that FROMs temp image and COPY --from source containers - Build final image from generated Dockerfile with real tag - Removed CopyContainerFilesAsync from IContainerRuntime (no longer needed) - Removed GetPublishDirectoryAsync helper (no longer needed) Co-authored-by: eerhardt <[email protected]>
The new design uses DockerfileBuilder with COPY --from: instead of extracting files from containers to the host filesystem, so the CopyContainerFilesAsync method is no longer needed. Co-authored-by: eerhardt <[email protected]>
All feedback has been addressed in commits cd9a23f and 1b0aa02: ✅ Line 1118 feedback: Refactored implementation to build ProjectResource image first, tag with temp GUID, generate Dockerfile using DockerfileBuilder API with COPY --from: statements, then build final image. ✅ Previous feedback resolved:
The implementation now uses Docker multi-stage builds with COPY --from: instead of filesystem operations, eliminating the need for CopyContainerFilesAsync and PublishDir determination. |
| .WithName("GetWeatherForecast") | ||
| .WithOpenApi(); | ||
|
|
||
| app.UseDefaultFiles(); |
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: UseFileServer combines these
| // Remove the temporary tagged image | ||
| //logger.LogDebug("Removing temporary image {TempImageName}", tempImageName); | ||
| //await containerRuntime.RemoveImageAsync(tempImageName, ctx.CancellationToken).ConfigureAwait(false); |
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.
@copilot - implement this feature in IContainerRuntime and its derived classes.
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.
Implemented in ba83528. Added RemoveImageAsync method to:
IContainerRuntimeinterfaceContainerRuntimeBaseimplementation usingrmicommand (inherited by both Docker and Podman runtimes)- Uncommented the cleanup code in ProjectResource.cs to remove temporary tagged images after building the final image
…ages - Added RemoveImageAsync method to IContainerRuntime interface - Implemented in ContainerRuntimeBase using 'rmi' command - Uncommented cleanup code in ProjectResource to remove temporary tagged images - Ensures temporary images are cleaned up after layering container files Co-authored-by: eerhardt <[email protected]>
Implementation Complete: Static Files Copying Support for ProjectResource
Successfully enhanced ProjectResource to support copying static files from other container resources before building docker images, following the pattern established in PR #12265.
✅ Completed - All Feedback Addressed
Latest Design (per review feedback):
Instead of copying files to PublishDir before building, the implementation now:
temp-{GUID})FROMthe temp-tagged ProjectResource imageCOPY --from:to layer files from source container imagesRemoveImageAsync📝 Implementation Summary
Files Modified:
src/Aspire.Hosting/ProjectResourceBuilderExtensions.csCreateBuildImageStepfor generic resource image buildingCreateProjectBuildImageStepto:src/Aspire.Hosting/Publishing/IContainerRuntime.csRemoveImageAsyncmethod for cleaning up temporary imagessrc/Aspire.Hosting/Publishing/ContainerRuntimeBase.csRemoveImageAsyncusingrmicommand (works for both Docker and Podman)tests/Aspire.Hosting.Tests/ProjectResourceTests.cs🔧 Technical Details
New Approach:
COPY --from:for efficient file copyingRemoveImageAsyncto IContainerRuntime interface for proper resource cleanupBenefits:
🎯 Usage
Files are layered into the project's container image using Docker COPY --from: during image build. Temporary images are automatically cleaned up after the final image is built.
✅ Testing & Validation
This pull request was created as a result of the following prompt from Copilot chat.
Original prompt
This pull request was created as a result of the following prompt from Copilot chat.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.