# Runtime-only Dockerfile for Next.js 16 standalone output
# No build stage — assumes `.next/standalone`, `.next/static`, `public`
# are already built locally and shipped alongside this Dockerfile.
#
# Why: LXC 192.168.40.22 (target) is unprivileged + 2GB RAM, can't run
# `npm run build` (Next 16 build needs ~3GB peak + swapon is blocked).
# Build on the dev host (16GB RAM), ship artifacts, run-only on LXC.
#
# Build context expects:
#   ./.next/standalone/         (server.js, minimal node_modules, etc.)
#   ./.next/static/             (hashed JS/CSS chunks)
#   ./public/                   (static assets)
#   ./prisma/                   (schema + migrations, for runtime queries)

FROM node:22-alpine AS runner
WORKDIR /app

RUN apk add --no-cache libc6-compat openssl curl \
 && addgroup --system --gid 1001 nodejs \
 && adduser  --system --uid 1001 nextjs

ENV NODE_ENV=production \
    NEXT_TELEMETRY_DISABLED=1 \
    PORT=3000 \
    HOSTNAME=0.0.0.0

# Standalone output is self-contained: server.js + minimal node_modules
COPY --chown=nextjs:nodejs .next/standalone ./
COPY --chown=nextjs:nodejs .next/static     ./.next/static
COPY --chown=nextjs:nodejs public           ./public
COPY --chown=nextjs:nodejs prisma           ./prisma

USER nextjs
EXPOSE 3000

HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
  CMD curl -fsS http://localhost:3000/api/health || exit 1

CMD ["node", "server.js"]
