Fix pip+pyproject.toml apps missing install commands in generated Dockerfile
Description
Python apps using pip with pyproject.toml (without requirements.txt) were generating Dockerfiles without dependency installation commands, causing build failures. At runtime, pip install . executes automatically when pyproject.toml is detected, but this wasn't reflected in published Dockerfiles.
Fixes #8625
Changes
Modified GenerateFallbackDockerfile to check for pyproject.toml and generate appropriate install commands:
# Copy pyproject.toml for dependency installation
COPY pyproject.toml /app/pyproject.toml
# Install dependencies using pip
RUN apt-get update \
&& apt-get install -y --no-install-recommends build-essential \
&& pip install --no-cache-dir . \
&& apt-get purge -y --auto-remove build-essential \
&& rm -rf /var/lib/apt/lists/*
Priority: requirements.txt > pyproject.toml > none, matching runtime behavior.
Checklist
- Is this feature complete?
- [x] Yes. Ready to ship.
- [ ] No. Follow-up changes expected.
- Are you including unit tests for the changes and scenario tests if relevant?
- [x] Yes
- [ ] No
- Did you add public API?
- [ ] Yes
- If yes, did you have an API Review for it?
- [ ] Yes
- [ ] No
- Did you add
<remarks />and<code />elements on your triple slash comments?- [ ] Yes
- [ ] No
- If yes, did you have an API Review for it?
- [x] No
- [ ] Yes
- Does the change make any security assumptions or guarantees?
- [ ] Yes
- If yes, have you done a threat model and had a security review?
- [ ] Yes
- [ ] No
- If yes, have you done a threat model and had a security review?
- [x] No
- [ ] Yes
- Does the change require an update in our Aspire docs?
- [ ] Yes
- Link to aspire-docs issue (consider using one of the following templates):
- [x] No
- [ ] Yes
Original prompt
This section details on the original issue you should resolve
<issue_title>Python apps using pip and pyproject.toml don't get install commands in generated dockerfile</issue_title> <issue_description>### Is there an existing issue for this?
- [x] I have searched the existing issues
Describe the bug
When a python app doesn't have
WithUv, but has a pyproject.toml file, we automatically includepip install .at runtime.However, when we generate the dockerfile, we aren't including a call to install:
FROM python:3.13-slim-bookworm # ------------------------------ # 🚀 Python Application # ------------------------------ # Create non-root user for security RUN groupadd --system --gid 999 appuser && useradd --system --gid 999 --uid 999 --create-home appuser # Set working directory WORKDIR /app # Copy application files COPY --chown=appuser:appuser . /app # Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 # Use the non-root user to run the application USER appuser # Run the application ENTRYPOINT ["uvicorn"]Expected Behavior
The dockerfile should contain a call to
pip install .FROM python:3.13-slim-bookworm COPY --from=frontend_stage /app/dist /app/./static # ------------------------------ # 🚀 Python Application # ------------------------------ # Create non-root user for security RUN groupadd --system --gid 999 appuser && useradd --system --gid 999 --uid 999 --create-home appuser # Set working directory WORKDIR /app # Copy pyproject.toml for dependency installation COPY pyproject.toml /app/pyproject.toml # Install dependencies using pip RUN apt-get update \ && apt-get install -y --no-install-recommends build-essential \ && pip install --no-cache-dir . \ && apt-get purge -y --auto-remove build-essential \ && rm -rf /var/lib/apt/lists/* # Copy application files COPY --chown=appuser:appuser . /app # Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 # Use the non-root user to run the application USER appuser # Run the application ENTRYPOINT ["uvicorn"]Steps To Reproduce
Change the
.WithUv()call to.WithPip()from the aspire-py-starter template.You will also need to move the 2 .py files down into a
srcfolder.Exceptions (if any)
No response
.NET Version info
No response
Anything else?
No response</issue_description>
Comments on the Issue (you are @copilot in this section)
- Fixes dotnet/aspire#12875
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.
🚀 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 -- 12876
Or
- Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12876"