# ---------------------------------------------------------------------------
# Media Team Hub — portable, containerized Next.js app.
# Multi-stage: build in an alpine/node image, run a lean runner image.
# The app is standard HTTP on :3000 — sit it behind your reverse proxy.
# ---------------------------------------------------------------------------

FROM node:22-alpine AS base
WORKDIR /app
ENV NODE_ENV=production
# pnpm is how this project is built (see package.json scripts).
RUN npm install -g pnpm@9.15.0

FROM base AS builder
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
# Frozen install — fails the build if the lockfile is out of sync.
RUN pnpm install --frozen-lockfile
COPY . .
RUN pnpm build

FROM node:22-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
# pnpm runs the app in production (see package.json scripts).
RUN npm install -g pnpm@9.15.0

# Run as a non-root user (busybox adduser/addgroup on alpine).
RUN addgroup -S nodegrp \
  && adduser -S -G nodegrp -H -D nextjs

# Build output, deps, static assets.
COPY --from=builder --chown=nextjs:nodegrp /app/public ./public
COPY --from=builder --chown=nextjs:nodegrp /app/node_modules ./node_modules
COPY --from=builder --chown=nextjs:nodegrp /app/package.json ./package.json
COPY --from=builder --chown=nextjs:nodegrp /app/.next ./.next

USER nextjs
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME=0.0.0.0
CMD ["pnpm", "start"]
