Ver código fonte

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 8 meses atrás
pai
commit
38582f44c8
2 arquivos alterados com 65 adições e 107 exclusões
  1. 65 88
      README.md
  2. 0 19
      ecosystem.config.js

+ 65 - 88
README.md

@@ -219,44 +219,29 @@ npx sequelize-cli db:migrate
 sudo -u postgres psql -d financial_data -c "\dt"
 ```
 
-### Step 6: Install PM2 (Process Manager)
+### Step 6: Deploy with Docker (Recommended)
 ```bash
-# Install PM2 globally
-sudo npm install -g pm2
-
-# Create PM2 ecosystem file
-cat > ecosystem.config.js << EOF
-module.exports = {
-  apps: [{
-    name: 'market-data-api',
-    script: 'src/server.js',
-    instances: 'max',
-    exec_mode: 'cluster',
-    env: {
-      NODE_ENV: 'production',
-      PORT: 3001
-    },
-    error_file: './logs/err.log',
-    out_file: './logs/out.log',
-    log_file: './logs/combined.log',
-    time: true,
-    merge_logs: true,
-    watch: false,
-    max_memory_restart: '1G'
-  }]
-};
-EOF
+# Navigate to project directory
+cd /root/market-data-service
 
-# Start with PM2
-pm2 start ecosystem.config.js
-pm2 save
-pm2 startup
+# Copy environment template
+cp .env.example .env
+
+# Edit .env file with production values
+nano .env
 
-# Verify PM2 status
-pm2 status
-pm2 logs
+# Build and start production containers
+docker-compose -f docker-compose.prod.yml up -d --build
+
+# Verify containers are running
+docker-compose -f docker-compose.prod.yml ps
+
+# View logs
+docker-compose -f docker-compose.prod.yml logs -f api
 ```
 
+For detailed Docker deployment instructions, see [DOCKER.md](./DOCKER.md).
+
 ### Step 7: Configure Nginx (WITHOUT SSL first)
 ```bash
 # Copy nginx configuration
@@ -466,28 +451,17 @@ curl -X POST http://localhost:3001/api/live-prices/bulk \
 # Navigate to project directory
 cd /root/market-data-service
 
-# Stop the application
-pm2 stop market-data-api
-
 # Backup current deployment (optional but recommended)
 cp .env .env.backup
-cp ecosystem.config.js ecosystem.config.js.backup
 
 # Pull latest changes
 git pull origin master
 
-# Install any new dependencies
-npm install --production
-
-# Run database migrations (if schema changed)
-npx sequelize-cli db:migrate
-
-# Restart application
-pm2 start ecosystem.config.js
-pm2 save
+# Rebuild and restart containers (migrations run automatically)
+docker-compose -f docker-compose.prod.yml up -d --build
 
 # Verify everything is working
-pm2 status
+docker-compose -f docker-compose.prod.yml ps
 curl https://your-domain.com/health
 ```
 
@@ -500,33 +474,21 @@ cd /root/market-data-service
 # Create backup
 sudo cp -r /root/market-data-service /root/market-data-service-backup-$(date +%Y%m%d_%H%M%S)
 
-# Stop services
-pm2 stop market-data-api
-sudo systemctl stop nginx
+# Stop containers
+docker-compose -f docker-compose.prod.yml down
 
 # Update code
 git fetch origin
 git reset --hard origin/master
 
-# Install dependencies
-npm install --production
-
 # Update environment if needed
 nano .env
 
-# Run migrations
-npx sequelize-cli db:migrate
-
-# Update PM2 configuration if needed
-pm2 start ecosystem.config.js
-pm2 save
-
-# Restart nginx
-sudo systemctl start nginx
+# Rebuild and start containers (migrations run automatically)
+docker-compose -f docker-compose.prod.yml up -d --build
 
 # Verify deployment
-pm2 status
-sudo systemctl status nginx
+docker-compose -f docker-compose.prod.yml ps
 curl https://your-domain.com/health
 ```
 
@@ -563,31 +525,31 @@ ls -la /etc/letsencrypt/live/your-domain.com/
 sudo nginx -t
 ```
 
-#### 3. PM2 Multiple Instances
-**Question:** Why are there 8 instances running?
+#### 3. Docker Container Issues
+**Problem:** Container won't start or keeps restarting
 
-**Answer:** This is **GOOD for production**:
-- Uses all CPU cores efficiently
-- Better load distribution
-- Fault tolerance
-- Zero-downtime restarts
-
-**To adjust instances:**
+**Solution:**
 ```bash
-pm2 scale market-data-api 4  # Use 4 instances
-pm2 scale market-data-api 1  # Use 1 instance for testing
+# Check container logs
+docker-compose -f docker-compose.prod.yml logs api
+
+# Check container status
+docker-compose -f docker-compose.prod.yml ps
+
+# Restart specific service
+docker-compose -f docker-compose.prod.yml restart api
 ```
 
 ## 📊 Monitoring & Maintenance
 
 ```bash
 # Check service status
-pm2 status
+docker-compose -f docker-compose.prod.yml ps
 sudo systemctl status nginx
-sudo systemctl status postgresql
 
 # View logs
-pm2 logs --lines 50
+docker-compose -f docker-compose.prod.yml logs -f api
+docker-compose -f docker-compose.prod.yml logs -f db
 sudo tail -f /var/log/nginx/access.log
 sudo tail -f /var/log/nginx/error.log
 
@@ -607,14 +569,26 @@ sudo certbot renew --dry-run
 
 ## 🔧 Management Commands
 
-### PM2 Management
+### Docker Management
 ```bash
-pm2 status              # Check status
-pm2 logs                # View logs
-pm2 monit               # Real-time monitoring
-pm2 restart all         # Restart all apps
-pm2 stop all            # Stop all apps
-pm2 delete all          # Delete all apps
+# Check container status
+docker-compose -f docker-compose.prod.yml ps
+
+# View logs
+docker-compose -f docker-compose.prod.yml logs -f api
+docker-compose -f docker-compose.prod.yml logs -f db
+
+# Restart services
+docker-compose -f docker-compose.prod.yml restart
+
+# Stop all services
+docker-compose -f docker-compose.prod.yml down
+
+# Start services
+docker-compose -f docker-compose.prod.yml up -d
+
+# Rebuild and restart
+docker-compose -f docker-compose.prod.yml up -d --build
 ```
 
 ### Nginx Management
@@ -733,6 +707,9 @@ npx sequelize-cli db:migrate:undo
 
 ## Deployment
 
-1. Set `NODE_ENV=production` in your environment
-2. Run `npm start` to start the production server
-3. Consider using a process manager like PM2 for production deployments
+The project is fully containerized using Docker. For deployment:
+
+1. **Development**: Use `docker-compose up -d`
+2. **Production**: Use `docker-compose -f docker-compose.prod.yml up -d`
+
+See [DOCKER.md](./DOCKER.md) for complete deployment instructions.

+ 0 - 19
ecosystem.config.js

@@ -1,19 +0,0 @@
-module.exports = {
-  apps: [{
-    name: 'market-data-api',
-    script: 'src/server.js',
-    instances: 'max',
-    exec_mode: 'cluster',
-    env: {
-      NODE_ENV: 'production',
-      PORT: 3001
-    },
-    error_file: './logs/err.log',
-    out_file: './logs/out.log',
-    log_file: './logs/combined.log',
-    time: true,
-    merge_logs: true,
-    watch: false,
-    max_memory_restart: '1G'
-  }]
-};