-
Notifications
You must be signed in to change notification settings - Fork 153
Add IContainerFilesDestinationResource support to Golang integration #1108
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
Co-authored-by: tommasodotNET <[email protected]>
…port Co-authored-by: tommasodotNET <[email protected]>
Co-authored-by: tommasodotNET <[email protected]>
tommasodotNET
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.
@copilot looks like you are missing the update in the Golang Hosting Extensions.
we need to add .AddContainerFiles() similarly to what we do here:
var runtimeBuilder = dockerfileContext.Builder
.From(baseRuntimeImage, "runtime")
.EmptyLine()
.WorkDir("/app")
.CopyFrom("build", "/app", "/app")
.AddContainerFiles(dockerfileContext.Resource, "/app", logger)
.EmptyLine()
.Env("NODE_ENV", "production")
.EmptyLine()
.User("node")
.EmptyLine()
.Entrypoint([resource.Command, scriptPath]);Added the missing AddContainerFiles method call in the Golang hosting extension to properly handle container files during publishing. This ensures that files from resources implementing IContainerFilesDestinationResource are correctly copied into the generated Docker image. Changes: - Added using statement for Aspire.Hosting.ApplicationModel.Docker namespace - Added logger initialization from service provider - Added .AddContainerFiles(context.Resource, "/app", logger) call in the Dockerfile builder chain Co-authored-by: tommasodotNET <[email protected]>
Added the
All tests pass (12/12) and the build is successful. |
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 reviewed 8 out of 8 changed files in this pull request and generated 6 comments.
examples/golang/CommunityToolkit.Aspire.Hosting.Golang.AppHost/Program.cs
Outdated
Show resolved
Hide resolved
tests/CommunityToolkit.Aspire.Hosting.Golang.Tests/ResourceCreationTests.cs
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
…/Program.cs Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Added a new test to verify that the Golang resource properly implements IContainerFilesDestinationResource and supports container files during publishing. The test validates: - Resource implements the IContainerFilesDestinationResource interface - Default destination path is correctly set to /app/static - Resource is prepared for container files integration during Dockerfile generation Note: Direct testing with WithContainerFiles is not possible in unit tests as it requires ContainerResource types, but the Golang resource is an ExecutableResource that becomes a container during publishing via PublishAsDockerFile. Co-authored-by: tommasodotNET <[email protected]>
Minimum allowed line rate is |
Container Files Support for Golang Integration ✅
This PR adds support for pushing files into Go containers, as requested in the issue.
Implementation Summary
IContainerFilesDestinationResourceinterface implementation toGolangAppExecutableResource/app/static.AddContainerFiles()call in Dockerfile generation to handle container filesChanges Made
1. Resource Implementation (
GolangAppExecutableResource.cs)2. Dockerfile Generation (
GolangAppHostingExtension.cs)using Aspire.Hosting.ApplicationModel.Docker;to accessAddContainerFilesextension method.AddContainerFiles(context.Resource, "/app", logger)call in the Docker build chain to process container files3. Documentation (README.md)
4. Example Application
static-frontenddirectory with sample HTMLr.Static("/static", "./static"))5. Testing
Usage
Users can now copy files into Golang containers during publishing:
How It Works
GolangAppExecutableResourceimplementsIContainerFilesDestinationResource(marker interface)WithContainerFilesto register files to copy.AddContainerFiles()which:Testing
✅ All 13 resource creation tests pass (including new integration test)
✅ Tests validate
IContainerFilesDestinationResourceimplementation✅ Tests verify container files support for publishing workflow
✅ Builds successfully across all target frameworks (net8.0, net9.0, net10.0)
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.