# Stage 1: Builder - Install dependencies FROM python:3.13-slim AS builder WORKDIR /build # Install build-time dependencies required for compiling packages like asyncpg RUN apt-get update && apt-get install -y --no-install-recommends \ gcc \ libpq-dev \ && rm -rf /var/lib/apt/lists/* COPY requirements.txt . RUN pip install --no-cache-dir --prefix=/install -r requirements.txt # Stage 2: Runner - Final lightweight image FROM python:3.13-slim AS runner ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 WORKDIR /app # Install runtime dependencies required by asyncpg RUN apt-get update && apt-get install -y --no-install-recommends \ libpq5 \ && rm -rf /var/lib/apt/lists/* # Copy installed Python packages from the builder stage COPY --from=builder /install /usr/local # Copy application source code COPY . . RUN sed -i 's/\r$//' ./entrypoints/api.sh && \ chmod +x ./entrypoints/api.sh # Ensure the api script is executable RUN chmod +x ./entrypoints/api.sh # Default command runs migrations and starts the API CMD ["sh", "./entrypoints/api.sh"]