-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
88 lines (71 loc) · 3 KB
/
Dockerfile
File metadata and controls
88 lines (71 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# ==========================================
# Production Dockerfile for Next.js App
# Optimized for standalone output
# ==========================================
# Use build args for version pinning to ensure deterministic builds
ARG BUN_VERSION=1.3.10
ARG PRISMA_VERSION=7.4.0
# ------------------------------------------
# Stage 1: Dependencies
# ------------------------------------------
FROM node:20-alpine AS deps
ARG BUN_VERSION
RUN apk add --no-cache libc6-compat python3 make g++
RUN npm install -g bun@${BUN_VERSION}
WORKDIR /app
COPY package.json bun.lock ./
COPY prisma ./prisma
COPY prisma.config.ts ./
RUN bun install --frozen-lockfile
# ------------------------------------------
# Stage 2: Builder
# ------------------------------------------
FROM node:20-alpine AS builder
ARG BUN_VERSION
ARG PRISMA_VERSION
RUN npm install -g bun@${BUN_VERSION}
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ENV NEXT_TELEMETRY_DISABLED=1
# Generate Prisma Client
RUN DATABASE_URL=mysql://localhost:3306/dummy npx prisma@${PRISMA_VERSION} generate
# Build Next.js app (Standalone output enabled in next.config.ts)
RUN DATABASE_URL=mysql://localhost:3306/dummy bun run build
# ------------------------------------------
# Stage 3: Runner
# ------------------------------------------
FROM node:20-alpine AS runner
ARG BUN_VERSION
ARG PRISMA_VERSION
WORKDIR /app
# openssl required by Prisma query engine.
# wget required for healthcheck. nc (netcat) required for DB readiness check in entrypoint.
# bun and prisma CLI required for entrypoint (migrations/seeds)
RUN apk add --no-cache libc6-compat openssl wget
RUN npm install -g bun@${BUN_VERSION} prisma@${PRISMA_VERSION} @prisma/config@${PRISMA_VERSION} @prisma/driver-adapter-utils@${PRISMA_VERSION} tsx
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Copy standalone output and static assets
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/.prisma ./node_modules/.prisma
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/@prisma/client ./node_modules/@prisma/client
# Include Prisma artifacts for migrations in entrypoint
COPY --from=builder --chown=nextjs:nodejs /app/prisma ./prisma
COPY --from=builder --chown=nextjs:nodejs /app/prisma.config.ts ./
COPY --from=builder --chown=nextjs:nodejs /app/package.json ./
COPY --from=builder --chown=nextjs:nodejs /app/bun.lock ./
COPY --from=builder --chown=nextjs:nodejs /app/docker-entrypoint.sh ./
RUN chmod +x docker-entrypoint.sh
USER nextjs
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=5 \
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/api/health || exit 1
ENTRYPOINT ["./docker-entrypoint.sh"]
CMD ["node", "server.js"]