-
Notifications
You must be signed in to change notification settings - Fork 763
Add annotation to specify custom base images for generated Dockerfiles #12566
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
…on method Co-authored-by: eerhardt <[email protected]>
4683fe6 to
3d4b330
Compare
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12566Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12566" |
|
@copilot also respect this annotation in Yarp in this code: aspire/src/Aspire.Hosting.Yarp/YarpResourceExtensions.cs Lines 170 to 193 in ad6efe8
|
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 introduces an experimental API for customizing Docker base images in generated Dockerfiles. The feature allows developers to override default base images for Python (with UV), Node.js, and Vite applications during containerization.
Key changes:
- Adds
DockerfileBaseImageAnnotationto store custom build and runtime image specifications - Implements
WithDockerfileBaseImage()extension method marked as experimental API - Updates Python and Node.js Dockerfile generators to consume the annotation when available
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Aspire.Hosting/ApplicationModel/DockerfileBaseImageAnnotation.cs | New annotation class for storing custom build and runtime base images |
| src/Aspire.Hosting/ContainerResourceBuilderExtensions.cs | New experimental WithDockerfileBaseImage() extension method with validation |
| src/Aspire.Hosting.Python/PythonAppResourceBuilderExtensions.cs | Updated UV Dockerfile generator to use custom base images from annotation |
| src/Aspire.Hosting.NodeJs/NodeExtensions.cs | Updated Node.js and Vite Dockerfile generators to use custom base images from annotation |
| tests/Aspire.Hosting.Python.Tests/AddPythonAppTests.cs | Test verifying custom base images in Python UV Dockerfiles |
| tests/Aspire.Hosting.NodeJs.Tests/AddNodeAppTests.cs | Test verifying custom base images in Node.js multi-stage Dockerfiles |
| tests/Aspire.Hosting.NodeJs.Tests/AddViteAppTests.cs | Test verifying custom base images in Vite single-stage Dockerfiles |
@copilot - scratch that. It isn't necessary. Yarp is already a ContainerResource that has a ContainerImageAnnotation. So the base image is already able to be specified that way. |
|
/backport to release/13.0 |
|
Started backporting to release/13.0: https://github.com/dotnet/aspire/actions/runs/18986383052 |
Python and Node.js projects now auto-generate Dockerfiles, but developers couldn't override the default base images. This adds support for specifying custom build and runtime images.
Changes
DockerfileBaseImageAnnotation- stores optionalBuildImageandRuntimeImagepropertiesWithDockerfileBaseImage<T>()extension method - fluent API to set custom images on anyIResourceghcr.io/astral-sh/uvandpythonimagesnodeimageUsage
Multi-stage builds (Python with UV):
Single-stage builds (Node.js):
Marked experimental with
ASPIREDOCKERFILEBUILDER001diagnostic. Fully backward compatible - defaults unchanged when annotation absent.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
centralus.data.mcr.microsoft.comdotnet publish /home/REDACTED/work/aspire/aspire/tests/testproject/TestProject.ServiceA/TestProject.ServiceA.csproj --configuration Release /t:PublishContainer /p:ContainerRepository=servicea(dns block)dotnet publish /home/REDACTED/work/aspire/aspire/tests/testproject/TestProject.ServiceA/TestProject.ServiceA.csproj --configuration Release /t:PublishContainer /p:ContainerRepository=servicea /p:ContainerArchiveOutputPath=/tmp/test-output /p:ContainerImageFormat=OCI /p:ContainerRuntimeIdentifier=linux-x64(dns block)buildkitd --allow-insecure-entitlement=network.host(dns block)If you need me to access, download, or install something from one of these locations, you can either:
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.