-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
72 lines (52 loc) · 2.1 KB
/
Copy pathDockerfile
File metadata and controls
72 lines (52 loc) · 2.1 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
# ---------- Stage 1: Install dependencies ----------
FROM node:20-alpine AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
# Enable corepack so the correct pnpm version (from packageManager) is used
RUN corepack enable && corepack prepare pnpm@9.0.0 --activate
# Copy lockfile and workspace manifests first for layer caching
COPY pnpm-lock.yaml pnpm-workspace.yaml package.json ./
COPY apps/web/package.json ./apps/web/
COPY packages/database/package.json ./packages/database/
COPY packages/core/package.json ./packages/core/
COPY packages/ai/package.json ./packages/ai/
RUN pnpm install --frozen-lockfile
# ---------- Stage 2: Build the application ----------
FROM node:20-alpine AS builder
RUN apk add --no-cache libc6-compat
WORKDIR /app
RUN corepack enable && corepack prepare pnpm@9.0.0 --activate
# Copy installed node_modules from deps stage
COPY --from=deps /app/ ./
# Copy full source code
COPY . .
# Build args for values needed at build time only (Next.js inlines them).
# Runtime secrets (DATABASE_URL, NEXTAUTH_SECRET, etc.) are provided at
# container start and must NOT be set here.
ARG NEXT_PUBLIC_APP_URL=""
ARG SENTRY_ORG=""
ARG SENTRY_PROJECT=""
ENV NEXT_TELEMETRY_DISABLED=1
RUN pnpm build --filter=@kivvi/web
# ---------- Stage 3: Production runner ----------
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs
# Copy the standalone output (includes server + node_modules subset)
COPY --from=builder /app/apps/web/.next/standalone ./
# Copy static assets that standalone does not include
COPY --from=builder /app/apps/web/.next/static ./apps/web/.next/static
# Copy public assets if they exist (currently empty, but future-proof)
COPY --from=builder /app/apps/web/public ./apps/web/public
# Set correct ownership
RUN chown -R nextjs:nodejs /app
USER nextjs
# Next.js standalone server listens on 3000 by default
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
# The standalone output places the server entry point at apps/web/server.js
CMD ["node", "apps/web/server.js"]