-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
79 lines (56 loc) · 1.9 KB
/
Dockerfile
File metadata and controls
79 lines (56 loc) · 1.9 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
# Stage 1: Build
FROM node:20-slim AS builder
WORKDIR /app
# Install OpenSSL to match the production environment *before* installing dependencies
RUN apt-get update && \
apt-get install -y openssl ca-certificates && \
rm -rf /var/lib/apt/lists/*
# Copy package files
COPY package*.json ./
COPY tsconfig.json ./
# Copy Prisma schema
COPY prisma ./prisma
# Install all dependencies (including devDependencies needed for build)
RUN npm ci
# Copy source code
COPY src ./src
# Build TypeScript (this will also run prisma generate via build script)
RUN npm run build
# Stage 2: Production
FROM node:20-slim
# Set working directory
WORKDIR /app
# Install OpenSSL and other required libraries for Prisma
RUN apt-get update && \
apt-get install -y openssl ca-certificates && \
rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN groupadd -r nodejs && \
useradd -r -g nodejs nodejs
# Copy package files
COPY package*.json ./
# Copy Prisma schema (needed for @prisma/client to work)
COPY prisma ./prisma
# Install production dependencies only, skipping postinstall scripts
RUN npm ci --only=production --ignore-scripts && \
npm cache clean --force
# Copy generated Prisma client from builder
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
COPY --from=builder /app/node_modules/@prisma ./node_modules/@prisma
# Copy built application from builder
COPY --from=builder /app/dist ./dist
# Copy public files (auth page, etc.)
COPY public ./public
# Copy Supabase migrations
COPY supabase ./supabase
# Change ownership to nodejs user
RUN chown -R nodejs:nodejs /app
# Switch to non-root user
USER nodejs
# Expose port
EXPOSE 3000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD node -e "require('http').get('http://localhost:3000/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
# Start the application
CMD ["node", "dist/index.js"]