Dockerfile 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # syntax=docker/dockerfile:1
  2. # =============================================================================
  3. # Jenado Unlimited Website - Production Dockerfile
  4. # Multi-stage build for a minimal, secure production image.
  5. # =============================================================================
  6. # ---- Base image with Node (Alpine for small footprint) ------------------------
  7. FROM node:22-alpine AS base
  8. # Install system dependencies needed for sharp (image optimization) and healthchecks
  9. RUN apk add --no-cache libc6-compat wget
  10. WORKDIR /app
  11. # Enable corepack for pnpm (matches lockfileVersion 9)
  12. RUN corepack enable
  13. # ---- Dependencies stage -------------------------------------------------------
  14. FROM base AS deps
  15. # Copy only manifests for better layer caching
  16. COPY package.json pnpm-lock.yaml ./
  17. COPY pnpm-workspace.yaml ./
  18. # Install dependencies (frozen for reproducibility)
  19. RUN pnpm install --frozen-lockfile
  20. # ---- Builder stage ------------------------------------------------------------
  21. FROM base AS builder
  22. # Bring in dependencies
  23. COPY --from=deps /app/node_modules ./node_modules
  24. COPY . .
  25. # Build the Next.js app (uses output: "standalone" from next.config.ts)
  26. ENV NEXT_TELEMETRY_DISABLED=1
  27. RUN pnpm build
  28. # ---- Runner stage (minimal production image) ----------------------------------
  29. FROM base AS runner
  30. ENV NODE_ENV=production
  31. ENV NEXT_TELEMETRY_DISABLED=1
  32. # Default port (can be overridden at runtime)
  33. ENV PORT=3000
  34. # Create a non-root user for security
  35. RUN addgroup --system --gid 1001 nodejs \
  36. && adduser --system --uid 1001 nextjs
  37. WORKDIR /app
  38. # Copy public assets
  39. COPY --from=builder /app/public ./public
  40. # Copy standalone output (contains a minimal server.js + required node_modules)
  41. # See: https://nextjs.org/docs/app/api-reference/next-config-js/output
  42. COPY --from=builder /app/.next/standalone ./
  43. # Copy static assets into the correct location relative to server.js
  44. COPY --from=builder /app/.next/static ./.next/static
  45. # Ensure correct ownership
  46. RUN chown -R nextjs:nodejs /app
  47. USER nextjs
  48. EXPOSE 3000
  49. # Basic healthcheck using the /api/health endpoint
  50. HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
  51. CMD wget -qO- http://127.0.0.1:${PORT}/api/health || exit 1
  52. # Start the standalone server
  53. CMD ["node", "server.js"]