-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
69 lines (49 loc) · 2.03 KB
/
Dockerfile
File metadata and controls
69 lines (49 loc) · 2.03 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
# ==============================================================================
# Stage 1: Build
# ==============================================================================
FROM node:20-alpine AS builder
WORKDIR /app
# Install build dependencies for native modules
RUN apk add --no-cache python3 make g++
# Copy package files first for better layer caching
COPY package.json package-lock.json ./
# Install all dependencies (including dev deps for building)
RUN npm ci
# Copy source code
COPY . .
# Build the application (compiles server to dist/index.cjs and client to dist/public)
RUN npm run build
# Generate migrations from schema (shipped with the image)
RUN npx drizzle-kit generate || echo "Migration generation completed"
# ==============================================================================
# Stage 2: Production Runtime
# ==============================================================================
FROM node:20-alpine AS runtime
WORKDIR /app
# Install runtime utilities (wget for healthcheck, postgresql-client for pg_isready)
RUN apk add --no-cache wget postgresql-client
# Copy package files
COPY package.json package-lock.json ./
# Install production dependencies only
RUN npm ci --omit=dev && npm cache clean --force
# Copy built artifacts from builder stage
COPY --from=builder /app/dist ./dist
# Copy drizzle config, shared types, and migrations
COPY --from=builder /app/drizzle.config.ts ./drizzle.config.ts
COPY --from=builder /app/shared ./shared
COPY --from=builder /app/tsconfig.json ./tsconfig.json
COPY --from=builder /app/migrations ./migrations
# Create uploads directory for file storage
RUN mkdir -p /app/uploads && chown -R node:node /app/uploads
# Set environment variables
ENV NODE_ENV=production
ENV PORT=8080
# Use non-root user for security
USER node
# Expose the port
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/api/health || exit 1
# Run the application
CMD ["node", "dist/index.cjs"]