# SiMS HQ console — production image (D20 hosting slice).
# Runs the Express server, which also serves the built React UI and the public
# /share links, on port 5182. Postgres is EXTERNAL (the shared `accurate-postgres`
# container), reached over the host gateway — see docker-compose.yml.
FROM node:20-bookworm

# Chromium runtime libraries for puppeteer (PDF letterhead rendering).
RUN apt-get update && apt-get install -y --no-install-recommends \
      ca-certificates fonts-liberation \
      libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 \
      libgbm1 libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 \
      libpango-1.0-0 libcairo2 libasound2 libatspi2.0-0 libgtk-3-0 \
      libx11-6 libxcb1 libxext6 libxi6 \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Install all workspaces (also fetches puppeteer's Chromium + better-sqlite3 prebuilt
# binary for linux-x64), then build the web UI and bundle the server.
COPY . .
RUN npm install \
 && npm run build --workspace @sims/hq-web \
 && npm run build --workspace @sims/hq

ENV NODE_ENV=production
EXPOSE 5182

# Launch from the repo root: server.cjs resolves ../../hq-web/dist for the UI and
# loads better-sqlite3/puppeteer (kept external from the bundle) from ./node_modules.
CMD ["node", "apps/hq/dist/server.cjs"]
