-
Notifications
You must be signed in to change notification settings - Fork 142
Add automatic Dockerfile generation with version detection for Golang integration #969
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
Conversation
Co-authored-by: tommasodotNET <12819039+tommasodotNET@users.noreply.github.com>
Co-authored-by: tommasodotNET <12819039+tommasodotNET@users.noreply.github.com>
Co-authored-by: tommasodotNET <12819039+tommasodotNET@users.noreply.github.com>
| buildArgs.Add(executable); | ||
|
|
||
| var buildStage = context.Builder | ||
| .From("golang:1.23", "builder") |
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 See the code here https://github.com/dotnet/aspire/blob/04bae8e2f0dfa71823b74dc3a7a48c630f441e99/src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs#L316-L322. Use DockerfileBaseImageAnnotation to override the default base image. Also handle detecting the default go version based on the go installed and fallback to version.
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.
Done! Added DockerfileBaseImageAnnotation support to customize both build and runtime images, and implemented automatic Go version detection from go.mod and installed toolchain with fallback to 1.23. The implementation follows the JavaScript integration pattern. (46c54ea)
…tection Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
| ```csharp | ||
| var golang = builder.AddGolangApp("golang", "../gin-api") | ||
| .WithHttpEndpoint(env: "PORT") | ||
| .WithAnnotation(new DockerfileBaseImageAnnotation |
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 You can use WithDockerfileBaseImage:
builder.AddPythonApp("myapp", "path/to/app", "main.py")
.WithDockerfileBaseImage(
buildImage: "ghcr.io/astral-sh/uv:python3.12-bookworm-slim",
runtimeImage: "python:3.12-slim-bookworm");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.
Updated README to use WithDockerfileBaseImage() extension method for a cleaner API. (4fb890c)
Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Co-authored-by: tommasodotNET <12819039+tommasodotNET@users.noreply.github.com>
Added comprehensive unit tests for Go version detection in
Made |
|
I wrote something similar here (with less features), I think you should consider the |
Do you mean extending the current Go integration to support the installer model? If so, I'd prefer that we do it as a separate PR, so that we don't overcomplicate each PR produced. |
that's a great idea. i'll handle this in another pr so we can keep this one tied to the issue --> #975 |
|
@copilot looking at this sample https://github.com/davidfowl/aspire-13-samples/blob/731a43a848706cf0bbcece1506122e5b6c19f2d8/golang-api/apphost.cs#L31C39-L51C42 it looks like we are missing some steps in the container creation such as the certificate management |
Co-authored-by: tommasodotNET <12819039+tommasodotNET@users.noreply.github.com>
Added CA certificates installation and working directory to the runtime stage. The generated Dockerfile now includes:
This matches the pattern from the referenced sample. (8c72923) |
|
One more thing worth considering, if we want to support pushing files into go containers from other resources would be to implement |
as far as i understand, we just need to implement |
yeah saw that after. updated my comment and the issue. sry |
PublishAsGolangDockerfileextension method with Dockerfile builder support for GolangPublishAsGolangDockerfilewith custom Dockerfile builderSummary
Added automatic Dockerfile generation for Golang applications using Aspire 13's experimental
WithDockerfileBuilderAPI. The implementation:go.modfile or installed toolchain, falling back to 1.23golang:{detected-version}for the build stage andalpine:3.21for the runtime stage/appin the runtime stageDockerfileBaseImageAnnotationto customize both build and runtime imagesWithDockerfileBaseImage()API for easier customizationAddGolangAppcallCode quality improvements:
DetectGoVersionmethod internal and added InternalsVisibleTo for testingRuntime improvements:
apk --no-cache add ca-certificates) to Alpine runtime image for HTTPS support/appin runtime stage for better organizationTest coverage:
All unit tests pass (8/8) and the code follows the project's style guidelines.
Fixes #968
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.