-
Notifications
You must be signed in to change notification settings - Fork 762
Generate fallback Dockerfile for Python apps without UV #12627
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
Generate fallback Dockerfile for Python apps without UV #12627
Conversation
- Modified PythonAppResourceBuilderExtensions to generate Dockerfiles for all Python apps - Split Dockerfile generation into two methods: GenerateUvDockerfile and GenerateFallbackDockerfile - Fallback Dockerfiles detect requirements.txt and run pip install if present - Uses same runtime image (python:X.Y-slim-bookworm) as UV workflow for consistency - Updated PythonVersionDetector to accept nullable VirtualEnvironment parameter - Added comprehensive tests for fallback Dockerfile generation Co-authored-by: davidfowl <[email protected]>
…move empty line Co-authored-by: davidfowl <[email protected]>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12627Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12627" |
src/Aspire.Hosting.Python/PythonAppResourceBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
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.
I just had the one comment. Beyond that, this looks good to me.
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 support for generating fallback Dockerfiles for Python applications that don't use UV (the modern Python package installer). Previously, Dockerfiles were only generated for UV-based projects; now projects using traditional requirements.txt or no dependencies at all will also get appropriate Dockerfiles generated.
Key changes:
- Refactored Dockerfile generation logic to support both UV and non-UV Python projects
- Added a new
GenerateFallbackDockerfilemethod for traditional Python projects using pip/requirements.txt - Updated version detection to handle cases where no virtual environment exists
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/Aspire.Hosting.Python/PythonAppResourceBuilderExtensions.cs |
Refactored Dockerfile generation into separate methods (GenerateUvDockerfile and GenerateFallbackDockerfile) to support both UV and traditional Python projects |
src/Aspire.Hosting.Python/PythonVersionDetector.cs |
Changed virtualEnvironment parameter to nullable and added null check to support version detection without a virtual environment |
tests/Aspire.Hosting.Python.Tests/AddPythonAppTests.cs |
Added three new test methods to verify fallback Dockerfile generation for various scenarios (with/without requirements.txt, different entrypoint types) |
tests/Aspire.Hosting.Python.Tests/Snapshots/*.verified.txt |
Added snapshot files for the new test cases showing expected Dockerfile content |
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.
I just had the one comment. Beyond that, this looks good to me.
|
/backport to release/13.0 |
|
Started backporting to release/13.0: https://github.com/dotnet/aspire/actions/runs/19051517713 |
|
/backport to release/13.0 |
|
Started backporting to release/13.0: https://github.com/dotnet/aspire/actions/runs/19051857972 |
Previously, Dockerfiles were only generated for Python apps using UV. Non-UV Python apps had no automatic containerization support.
Changes
GenerateUvDockerfileandGenerateFallbackDockerfilemethodspython:{version}-slim-bookwormrequirements.txtand runpip install --no-cache-dir -r requirements.txtwhen presentPythonVersionDetectorto accept nullableVirtualEnvironmentfor version detection without venvExample
Generated Dockerfile (with requirements.txt):
Original prompt
💡 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.