Guest User

Dockerfile

a guest
Jan 29th, 2024
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. FROM node:20-alpine AS base
  2. ENV PNPM_HOME="/pnpm"
  3. ENV PATH="$PNPM_HOME:$PATH"
  4. RUN npm install -g pnpm && pnpm add -g turbo
  5.  
  6. FROM base AS builder
  7. RUN apk add --no-cache libc6-compat
  8. RUN apk update
  9. WORKDIR /app
  10. COPY . .
  11. RUN turbo prune @myapp/merlin --docker
  12. RUN rm -rf /app/out/full/*/*/node_modules
  13.  
  14. # Add lockfile and package.json's of isolated subworkspace
  15. FROM base AS installer
  16. RUN apk add --no-cache libc6-compat
  17. RUN apk update
  18. WORKDIR /app
  19.  
  20. # First install the dependencies (as they change less often)
  21. COPY .gitignore .gitignore
  22. COPY --from=builder /app/out/json/ .
  23. COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
  24. RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install
  25.  
  26. # Build the project
  27. COPY --from=builder /app/out/full/ .
  28. RUN turbo run build --filter=@myapp/merlin
  29.  
  30. ENV SKIP_ENV_VALIDATION=
  31.  
  32. FROM base AS runner
  33. WORKDIR /app
  34. RUN npm i -g --arch=x64 --platform=linux --libc=glibc [email protected]
  35.  
  36. # Don't run production as root
  37. RUN addgroup --system --gid 1001 nodejs
  38. RUN adduser --system --uid 1001 nextjs
  39. USER nextjs
  40.  
  41. EXPOSE 3000
  42. ENV PORT 3000
  43. ENV HOSTNAME 0.0.0.0
  44.  
  45. COPY --from=installer /app/apps/nextjs/next.config.mjs .
  46. COPY --from=installer /app/apps/nextjs/package.json .
  47.  
  48. # Automatically leverage output traces to reduce image size
  49. # https://nextjs.org/docs/advanced-features/output-file-tracing
  50. COPY --from=installer --chown=nextjs:nodejs /app/apps/nextjs/.next/standalone .
  51. COPY --from=installer --chown=nextjs:nodejs /app/apps/nextjs/.next/static ./apps/nextjs/.next/static
  52. COPY --from=installer --chown=nextjs:nodejs /app/apps/nextjs/public ./apps/nextjs/public
  53.  
  54. ENV NEXT_SHARP_PATH=/usr/local/lib/node_modules/sharp
  55.  
  56. # Copy migrations over
  57. COPY apps/nextjs/src/server/db/migrations /app/apps/nextjs/src/server/db/migrations
  58.  
  59. CMD node apps/nextjs/server.js
Advertisement
Add Comment
Please, Sign In to add comment