# Multi-stage Dockerfile for a Docusaurus site.
#
# Stage 1 builds the static site with Node.
# Stage 2 serves the resulting /build folder with a tiny nginx image.
# Final image is ~20-30 MB (nginx:alpine + static HTML) — kind to the
# DigitalOcean free-tier registry's 500 MB budget.
#
# For a NON-static app (e.g. a Node server, Python API), you'd skip the
# nginx stage and instead run your server directly — see notes at bottom.

# ---- Build stage ----
FROM node:20-alpine AS build
WORKDIR /app

# Install deps first (better layer caching — only re-runs when lockfile changes)
COPY package.json package-lock.json ./
RUN npm ci

# Build the static site → outputs to /app/build
COPY . .
RUN npm run build

# ---- Serve stage ----
FROM nginx:alpine

# Static site output
COPY --from=build /app/build /usr/share/nginx/html

# nginx config that handles Docusaurus clean URLs / 404s
COPY nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 80
# nginx:alpine already runs nginx in the foreground by default.

# ---------------------------------------------------------------------------
# Adapting this for a non-static app (delete the two stages above and use):
#
#   FROM node:20-alpine
#   WORKDIR /app
#   COPY package.json package-lock.json ./
#   RUN npm ci --omit=dev
#   COPY . .
#   EXPOSE 3000
#   CMD ["node", "server.js"]
#
# Then set <app-port> to your server's port in docker-compose.yml.
# ---------------------------------------------------------------------------
