Dockerfile 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. FROM node:16-alpine AS deps
  2. # Install dependencies only when needed. Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
  3. # RUN apk add --no-cache libc6-compat
  4. WORKDIR /app
  5. ARG POSTHOG_HOST=https://app.posthog.com
  6. ARG POSTHOG_API_KEY=posthog-api-key
  7. ARG INTERCOM_ID=intercom-id
  8. ARG NEXT_INFISICAL_PLATFORM_VERSION=next-infisical-platform-version
  9. # Copy over dependency files
  10. COPY package.json package-lock.json next.config.js ./
  11. # Install dependencies
  12. RUN npm ci --only-production --ignore-scripts
  13. # Rebuild the source code only when needed
  14. FROM node:16-alpine AS builder
  15. WORKDIR /app
  16. # Copy dependencies
  17. COPY --from=deps /app/node_modules ./node_modules
  18. # Copy all files
  19. COPY . .
  20. ENV NODE_ENV production
  21. ENV NEXT_PUBLIC_ENV production
  22. ARG POSTHOG_HOST
  23. ENV NEXT_PUBLIC_POSTHOG_HOST $POSTHOG_HOST
  24. ARG POSTHOG_API_KEY
  25. ENV NEXT_PUBLIC_POSTHOG_API_KEY $POSTHOG_API_KEY
  26. ARG INTERCOM_ID
  27. ENV NEXT_PUBLIC_INTERCOM_ID $INTERCOM_ID
  28. # Build
  29. RUN npm run build
  30. # Production image
  31. FROM node:16-alpine AS runner
  32. WORKDIR /app
  33. RUN addgroup --system --gid 1001 nodejs
  34. RUN adduser --system --uid 1001 nextjs
  35. RUN mkdir -p /app/.next/cache/images && chown nextjs:nodejs /app/.next/cache/images
  36. VOLUME /app/.next/cache/images
  37. ARG POSTHOG_API_KEY
  38. ENV NEXT_PUBLIC_POSTHOG_API_KEY=$POSTHOG_API_KEY \
  39. BAKED_NEXT_PUBLIC_POSTHOG_API_KEY=$POSTHOG_API_KEY
  40. ARG INTERCOM_ID
  41. ENV NEXT_PUBLIC_INTERCOM_ID=$INTERCOM_ID \
  42. BAKED_NEXT_PUBLIC_INTERCOM_ID=$INTERCOM_ID
  43. ARG NEXT_INFISICAL_PLATFORM_VERSION
  44. ENV NEXT_PUBLIC_INFISICAL_PLATFORM_VERSION=$NEXT_INFISICAL_PLATFORM_VERSION
  45. COPY --chown=nextjs:nodejs --chmod=555 scripts ./scripts
  46. COPY --from=builder /app/public ./public
  47. RUN chown nextjs:nodejs ./public/data
  48. COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
  49. COPY --from=builder --chown=nextjs:nodejs --chmod=777 /app/.next/static ./.next/static
  50. RUN chmod -R 777 /app/.next/server
  51. USER nextjs
  52. EXPOSE 3000
  53. ENV PORT 3000
  54. ENV NEXT_TELEMETRY_DISABLED 1
  55. HEALTHCHECK --interval=10s --timeout=3s --start-period=10s \
  56. CMD node scripts/healthcheck.js
  57. CMD ["/app/scripts/start.sh"]