-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.backend
More file actions
64 lines (49 loc) · 3.27 KB
/
Copy pathDockerfile.backend
File metadata and controls
64 lines (49 loc) · 3.27 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
# ─────────────────────────────────────────────────────────────────────────────
# Stage 1: deps — install production-only dependencies
# ─────────────────────────────────────────────────────────────────────────────
FROM node:22-alpine AS deps
WORKDIR /app
COPY backend/package*.json ./
RUN npm install --omit=dev
# ─────────────────────────────────────────────────────────────────────────────
# Stage 2: builder — install all deps, generate Prisma client, compile TS
# ─────────────────────────────────────────────────────────────────────────────
FROM node:22-alpine AS builder
WORKDIR /app
COPY backend/package*.json ./
RUN npm install
# Copy Prisma schema and config first so generate can run before full src copy
COPY backend/prisma ./prisma
COPY backend/prisma.config.ts ./
RUN DATABASE_URL="mysql://placeholder:placeholder@localhost:3306/placeholder" npx prisma generate
# Copy source and build
COPY backend/tsconfig.json ./
COPY backend/src ./src
RUN npm run build
# ─────────────────────────────────────────────────────────────────────────────
# Stage 3: runner — lean production image
# ─────────────────────────────────────────────────────────────────────────────
FROM node:22-alpine AS runner
WORKDIR /app
# Create non-root user
RUN addgroup -g 1001 -S nodejs && adduser -S fastify -u 1001
# Production node_modules from deps stage
COPY --from=deps /app/node_modules ./node_modules
# Overlay the generated Prisma client (produced in builder, not in deps)
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
COPY --from=builder /app/node_modules/@prisma/client ./node_modules/@prisma/client
# Prisma CLI is a devDep — copy it so CMD can run `prisma migrate deploy`
COPY --from=builder /app/node_modules/prisma ./node_modules/prisma
COPY --from=builder /app/node_modules/.bin/prisma ./node_modules/.bin/prisma
# Application artifacts
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/prisma.config.ts ./
# cdn/ is the default filesystem upload directory (STORAGE_PATH=./cdn/).
# Mount a named volume here when STORAGE_DRIVER=filesystem in production.
# Skip the volume mount entirely when using STORAGE_DRIVER=s3 or cloudinary.
RUN mkdir -p cdn && chown -R fastify:nodejs cdn /app
USER fastify
EXPOSE 5000
# Run migrations then start the server
CMD ["sh", "-c", "node_modules/.bin/prisma migrate deploy && node dist/server.js"]