-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
60 lines (44 loc) · 1.55 KB
/
Copy pathDockerfile
File metadata and controls
60 lines (44 loc) · 1.55 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
# ==========================================
# STAGE 1: Dependency Builder
# ==========================================
FROM node:26.3.0-alpine AS builder
WORKDIR /app
# Install system utilities needed for compiling native bindings
RUN apk add --no-cache libc6-compat python3 make g++
# Copy package descriptors
COPY package*.json ./
COPY prisma ./prisma/
# Install all packages including devDependencies
RUN npm ci
# Copy application source files
COPY . .
# Generate Prisma Client
RUN npx prisma generate
# Compile Next.js production bundles and custom Express gateway server
RUN npm run build
# ==========================================
# STAGE 2: Production Runner
# ==========================================
FROM node:26.3.0-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV PORT=3000
# Create a secure, non-privileged system user for process execution
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs
# Copy runtime assets and standalone builds
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/docs ./docs
# Create database and uploads volumes with secure nodejs ownership
RUN mkdir -p /app/data /app/public/uploads/avatars && \
chown -R nextjs:nodejs /app
# Switch to non-root system user
USER nextjs
EXPOSE 3000
# Run custom compiled Express gateway server
CMD ["node", "dist/server.js"]