-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
83 lines (59 loc) · 2 KB
/
Dockerfile
File metadata and controls
83 lines (59 loc) · 2 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
# Multi-stage Dockerfile for LocalStore API
# Supports development and production builds
# ============================================
# Base stage - common dependencies
# ============================================
FROM node:22-alpine AS base
# Install pnpm
RUN corepack enable && corepack prepare pnpm@latest --activate
WORKDIR /app
# Copy package files
COPY package.json pnpm-lock.yaml ./
# ============================================
# Development stage
# ============================================
FROM base AS development
# Install all dependencies (including devDependencies)
RUN pnpm install --frozen-lockfile
# Copy source code
COPY . .
# Expose port
EXPOSE 8080
# Start development server
CMD ["pnpm", "run", "start:dev"]
# ============================================
# Build stage - compile TypeScript
# ============================================
FROM base AS build
# Install all dependencies for building
RUN pnpm install --frozen-lockfile
# Copy source code
COPY . .
# Build the application
RUN pnpm run build
# Build migrations (compile TS migrations to JS for production)
RUN pnpm run migration:build
# Prune devDependencies
RUN pnpm prune --prod
# ============================================
# Production stage - minimal runtime image
# ============================================
FROM node:22-alpine AS production
# Install pnpm for running
RUN corepack enable && corepack prepare pnpm@latest --activate
WORKDIR /app
# Copy built application, compiled migrations, and production dependencies
COPY --from=build /app/dist ./dist
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/package.json ./
# Create non-root user for security
RUN addgroup -g 1001 -S nodejs && \
adduser -S nestjs -u 1001 -G nodejs
USER nestjs
# Expose port
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/api/v1/health || exit 1
# Start production server
CMD ["node", "dist/main.js"]