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