FROM python:3.12-slim AS build
WORKDIR /build
RUN apt-get update && apt-get install -y --no-install-recommends build-essential && rm -rf /var/lib/apt/lists/*
COPY requirements.txt requirements-production.txt ./
RUN pip wheel --no-cache-dir --wheel-dir /wheels -r requirements-production.txt

FROM python:3.12-slim
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1 PORT=10000
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends tzdata ca-certificates && rm -rf /var/lib/apt/lists/*
COPY --from=build /wheels /wheels
COPY requirements.txt requirements-production.txt ./
RUN pip install --no-cache-dir --no-index --find-links=/wheels -r requirements-production.txt && rm -rf /wheels
COPY production.py server.py poetry_corpus.py translations.py gunicorn.conf.py ./
COPY planet-corpus.json index.html style.css voice.js ./
COPY source-bundle.zip LICENSE.txt ./
RUN useradd --create-home --uid 10001 possession
USER possession
EXPOSE 10000
CMD ["gunicorn", "--config", "gunicorn.conf.py", "production:application"]
