-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeployment-config.txt
More file actions
247 lines (223 loc) · 5.41 KB
/
deployment-config.txt
File metadata and controls
247 lines (223 loc) · 5.41 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# docker-compose.yml - For local development
# This is like setting up your chess board for practice
version: '3.8'
services:
# Main application - The King piece (most important)
app:
build:
context: .
dockerfile: Dockerfile
ports:
- "3000:3000"
environment:
- NODE_ENV=development
- DATABASE_URL=postgresql://chess:password@postgres:5432/chess_learning
- REDIS_URL=redis://redis:6379
- JWT_SECRET=your-secret-key-here
depends_on:
- postgres
- redis
volumes:
- ./src:/app/src # Hot reload for development
- ./prisma:/app/prisma
# PostgreSQL database - The Queen (powerful and versatile)
postgres:
image: postgres:15-alpine
environment:
- POSTGRES_USER=chess
- POSTGRES_PASSWORD=password
- POSTGRES_DB=chess_learning
volumes:
- postgres_data:/var/lib/postgresql/data
ports:
- "5432:5432"
# Redis for caching and WebSocket scaling - The Knights (quick and agile)
redis:
image: redis:7-alpine
command: redis-server --appendonly yes
volumes:
- redis_data:/data
ports:
- "6379:6379"
# Stockfish service - The Bishops (deep analysis)
stockfish:
build:
context: ./stockfish
dockerfile: Dockerfile
deploy:
replicas: 4 # Multiple engines for parallel analysis
environment:
- STOCKFISH_THREADS=2
- STOCKFISH_HASH=256
volumes:
postgres_data:
redis_data:
# Dockerfile - Building our application container
FROM node:18-alpine AS builder
# Install dependencies for native modules
RUN apk add --no-cache python3 make g++
WORKDIR /app
# Copy package files
COPY package*.json ./
COPY prisma ./prisma/
# Install dependencies
RUN npm ci
# Generate Prisma client
RUN npx prisma generate
# Copy source code
COPY . .
# Build the application
RUN npm run build
# Production stage
FROM node:18-alpine
# Install Stockfish (for local analysis option)
RUN apk add --no-cache stockfish
WORKDIR /app
# Copy built application
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/package*.json ./
# Expose port
EXPOSE 3000
# Health check - Ensuring our King is safe
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
CMD node healthcheck.js
# Start the application
CMD ["npm", "run", "start:prod"]
# kubernetes/deployment.yaml - For production scaling
# This is like organizing a chess tournament with multiple boards
apiVersion: apps/v1
kind: Deployment
metadata:
name: chess-learning-api
labels:
app: chess-learning
spec:
replicas: 3 # Start with 3 instances
selector:
matchLabels:
app: chess-learning-api
template:
metadata:
labels:
app: chess-learning-api
spec:
containers:
- name: api
image: your-registry/chess-learning:latest
ports:
- containerPort: 3000
env:
- name: NODE_ENV
value: "production"
- name: DATABASE_URL
valueFrom:
secretKeyRef:
name: chess-secrets
key: database-url
- name: REDIS_URL
valueFrom:
secretKeyRef:
name: chess-secrets
key: redis-url
resources:
requests:
memory: "512Mi"
cpu: "500m"
limits:
memory: "1Gi"
cpu: "1000m"
livenessProbe:
httpGet:
path: /health
port: 3000
initialDelaySeconds: 30
periodSeconds: 10
readinessProbe:
httpGet:
path: /ready
port: 3000
initialDelaySeconds: 5
periodSeconds: 5
---
# Horizontal Pod Autoscaler - Scales based on load
# Like adding more chess boards when more players arrive
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: chess-learning-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: chess-learning-api
minReplicas: 3
maxReplicas: 20
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 80
behavior:
scaleUp:
stabilizationWindowSeconds: 60
policies:
- type: Percent
value: 100 # Double pods
periodSeconds: 60
scaleDown:
stabilizationWindowSeconds: 300 # Wait 5 minutes before scaling down
policies:
- type: Percent
value: 50 # Remove half
periodSeconds: 60
---
# Service - Load balancer for our API
apiVersion: v1
kind: Service
metadata:
name: chess-learning-service
spec:
type: LoadBalancer
selector:
app: chess-learning-api
ports:
- port: 80
targetPort: 3000
sessionAffinity: ClientIP # Important for WebSocket connections
---
# Redis deployment for caching and WebSocket scaling
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis
spec:
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
containers:
- name: redis
image: redis:7-alpine
ports:
- containerPort: 6379
resources:
requests:
memory: "256Mi"
cpu: "250m"
limits:
memory: "512Mi"
cpu: "500m"