FROM python:3.12.13-bookworm AS builder
ENV PYTHONUNBUFFERED=1
ARG POETRY_VERSION=2.3.2
# Install system build dependencies required for building and compiling Python packages
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
libssl-dev \
libffi-dev \
python3-dev \
cargo \
git \
curl \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Install Poetry (exact version per blueprint)
RUN python -m pip install --no-cache-dir poetry==${POETRY_VERSION}
WORKDIR /app
# Copy only pyproject.toml and poetry.lock first to leverage caching
COPY pyproject.toml poetry.lock* /app/
ENV POETRY_VIRTUALENVS_CREATE=false
# Install dependencies for the project (build-time step)
RUN poetry install --no-interaction --no-ansi
# Copy the rest of the repository
COPY . /app
# Build the project from source (wheel will be placed in dist/)
RUN poetry build
# Runtime image: minimal Python environment with Poetry installed from the built wheel
FROM python:3.12.13-bookworm
ENV PYTHONUNBUFFERED=1
WORKDIR /app
# Copy built wheel from builder stage
COPY --from=builder /app/dist /dist
# Install the built Poetry wheel into the runtime image
RUN python -m pip install --no-cache-dir /dist/poetry-*.whl
ENTRYPOINT ["poetry"]
CMD ["--version"]
# Ignore version control .git/ # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # Distribution / packaging dist/ build/ *.egg-info/ # Virtual environments .venv/ venv/ ENV/ .env/ .envs/ # PyTest / caches .pytest_cache/ .mypy_cache/ .ruff_cache/ .cache/ # Node modules / frontend assets (not needed for Poetry project but safe to ignore) node_modules/ # Other *.log logs/ # Local mypy / caches migrations/
# Ignore version control .git/ # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # Distribution / packaging dist/ build/ *.egg-info/ # Virtual environments .venv/ venv/ ENV/ .env/ .envs/ # PyTest / caches .pytest_cache/ .mypy_cache/ .ruff_cache/ .cache/ # Node modules / frontend assets (not needed for Poetry project but safe to ignore) node_modules/ # Other *.log logs/ # Local mypy / caches migrations/
Concerns: The runtime stage attempts to install a wheel with a name matching /dist/poetry-*.whl, but /dist actually contains the project's built wheel, not Poetry. This will fail at build time and result in a non-functional image., The final image relies on Poetry as the entrypoint, but Poetry is not installed in the runtime stage (the RUN pip install targets a non-existent wheel). This means the container may not have the Poetry CLI available when run as intended., If the goal is to ship a CLI tool via Poetry, consider either installing Poetry in the runtime image (e.g., via pip install --no-cache-dir poetry==${POETRY_VERSION}) or copying the Poetry wheel from a separate build artifact, then install the built project wheel. Alternatively, install the project wheel and set the entrypoint to the actual CLI script exposed by the package.FROM python:3.12.13-bookworm AS builder
ENV PYTHONUNBUFFERED=1
ARG POETRY_VERSION=2.3.2
# Install system build dependencies required for building and compiling Python packages
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
libssl-dev \
libffi-dev \
python3-dev \
cargo \
git \
curl \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Install Poetry (exact version per blueprint)
RUN python -m pip install --no-cache-dir poetry==${POETRY_VERSION}
WORKDIR /app
# Copy only pyproject.toml and poetry.lock first to leverage caching
COPY pyproject.toml poetry.lock* /app/
ENV POETRY_VIRTUALENVS_CREATE=false
# Install dependencies for the project (build-time step)
RUN poetry install --no-interaction --no-ansi
# Copy the rest of the repository
COPY . /app
# Build the project from source (wheel will be placed in dist/)
RUN poetry build
# Runtime image: minimal Python environment with Poetry installed from the built wheel
FROM python:3.12.13-bookworm
ENV PYTHONUNBUFFERED=1
WORKDIR /app
# Copy built wheel from builder stage (explicit name to avoid wildcard issues)
COPY --from=builder /app/dist/poetry-2.3.2-py3-none-any.whl /dist/poetry-2.3.2-py3-none-any.whl
# Install the built Poetry wheel into the runtime image
RUN python -m pip install --no-cache-dir /dist/poetry-2.3.2-py3-none-any.whl
ENTRYPOINT ["poetry"]
CMD ["--version"]
- Build status: build_failed - Failing step: [builder 6/8] RUN poetry install --no-interaction --no-ansi (in Dockerfile) - Exact error: The current project could not be installed: Readme path `/app/README.md` does not exist. Exit code: 1 - Command that failed: RUN poetry install --no-interaction --no-ansi - Missing file: Readme path `/app/README.md` does not exist. Poetry attempted to install the current project and failed due to the missing README at /app/README.md. - Context / environment: - Base image: python:3.12.13-bookworm - Debian apt installs a Python 3.11 stack side-by-side (libpython3.11, python3.11-dev, etc.) - Packaging adjustments during build: downgrades of packaging (26.0→25.0), virtualenv (21.2.0→20.36.1), pbs-installer (2026.3.10→2026.1.14), platformdirs (4.9.4→4.5.1) - Poetry version installed: 2.3.2 - Log shows: Installing the current project: poetry (2.3.2) just before the failure; error arises during packaging, not dependency resolution - Actionable notes / workarounds: - If you don’t want to install the current project as a package: run poetry install --no-root - Ensure pyproject.toml has packages configured - Add README.md at /app/README.md - Additional observations: - The build copies a wheel named poetry-2.3.2-py3-none-any.whl from the builder stage; this wheel-name assumption is brittle if package name/version changes.
FROM python:3.12.13-bookworm AS builder
ENV PYTHONUNBUFFERED=1
ARG POETRY_VERSION=2.3.2
# Install system build dependencies required for building and compiling Python packages
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
libssl-dev \
libffi-dev \
python3-dev \
cargo \
git \
curl \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Install Poetry (exact version per blueprint)
RUN python -m pip install --no-cache-dir poetry==${POETRY_VERSION}
WORKDIR /app
# Copy only pyproject.toml and poetry.lock first to leverage caching
COPY pyproject.toml poetry.lock* /app/
ENV POETRY_VIRTUALENVS_CREATE=false
# Install dependencies for the project (build-time step)
# Use --no-root to avoid installing the current project as a package (prevents missing README issue)
RUN poetry install --no-interaction --no-ansi --no-root
# Copy the rest of the repository
COPY . /app
# Build the project from source (wheel will be placed in dist/)
RUN poetry build
# Runtime image: minimal Python environment with Poetry installed from the built wheel
FROM python:3.12.13-bookworm
ENV PYTHONUNBUFFERED=1
WORKDIR /app
# Copy built wheel from builder stage (explicit name to avoid wildcard issues)
COPY --from=builder /app/dist/poetry-2.3.2-py3-none-any.whl /dist/poetry-2.3.2-py3-none-any.whl
# Install the built Poetry wheel into the runtime image
RUN python -m pip install --no-cache-dir /dist/poetry-2.3.2-py3-none-any.whl
ENTRYPOINT ["poetry"]
CMD ["--version"]
Concerns: COPY pyproject.toml poetry.lock* assumes a poetry.lock file exists; if the lock file is absent, the COPY may fail during build., Hard-coded wheel filename in COPY --from=builder /app/dist/poetry-2.3.2-py3-none-any.whl may break if the project name/version changes or the build outputs a differently named wheel., Smoke tests only verify version/CLI presence; consider adding a basic functional test (e.g., running a simple Poetry command) to ensure runtime behavior beyond --version. Smoke [PASS]: poetry --version Smoke [PASS]: poetry --help