# syntax=docker/dockerfile:1
# One image: build the React console, then run FastAPI serving the API + that console.
# No Redis (jobs are in-process) and no Mongo here (it's Atlas) — nothing else to orchestrate.

# --- stage 1: build the console ---
FROM node:20-alpine AS web
WORKDIR /web
COPY web/package.json web/package-lock.json* ./
RUN npm ci 2>/dev/null || npm install
COPY web/ ./
RUN npm run build

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

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

COPY gh_key_hunter.py keystore.py check_keys.py ./
COPY api/ ./api/
COPY --from=web /web/dist ./web/dist

EXPOSE 8001
# Secrets (GITHUB_TOKEN, MONGODB_URI, API_TOKEN) come from the environment at run time, never baked in.
CMD ["uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "8001"]
