FROM python:3.12-slim

RUN apt-get update && apt-get install -y --no-install-recommends openssh-client && rm -rf /var/lib/apt/lists/*

WORKDIR /app

RUN pip install --no-cache-dir \
    fastapi==0.115.12 \
    "uvicorn[standard]==0.34.0" \
    jinja2==3.1.6 \
    python-multipart==0.0.20

COPY app/ ./app/
COPY scripts/ ./scripts/
COPY docs/_build/html /app/docs

ENV COSMA_QC_DB=/var/lib/cosma-qc/jobs.db

EXPOSE 8000

CMD ["/bin/sh", "-c", "if [ -d /ssh-in ]; then mkdir -p /root/.ssh && cp -r /ssh-in/. /root/.ssh/ && chmod 700 /root/.ssh && chmod 600 /root/.ssh/* 2>/dev/null; fi && uvicorn app.main:app --host 0.0.0.0 --port 8000"]
