Skip to content

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

Merged
eerhardt merged 3 commits intomainfrom
copilot/fix-dockerfile-install-command
Nov 19, 2025
Merged

Fix pip+pyproject.toml apps missing install commands in generated Dockerfile#12876
eerhardt merged 3 commits intomainfrom
copilot/fix-dockerfile-install-command

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 10, 2025

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?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • 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
    • 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
    • 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?

  • 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)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: eerhardt <8291187+eerhardt@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix dockerfile to include pip install command Fix pip+pyproject.toml apps missing install commands in generated Dockerfile Nov 10, 2025
Copilot AI requested a review from eerhardt November 10, 2025 22:31
@eerhardt eerhardt marked this pull request as ready for review November 13, 2025 18:57
@github-actions
Copy link
Copy Markdown
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 -- 12876

Or

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

Copilot AI review requested due to automatic review settings November 13, 2025 18:57
@eerhardt eerhardt requested a review from davidfowl November 13, 2025 19:05
Copy link
Copy Markdown
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@eerhardt eerhardt merged commit ac4c25a into main Nov 19, 2025
301 of 302 checks passed
@eerhardt eerhardt deleted the copilot/fix-dockerfile-install-command branch November 19, 2025 16:21
@dotnet-policy-service dotnet-policy-service bot added this to the 13.1 milestone Nov 19, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Dec 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python apps using pip and pyproject.toml don't get install commands in generated dockerfile

4 participants