Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 21, 2025

Problem

Running aspire deploy on a Python project using UV package manager fails when the uv.lock file doesn't exist. This happens when deploying without running aspire run first:

docker buildx (stderr): ERROR: failed to build: failed to solve: failed to compute
cache key: failed to calculate checksum of ref ngtgltiej6cnsp6a6149o0sm2::dz4b7s2gighc6by5chyfoyue0: "/app/uv.lock": not found

The generated Dockerfile attempted to bind mount uv.lock and use the --locked flag with uv sync, but the file only exists after running aspire run locally (via WithUvEnvironment()).

Solution

Modified the Dockerfile generation logic to check if uv.lock exists and generate appropriate Docker commands:

When uv.lock exists (after running locally):

  • Uses --locked flag with bind mounts for reproducible builds
  • Ensures consistent dependency versions across builds

When uv.lock doesn't exist (first-time deploy):

  • Copies only pyproject.toml to the container
  • Runs uv sync without --locked to generate the lock file during Docker build
  • Allows deployment without running the app locally first

Example 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-dev

After (when uv.lock doesn't exist):

COPY pyproject.toml /app/
RUN --mount=type=cache,target=/root/.cache/uv \
    uv sync --no-install-project --no-dev

This allows aspire deploy to work on a fresh clone of a Python project without requiring aspire run to be executed first.

Fixes #8862

cc @davidfowl @mitchdenny

Original prompt

This section details on the original issue you should resolve

<issue_title>aspire deploy of the py-starter app without running first fails</issue_title>
<issue_description>Error is:

dotnet(66820) stdout:       docker buildx (stderr): ERROR: failed to build: failed to solve: failed to compute
cache key: failed to calculate checksum of ref ngtgltiej6cnsp6a6149o0sm2::dz4b7s2gighc6by5chyfoyue0: "/app/uv.lock": not found

This is because we removed the uv.lock file. It gets generated when we run uv sync which only happens during aspire run.

We should ensure uv sync runs first, or somehow else fix the dockerfile.

cc @davidfowl @mitchdenny </issue_description>

<agent_instructions>This is the docker file, we need to handle when uv sync has never run outside of the docker file as well.

.RunWithMounts(
"uv sync --locked --no-install-project --no-dev",
"type=cache,target=/root/.cache/uv",
"type=bind,source=uv.lock,target=uv.lock",
"type=bind,source=pyproject.toml,target=pyproject.toml")
</agent_instructions>

Comments on the Issue (you are @copilot in this section)

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.

- 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]>
Copilot AI changed the title [WIP] Fix aspire deploy failure due to missing uv.lock Fix aspire deploy of Python apps when uv.lock doesn't exist Oct 21, 2025
Copilot AI requested a review from davidfowl October 21, 2025 05:48
Copilot finished work on behalf of davidfowl October 21, 2025 05:48
@github-actions
Copy link
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12240

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12240"

1 similar comment
@github-actions
Copy link
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12240

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12240"

@davidfowl davidfowl marked this pull request as ready for review October 23, 2025 05:16
@davidfowl davidfowl requested review from Copilot and eerhardt October 23, 2025 05:16
@davidfowl
Copy link
Member

OK this works!

Copy link
Contributor

Copilot AI left a 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.lock file existence before generating Dockerfiles
  • Implemented two different Dockerfile generation paths: one for locked mode (when uv.lock exists) 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

@davidfowl davidfowl requested a review from mitchdenny October 23, 2025 05:18
@mitchdenny mitchdenny merged commit fb43e58 into main Oct 23, 2025
306 of 308 checks passed
@mitchdenny mitchdenny deleted the copilot/fix-aspire-deploy-issue branch October 23, 2025 07:00
@dotnet-policy-service dotnet-policy-service bot added this to the 13.0 milestone Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

aspire deploy of the py-starter app without running first fails .WithContainerName() is ignored during aspire publish

3 participants