aspire icon indicating copy to clipboard operation
aspire copied to clipboard

Fix pip+pyproject.toml apps missing install commands in generated Dockerfile

Open Copilot opened this issue 5 months ago • 1 comments

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
    • [x] No
  • 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
    • [x] No
  • Does the change require an update in our Aspire docs?
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 include pip 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 src folder.

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.

Copilot avatar Nov 10 '25 22:11 Copilot

🚀 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"

github-actions[bot] avatar Nov 13 '25 18:11 github-actions[bot]