FROM node:22-bookworm-slim AS frontend

WORKDIR /app/frontend

RUN apt-get update \
    && apt-get install -y --no-install-recommends ca-certificates git \
    && rm -rf /var/lib/apt/lists/*

COPY frontend/package*.json ./
RUN npm ci

COPY frontend ./
RUN npm run build


FROM python:3.13-slim AS runtime

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1

WORKDIR /app

RUN apt-get update \
    && apt-get install -y --no-install-recommends ca-certificates git postgresql-client \
    && rm -rf /var/lib/apt/lists/*

COPY pyproject.toml README.md ./
COPY alembic.ini ./
COPY alembic ./alembic
COPY gnexus_creds ./gnexus_creds
COPY extensions ./extensions

RUN pip install --no-cache-dir .

COPY --from=frontend /app/frontend/dist ./frontend/dist
COPY --from=frontend /app/frontend/node_modules/gnexus-ui-kit/dist/assets/fonts ./frontend/node_modules/gnexus-ui-kit/dist/assets/fonts

EXPOSE 8000

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