-
Notifications
You must be signed in to change notification settings - Fork 707
Fix aspire deploy of Python apps when uv.lock doesn't exist #12240
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
- Check if uv.lock exists before generating Dockerfile - If exists, use --locked flag with bind mount for reproducible builds - If doesn't exist, copy pyproject.toml and run uv sync without --locked - Add test to verify Dockerfile generation without uv.lock file - All 62 Python hosting tests pass 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 -- 12240Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12240" |
1 similar comment
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12240Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12240" |
|
OK this works! |
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 fixes a deployment issue where aspire deploy fails for Python applications using the UV package manager when uv.lock doesn't exist. The fix implements conditional Dockerfile generation based on whether uv.lock is present in the project directory.
Key changes:
- Added runtime detection of
uv.lockfile existence before generating Dockerfiles - Implemented two different Dockerfile generation paths: one for locked mode (when
uv.lockexists) and one for unlocked mode (when it doesn't) - Added comprehensive test coverage for the new unlocked mode scenario
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/Aspire.Hosting.Python/PythonAppResourceBuilderExtensions.cs |
Added logic to check for uv.lock existence and generate appropriate Docker commands for locked vs unlocked scenarios |
tests/Aspire.Hosting.Python.Tests/AddPythonAppTests.cs |
Added new test WithUvEnvironment_GeneratesDockerfileInPublishMode_WithoutUvLock to verify Dockerfile generation without uv.lock |
tests/Aspire.Hosting.Python.Tests/Snapshots/AddPythonAppTests.WithUvEnvironment_GeneratesDockerfileInPublishMode_WithoutUvLock#00.verified.txt |
Snapshot verification for script entrypoint Dockerfile without uv.lock |
tests/Aspire.Hosting.Python.Tests/Snapshots/AddPythonAppTests.WithUvEnvironment_GeneratesDockerfileInPublishMode_WithoutUvLock#01.verified.txt |
Snapshot verification for module entrypoint Dockerfile without uv.lock |
tests/Aspire.Hosting.Python.Tests/Snapshots/AddPythonAppTests.WithUvEnvironment_GeneratesDockerfileInPublishMode_WithoutUvLock#02.verified.txt |
Snapshot verification for executable entrypoint Dockerfile without uv.lock |
Problem
Running
aspire deployon a Python project using UV package manager fails when theuv.lockfile doesn't exist. This happens when deploying without runningaspire runfirst:The generated Dockerfile attempted to bind mount
uv.lockand use the--lockedflag withuv sync, but the file only exists after runningaspire runlocally (viaWithUvEnvironment()).Solution
Modified the Dockerfile generation logic to check if
uv.lockexists and generate appropriate Docker commands:When uv.lock exists (after running locally):
--lockedflag with bind mounts for reproducible buildsWhen uv.lock doesn't exist (first-time deploy):
pyproject.tomlto the containeruv syncwithout--lockedto generate the lock file during Docker buildExample Dockerfile Changes
Before (always expected uv.lock):
RUN --mount=type=bind,source=uv.lock,target=uv.lock \ --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ uv sync --locked --no-install-project --no-devAfter (when uv.lock doesn't exist):
This allows
aspire deployto work on a fresh clone of a Python project without requiringaspire runto be executed first.Fixes #8862
cc @davidfowl @mitchdenny
Original prompt
Fixes #12237
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.