# Timetable solver — Timefold needs a JVM at runtime, so this image bundles
# OpenJDK 17 alongside Python 3.11.
FROM eclipse-temurin:17-jdk-alpine AS jdk

FROM python:3.11-slim

# Pull the JVM from the temurin image so we don't shell out to apt for a JDK
# (which on slim adds ~400 MB).
COPY --from=jdk /opt/java/openjdk /opt/java/openjdk
ENV JAVA_HOME=/opt/java/openjdk
ENV PATH="${JAVA_HOME}/bin:${PATH}"

WORKDIR /app

# Install runtime deps the JVM bridge needs.
RUN apt-get update && apt-get install -y --no-install-recommends \
        libgomp1 \
    && rm -rf /var/lib/apt/lists/*

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY app ./app

EXPOSE 8095

HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
    CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8095/health')" || exit 1

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8095"]
