-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeployment.html
More file actions
472 lines (390 loc) · 13.2 KB
/
deployment.html
File metadata and controls
472 lines (390 loc) · 13.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
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Deployment Guide - QueryForge</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>🚀 Deployment Guide</h1>
<p>Production Setup, Scaling, and Monitoring</p>
</header>
<nav class="breadcrumb">
<a href="index.html">Home</a> > Deployment Guide
</nav>
<div class="container">
<section class="doc-section">
<h2>Prerequisites</h2>
<h3>System Requirements</h3>
<ul>
<li><strong>Node.js:</strong> Version 18.x or higher</li>
<li><strong>Memory:</strong> Minimum 2GB RAM</li>
<li><strong>Storage:</strong> 500MB for application + logs</li>
<li><strong>Network:</strong> Access to database servers</li>
</ul>
<h3>Database Drivers</h3>
<ul>
<li><strong>PostgreSQL:</strong> pg (included)</li>
<li><strong>MySQL:</strong> mysql2 (included)</li>
<li><strong>Oracle:</strong> oracledb (requires Oracle Instant Client)</li>
</ul>
</section>
<section class="doc-section">
<h2>Installation Steps</h2>
<h3>1. Clone Repository</h3>
<div class="code-block">
git clone <repository-url>
cd dbclient
</div>
<h3>2. Install Dependencies</h3>
<div class="code-block">
npm install
</div>
<h3>3. Configure Environment</h3>
<p>Create <code>.env</code> file:</p>
<div class="code-block">
# Application Environment
APP_ENV=production
# Session Configuration
SESSION_SECRET=<generate-strong-random-secret>
SESSION_TIMEOUT=300000
SESSION_MAX_AGE=3600000
# Server Configuration
PORT=3000
</div>
<p>Create <code>.env.server</code> file:</p>
<div class="code-block">
# Server Binding
HOST=0.0.0.0
PORT=3000
</div>
<h3>4. Configure SAML</h3>
<p>Create <code>saml-config.json</code>:</p>
<div class="code-block">
{
"entryPoint": "https://your-idp.example.com/sso/saml",
"issuer": "database-client",
"callbackUrl": "https://your-app-domain.com/auth/saml/callback",
"cert": "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----"
}
</div>
<h3>5. Build Frontend</h3>
<div class="code-block">
npm run build
</div>
<h3>6. Start Server</h3>
<div class="code-block">
node server.js
</div>
</section>
<section class="doc-section">
<h2>Production Deployment</h2>
<h3>Using PM2 (Recommended)</h3>
<div class="code-block">
# Install PM2
npm install -g pm2
# Start application
pm2 start server.js --name dbclient
# Enable startup script
pm2 startup
pm2 save
# Monitor
pm2 monit
# View logs
pm2 logs dbclient
</div>
<h3>PM2 Ecosystem File</h3>
<p>Create <code>ecosystem.config.js</code>:</p>
<div class="code-block">
module.exports = {
apps: [{
name: 'dbclient',
script: 'server.js',
instances: 2,
exec_mode: 'cluster',
env: {
NODE_ENV: 'production',
PORT: 3000
},
error_file: './logs/pm2-error.log',
out_file: './logs/pm2-out.log',
log_date_format: 'YYYY-MM-DD HH:mm:ss Z',
max_memory_restart: '1G'
}]
};
</div>
<div class="code-block">
# Start with ecosystem file
pm2 start ecosystem.config.js
</div>
</section>
<section class="doc-section">
<h2>Reverse Proxy Setup</h2>
<h3>Nginx Configuration</h3>
<div class="code-block">
server {
listen 80;
server_name your-domain.com;
# Redirect to HTTPS
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
server_name your-domain.com;
ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;
# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
# Timeouts for long queries
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
}
}
</div>
</section>
<section class="doc-section">
<h2>Docker Deployment</h2>
<h3>Dockerfile</h3>
<div class="code-block">
FROM node:18-alpine
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install dependencies
RUN npm ci --only=production
# Copy application files
COPY . .
# Build frontend
RUN npm run build
# Create logs directory
RUN mkdir -p logs
# Expose port
EXPOSE 3000
# Start application
CMD ["node", "server.js"]
</div>
<h3>Docker Compose</h3>
<div class="code-block">
version: '3.8'
services:
dbclient:
build: .
ports:
- "3000:3000"
environment:
- NODE_ENV=production
- APP_ENV=production
env_file:
- .env
- .env.server
volumes:
- ./logs:/app/logs
- ./saml-config.json:/app/saml-config.json:ro
restart: unless-stopped
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:3000/health"]
interval: 30s
timeout: 10s
retries: 3
</div>
<h3>Build and Run</h3>
<div class="code-block">
# Build image
docker-compose build
# Start container
docker-compose up -d
# View logs
docker-compose logs -f
# Stop container
docker-compose down
</div>
</section>
<section class="doc-section">
<h2>Monitoring & Logging</h2>
<h3>Application Logs</h3>
<ul>
<li><strong>Activity Log:</strong> <code>logs/activity-YYYY-MM-DD.log</code></li>
<li><strong>Security Log:</strong> <code>logs/security-YYYY-MM-DD.log</code></li>
<li><strong>Error Log:</strong> <code>logs/error-YYYY-MM-DD.log</code></li>
</ul>
<h3>Log Rotation</h3>
<p>Logs automatically rotate daily. Configure retention in <code>server.js</code>:</p>
<div class="code-block">
maxFiles: '30d' // Keep logs for 30 days
</div>
<h3>Health Check Endpoint</h3>
<div class="code-block">
GET /health
Response:
{
"status": "ok",
"timestamp": "2026-02-19T11:22:00.000Z"
}
</div>
<h3>Monitoring Metrics</h3>
<ul>
<li>Active sessions count</li>
<li>Query execution times</li>
<li>Error rates</li>
<li>Memory usage</li>
<li>CPU usage</li>
</ul>
</section>
<section class="doc-section">
<h2>Security Hardening</h2>
<h3>Environment Variables</h3>
<div class="warning-box">
<strong>⚠️ Critical:</strong>
<ul>
<li>Never commit <code>.env</code> files to version control</li>
<li>Use strong random SESSION_SECRET (32+ characters)</li>
<li>Rotate SESSION_SECRET periodically</li>
<li>Restrict file permissions: <code>chmod 600 .env*</code></li>
</ul>
</div>
<h3>HTTPS Only</h3>
<ul>
<li>Always use HTTPS in production</li>
<li>Use valid SSL certificates (Let's Encrypt recommended)</li>
<li>Enable HSTS headers</li>
<li>Disable HTTP access</li>
</ul>
<h3>Firewall Rules</h3>
<ul>
<li>Allow only necessary ports (443 for HTTPS)</li>
<li>Restrict database access to application server only</li>
<li>Use security groups/network ACLs</li>
<li>Enable fail2ban for brute force protection</li>
</ul>
</section>
<section class="doc-section">
<h2>Backup & Recovery</h2>
<h3>What to Backup</h3>
<ul>
<li><strong>Configuration:</strong> <code>.env</code>, <code>.env.server</code>, <code>saml-config.json</code></li>
<li><strong>Logs:</strong> <code>logs/</code> directory (for compliance)</li>
<li><strong>Application:</strong> Entire codebase</li>
</ul>
<h3>Backup Script</h3>
<div class="code-block">
#!/bin/bash
DATE=$(date +%Y%m%d)
BACKUP_DIR="/backups/dbclient"
# Create backup directory
mkdir -p $BACKUP_DIR
# Backup logs
tar -czf $BACKUP_DIR/logs-$DATE.tar.gz logs/
# Backup configuration (encrypted)
tar -czf - .env* saml-config.json | \
openssl enc -aes-256-cbc -salt -out $BACKUP_DIR/config-$DATE.tar.gz.enc
# Keep only last 30 days
find $BACKUP_DIR -name "*.tar.gz*" -mtime +30 -delete
</div>
</section>
<section class="doc-section">
<h2>Scaling Considerations</h2>
<h3>Horizontal Scaling</h3>
<ul>
<li>Use PM2 cluster mode for multiple instances</li>
<li>Deploy behind load balancer (ALB, Nginx)</li>
<li>Enable sticky sessions for session persistence</li>
<li>Consider Redis for shared session storage</li>
</ul>
<h3>Performance Tuning</h3>
<ul>
<li>Adjust <code>max_memory_restart</code> in PM2</li>
<li>Configure database connection pooling</li>
<li>Enable gzip compression in Nginx</li>
<li>Use CDN for static assets</li>
</ul>
<h3>Database Connections</h3>
<ul>
<li>Each user session = 1 database connection</li>
<li>Plan database connection limits accordingly</li>
<li>Monitor connection pool usage</li>
<li>Set appropriate timeouts</li>
</ul>
</section>
<section class="doc-section">
<h2>Troubleshooting</h2>
<h3>Common Issues</h3>
<div class="issue-box">
<h4>Application won't start</h4>
<ul>
<li>Check <code>.env</code> files exist and are readable</li>
<li>Verify <code>saml-config.json</code> is valid JSON</li>
<li>Ensure port 3000 is not in use</li>
<li>Check Node.js version (18+)</li>
</ul>
</div>
<div class="issue-box">
<h4>SAML authentication fails</h4>
<ul>
<li>Verify <code>callbackUrl</code> matches IdP configuration</li>
<li>Check certificate is correct and not expired</li>
<li>Ensure HTTPS is enabled</li>
<li>Review security logs</li>
</ul>
</div>
<div class="issue-box">
<h4>Database connection fails</h4>
<ul>
<li>Verify network connectivity to database</li>
<li>Check firewall rules</li>
<li>Confirm credentials are correct</li>
<li>Ensure database driver is installed</li>
</ul>
</div>
<h3>Debug Mode</h3>
<div class="code-block">
# Enable debug logging
DEBUG=* node server.js
# Or with PM2
pm2 start server.js --name dbclient --log-date-format 'YYYY-MM-DD HH:mm:ss Z'
</div>
</section>
<section class="doc-section">
<h2>Maintenance</h2>
<h3>Regular Tasks</h3>
<ul>
<li><strong>Daily:</strong> Monitor logs for errors</li>
<li><strong>Weekly:</strong> Review security logs, check disk space</li>
<li><strong>Monthly:</strong> Update dependencies, rotate secrets</li>
<li><strong>Quarterly:</strong> Security audit, performance review</li>
</ul>
<h3>Update Procedure</h3>
<div class="code-block">
# Backup current version
tar -czf dbclient-backup-$(date +%Y%m%d).tar.gz .
# Pull latest code
git pull
# Install dependencies
npm install
# Rebuild frontend
npm run build
# Restart application
pm2 restart dbclient
</div>
</section>
</div>
<footer>
<p>© 2026 QueryForge Contributors | <a href="index.html">Back to Documentation Home</a></p>
</footer>
</body>
</html>