# syntax=docker/dockerfile:1

# ---- Stage 1: compile Tailwind CSS with the standalone CLI (no Node) ----
FROM debian:bookworm-slim AS css
WORKDIR /build
RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates \
    && rm -rf /var/lib/apt/lists/*
RUN curl -fsSL -o /usr/local/bin/tailwindcss \
      https://github.com/tailwindlabs/tailwindcss/releases/download/v3.4.10/tailwindcss-linux-x64 \
    && chmod +x /usr/local/bin/tailwindcss
COPY tailwind.config.js ./
COPY app/templates ./app/templates
COPY app/static/src.css ./app/static/src.css
RUN tailwindcss -c tailwind.config.js -i app/static/src.css -o app/static/app.css --minify

# ---- Stage 2: runtime ----
FROM python:3.12-slim AS runtime
WORKDIR /app
ENV PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1

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

COPY app ./app
COPY wsgi.py ./
# Compiled CSS from the build stage (overwrites any dev copy).
COPY --from=css /build/app/static/app.css ./app/static/app.css

EXPOSE 8080
# Single worker so only ONE APScheduler runs; threads handle UI concurrency.
CMD ["gunicorn", "-w", "1", "--threads", "8", "-b", "0.0.0.0:8080", \
     "--timeout", "600", "wsgi:app"]
