-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDockerfile
More file actions
88 lines (59 loc) · 1.94 KB
/
Copy pathDockerfile
File metadata and controls
88 lines (59 loc) · 1.94 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
# Multi-stage Dockerfile for QA Studio
# Supports both development and production builds
# Stage 1: Base Node.js image with dependencies
FROM node:22-alpine AS base
# Install dependencies needed for native modules
RUN apk add --no-cache libc6-compat openssl
WORKDIR /app
# Install dependencies based on lockfile
COPY package.json package-lock.json* ./
RUN npm ci
# Copy prisma schema for generation
COPY prisma ./prisma/
RUN npx prisma generate
# Stage 2: Development
FROM base AS development
WORKDIR /app
# Copy all source files
COPY . .
# Expose dev server port
EXPOSE 3000
# Run database migrations and start dev server
CMD ["sh", "-c", "npx prisma migrate deploy && npm run dev -- --host"]
# Stage 3: Builder for production
FROM base AS builder
WORKDIR /app
# Copy source files
COPY . .
# Build the application
RUN npm run build
# Prune dev dependencies (keeping Prisma client)
RUN npm prune --production
# Regenerate Prisma Client to ensure it's available
RUN npx prisma generate
# Stage 4: Production runner
FROM node:22-alpine AS production
# Install dumb-init to handle signals properly
RUN apk add --no-cache dumb-init
WORKDIR /app
# Copy built application
COPY --from=builder /app/build ./build
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
# Copy prisma for migrations
COPY --from=builder /app/prisma ./prisma
# Create non-root user
RUN addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001
# Set ownership
RUN chown -R nodejs:nodejs /app
USER nodejs
EXPOSE 3000
ENV NODE_ENV=production
# Health check for container orchestration
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
CMD node -e "require('http').get('http://localhost:3000/', (r) => process.exit(r.statusCode === 200 ? 0 : 1))"
# Use dumb-init to handle signals
ENTRYPOINT ["dumb-init", "--"]
# Run migrations and start the server
CMD ["sh", "-c", "npx prisma migrate deploy && node build"]