# =============================================================================
# SoHike-Next — Root Dockerfile (multi-service wrapper)
#
# In most deployments the ``backend/Dockerfile`` is used directly. This root
# Dockerfile exists for scenarios where the entire monorepo should be packaged
# into a single image (e.g. CI integration tests).
# =============================================================================

FROM python:3.11-slim AS builder

WORKDIR /app

RUN apt-get update && apt-get install -y --no-install-recommends \
    gcc libpq-dev \
    && rm -rf /var/lib/apt/lists/*

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

FROM python:3.11-slim

WORKDIR /app

RUN apt-get update && apt-get install -y --no-install-recommends \
    libpq-dev \
    && rm -rf /var/lib/apt/lists/*

COPY --from=builder /root/.local /root/.local
ENV PATH=/root/.local/bin:$PATH

COPY backend/ .

RUN mkdir -p /app/uploads

RUN groupadd -r sohike && useradd -r -g sohike -d /app -s /sbin/nologin sohike
RUN chown -R sohike:sohike /app
USER sohike

EXPOSE 8000

HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
    CMD python -c "import http.client; c=http.client.HTTPConnection('localhost',8000); c.request('GET','/api/v1/health'); r=c.getresponse(); exit(0 if r.status==200 else 1)"

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