Przeglądaj źródła

refactor: Remove PM2 deployment references in favor of Docker

Remove all PM2 process manager references and replace with Docker-based
deployment instructions throughout the project.

Changes:
- Delete ecosystem.config.js (PM2 configuration file)
- Replace PM2 installation step with Docker deployment step in README
- Update deployment update procedures to use Docker Compose
- Replace PM2 troubleshooting section with Docker container troubleshooting
- Replace PM2 management commands with Docker management commands
- Update deployment section to reference Docker exclusively

The project now uses Docker containers exclusively for both development
and production deployment, providing a consistent and containerized
deployment strategy.
Hussain Afzal 3 miesięcy temu
rodzic
commit
38582f44c8
2 zmienionych plików z 65 dodań i 107 usunięć
  1. 65 88
      README.md
  2. 0 19
      ecosystem.config.js

+ 65 - 88
README.md

@@ -219,44 +219,29 @@ npx sequelize-cli db:migrate
219 219
 sudo -u postgres psql -d financial_data -c "\dt"
220 220
 ```
221 221
 
222
-### Step 6: Install PM2 (Process Manager)
222
+### Step 6: Deploy with Docker (Recommended)
223 223
 ```bash
224
-# Install PM2 globally
225
-sudo npm install -g pm2
226
-
227
-# Create PM2 ecosystem file
228
-cat > ecosystem.config.js << EOF
229
-module.exports = {
230
-  apps: [{
231
-    name: 'market-data-api',
232
-    script: 'src/server.js',
233
-    instances: 'max',
234
-    exec_mode: 'cluster',
235
-    env: {
236
-      NODE_ENV: 'production',
237
-      PORT: 3001
238
-    },
239
-    error_file: './logs/err.log',
240
-    out_file: './logs/out.log',
241
-    log_file: './logs/combined.log',
242
-    time: true,
243
-    merge_logs: true,
244
-    watch: false,
245
-    max_memory_restart: '1G'
246
-  }]
247
-};
248
-EOF
224
+# Navigate to project directory
225
+cd /root/market-data-service
249 226
 
250
-# Start with PM2
251
-pm2 start ecosystem.config.js
252
-pm2 save
253
-pm2 startup
227
+# Copy environment template
228
+cp .env.example .env
229
+
230
+# Edit .env file with production values
231
+nano .env
254 232
 
255
-# Verify PM2 status
256
-pm2 status
257
-pm2 logs
233
+# Build and start production containers
234
+docker-compose -f docker-compose.prod.yml up -d --build
235
+
236
+# Verify containers are running
237
+docker-compose -f docker-compose.prod.yml ps
238
+
239
+# View logs
240
+docker-compose -f docker-compose.prod.yml logs -f api
258 241
 ```
259 242
 
243
+For detailed Docker deployment instructions, see [DOCKER.md](./DOCKER.md).
244
+
260 245
 ### Step 7: Configure Nginx (WITHOUT SSL first)
261 246
 ```bash
262 247
 # Copy nginx configuration
@@ -466,28 +451,17 @@ curl -X POST http://localhost:3001/api/live-prices/bulk \
466 451
 # Navigate to project directory
467 452
 cd /root/market-data-service
468 453
 
469
-# Stop the application
470
-pm2 stop market-data-api
471
-
472 454
 # Backup current deployment (optional but recommended)
473 455
 cp .env .env.backup
474
-cp ecosystem.config.js ecosystem.config.js.backup
475 456
 
476 457
 # Pull latest changes
477 458
 git pull origin master
478 459
 
479
-# Install any new dependencies
480
-npm install --production
481
-
482
-# Run database migrations (if schema changed)
483
-npx sequelize-cli db:migrate
484
-
485
-# Restart application
486
-pm2 start ecosystem.config.js
487
-pm2 save
460
+# Rebuild and restart containers (migrations run automatically)
461
+docker-compose -f docker-compose.prod.yml up -d --build
488 462
 
489 463
 # Verify everything is working
490
-pm2 status
464
+docker-compose -f docker-compose.prod.yml ps
491 465
 curl https://your-domain.com/health
492 466
 ```
493 467
 
@@ -500,33 +474,21 @@ cd /root/market-data-service
500 474
 # Create backup
501 475
 sudo cp -r /root/market-data-service /root/market-data-service-backup-$(date +%Y%m%d_%H%M%S)
502 476
 
503
-# Stop services
504
-pm2 stop market-data-api
505
-sudo systemctl stop nginx
477
+# Stop containers
478
+docker-compose -f docker-compose.prod.yml down
506 479
 
507 480
 # Update code
508 481
 git fetch origin
509 482
 git reset --hard origin/master
510 483
 
511
-# Install dependencies
512
-npm install --production
513
-
514 484
 # Update environment if needed
515 485
 nano .env
516 486
 
517
-# Run migrations
518
-npx sequelize-cli db:migrate
519
-
520
-# Update PM2 configuration if needed
521
-pm2 start ecosystem.config.js
522
-pm2 save
523
-
524
-# Restart nginx
525
-sudo systemctl start nginx
487
+# Rebuild and start containers (migrations run automatically)
488
+docker-compose -f docker-compose.prod.yml up -d --build
526 489
 
527 490
 # Verify deployment
528
-pm2 status
529
-sudo systemctl status nginx
491
+docker-compose -f docker-compose.prod.yml ps
530 492
 curl https://your-domain.com/health
531 493
 ```
532 494
 
@@ -563,31 +525,31 @@ ls -la /etc/letsencrypt/live/your-domain.com/
563 525
 sudo nginx -t
564 526
 ```
565 527
 
566
-#### 3. PM2 Multiple Instances
567
-**Question:** Why are there 8 instances running?
528
+#### 3. Docker Container Issues
529
+**Problem:** Container won't start or keeps restarting
568 530
 
569
-**Answer:** This is **GOOD for production**:
570
-- Uses all CPU cores efficiently
571
-- Better load distribution
572
-- Fault tolerance
573
-- Zero-downtime restarts
574
-
575
-**To adjust instances:**
531
+**Solution:**
576 532
 ```bash
577
-pm2 scale market-data-api 4  # Use 4 instances
578
-pm2 scale market-data-api 1  # Use 1 instance for testing
533
+# Check container logs
534
+docker-compose -f docker-compose.prod.yml logs api
535
+
536
+# Check container status
537
+docker-compose -f docker-compose.prod.yml ps
538
+
539
+# Restart specific service
540
+docker-compose -f docker-compose.prod.yml restart api
579 541
 ```
580 542
 
581 543
 ## 📊 Monitoring & Maintenance
582 544
 
583 545
 ```bash
584 546
 # Check service status
585
-pm2 status
547
+docker-compose -f docker-compose.prod.yml ps
586 548
 sudo systemctl status nginx
587
-sudo systemctl status postgresql
588 549
 
589 550
 # View logs
590
-pm2 logs --lines 50
551
+docker-compose -f docker-compose.prod.yml logs -f api
552
+docker-compose -f docker-compose.prod.yml logs -f db
591 553
 sudo tail -f /var/log/nginx/access.log
592 554
 sudo tail -f /var/log/nginx/error.log
593 555
 
@@ -607,14 +569,26 @@ sudo certbot renew --dry-run
607 569
 
608 570
 ## 🔧 Management Commands
609 571
 
610
-### PM2 Management
572
+### Docker Management
611 573
 ```bash
612
-pm2 status              # Check status
613
-pm2 logs                # View logs
614
-pm2 monit               # Real-time monitoring
615
-pm2 restart all         # Restart all apps
616
-pm2 stop all            # Stop all apps
617
-pm2 delete all          # Delete all apps
574
+# Check container status
575
+docker-compose -f docker-compose.prod.yml ps
576
+
577
+# View logs
578
+docker-compose -f docker-compose.prod.yml logs -f api
579
+docker-compose -f docker-compose.prod.yml logs -f db
580
+
581
+# Restart services
582
+docker-compose -f docker-compose.prod.yml restart
583
+
584
+# Stop all services
585
+docker-compose -f docker-compose.prod.yml down
586
+
587
+# Start services
588
+docker-compose -f docker-compose.prod.yml up -d
589
+
590
+# Rebuild and restart
591
+docker-compose -f docker-compose.prod.yml up -d --build
618 592
 ```
619 593
 
620 594
 ### Nginx Management
@@ -733,6 +707,9 @@ npx sequelize-cli db:migrate:undo
733 707
 
734 708
 ## Deployment
735 709
 
736
-1. Set `NODE_ENV=production` in your environment
737
-2. Run `npm start` to start the production server
738
-3. Consider using a process manager like PM2 for production deployments
710
+The project is fully containerized using Docker. For deployment:
711
+
712
+1. **Development**: Use `docker-compose up -d`
713
+2. **Production**: Use `docker-compose -f docker-compose.prod.yml up -d`
714
+
715
+See [DOCKER.md](./DOCKER.md) for complete deployment instructions.

+ 0 - 19
ecosystem.config.js

@@ -1,19 +0,0 @@
1
-module.exports = {
2
-  apps: [{
3
-    name: 'market-data-api',
4
-    script: 'src/server.js',
5
-    instances: 'max',
6
-    exec_mode: 'cluster',
7
-    env: {
8
-      NODE_ENV: 'production',
9
-      PORT: 3001
10
-    },
11
-    error_file: './logs/err.log',
12
-    out_file: './logs/out.log',
13
-    log_file: './logs/combined.log',
14
-    time: true,
15
-    merge_logs: true,
16
-    watch: false,
17
-    max_memory_restart: '1G'
18
-  }]
19
-};