Manual Deployment Guide
Panduan Deployment Manual 3 Services
Dokumen ini menjelaskan langkah-langkah deployment manual untuk 3 microservices (users, products, orders) pada monolith server. Setiap langkah akan diukur waktunya untuk perbandingan dengan CI/CD deployment.
Overview Deployment Process
Aplikasi yang Di-Deploy
| Service | Port | Fungsi | Dependencies |
|---|---|---|---|
| users-service | 3001 | User management | express, sqlite3 |
| products-service | 3002 | Product catalog | express, sqlite3 |
| orders-service | 3003 | Order processing | express, axios |
Total Time Target
Manual deployment 3 services: 3-5 menit
Deployment Flow
Start Timer ⏱️
↓
1. SSH to Server (10-15 sec)
↓
2. Navigate to App Directory (5 sec)
↓
3. Git Pull (15-30 sec)
↓
4. Deploy Service 1: users-service (60-90 sec)
↓
5. Deploy Service 2: products-service (60-90 sec)
↓
6. Deploy Service 3: orders-service (60-90 sec)
↓
7. Verify All Services (30-45 sec)
↓
Stop Timer ⏱️
Total: 3-5 minutes
Prerequisites
Sebelum mulai deployment, pastikan:
- ✅ SSH access ke server
- ✅ Git repository accessible
- ✅ PM2 installed dan configured
- ✅ Node.js v18.x installed
- ✅ Application code sudah di-push ke Git
Step 1: Login ke Server
⏱️ Estimated Time: 10-15 seconds
# Login via SSH
ssh user@your-server-ip
# Atau dengan SSH key
ssh -i ~/.ssh/your-key.pem user@your-server-ip
Time Checkpoint: ___ seconds
Step 2: Navigate to Application Directory
⏱️ Estimated Time: 5 seconds
# Masuk ke direktori aplikasi
cd /var/www/apps/microservices-app
# Verify current location
pwd
Output yang diharapkan:
/var/www/apps/microservices-app
Time Checkpoint: ___ seconds
Step 3: Pull Latest Code from Git
⏱️ Estimated Time: 15-30 seconds
# Pull latest code
git pull origin main
Output yang diharapkan:
Updating a1b2c3d..e4f5g6h
Fast-forward
users-service/src/index.js | 5 +++--
products-service/src/index.js | 3 ++-
orders-service/src/index.js | 7 ++++---
3 files changed, 9 insertions(+), 6 deletions(-)
Time Checkpoint: ___ seconds
⚠️ Possible Issues:
- Merge conflicts → Harus resolve manual
- Network issues → Retry atau check connection
- Authentication failed → Check Git credentials
Step 4: Deploy users-service
⏱️ Estimated Time: 60-90 seconds
4.1 Navigate to Service Directory
cd users-service
4.2 Install/Update Dependencies
npm install --production
Output:
added 52 packages in 30s
4.3 Restart Service with PM2
# Restart the service (DOWNTIME starts here ⚠️)
pm2 restart users-service
# Or if first time:
# pm2 start npm --name "users-service" -- start
Output:
[PM2] Applying action restartProcessId on app [users-service](ids: [ 0 ])
[PM2] [users-service](0) ✓
⚠️ DOWNTIME: ~10-20 seconds during restart
4.4 Verify Service Running
# Check PM2 status
pm2 status users-service
# Check logs
pm2 logs users-service --lines 20 --nostream
Expected Status: online
4.5 Test Health Endpoint
curl http://localhost:3001/health
Expected Response:
{
"status": "ok",
"service": "users-service",
"timestamp": "2024-01-15T10:30:45.123Z"
}
4.6 Go Back to Root Directory
cd ..
Time Checkpoint for users-service: ___ seconds
Step 5: Deploy products-service
⏱️ Estimated Time: 60-90 seconds
5.1 Navigate to Service Directory
cd products-service
5.2 Install/Update Dependencies
npm install --production
5.3 Restart Service
pm2 restart products-service
⚠️ DOWNTIME: ~10-20 seconds
5.4 Verify Service
pm2 status products-service
curl http://localhost:3002/health
Expected Response:
{
"status": "ok",
"service": "products-service",
"timestamp": "2024-01-15T10:32:15.456Z"
}
5.5 Go Back
cd ..
Time Checkpoint for products-service: ___ seconds
Step 6: Deploy orders-service
⏱️ Estimated Time: 60-90 seconds
6.1 Navigate to Service Directory
cd orders-service
6.2 Install/Update Dependencies
npm install --production
6.3 Restart Service
pm2 restart orders-service
⚠️ DOWNTIME: ~10-20 seconds
6.4 Verify Service
pm2 status orders-service
curl http://localhost:3003/health
Expected Response:
{
"status": "ok",
"service": "orders-service",
"timestamp": "2024-01-15T10:33:45.789Z"
}
6.5 Go Back
cd ..
Time Checkpoint for orders-service: ___ seconds
Step 7: Final Verification
⏱️ Estimated Time: 30-45 seconds
7.1 Check All Services Status
pm2 status
Expected Output:
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name │ mode │ ↺ │ status │ cpu │ memory │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0 │ users-service │ fork │ 15 │ online │ 0% │ 45.2mb │
│ 1 │ products-service │ fork │ 12 │ online │ 0% │ 42.8mb │
│ 2 │ orders-service │ fork │ 10 │ online │ 0% │ 48.1mb │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
✅ All services should show status: online
7.2 Test All Health Endpoints
# Quick test script
for port in 3001 3002 3003; do
echo "Testing port $port..."
curl -s http://localhost:$port/health | jq '.'
done
7.3 Test Inter-Service Communication (Optional)
# Test creating an order (requires all 3 services)
curl -X POST http://localhost:3003/api/orders \
-H "Content-Type: application/json" \
-d '{
"userId": 1,
"productId": 10,
"quantity": 2
}'
Time Checkpoint for verification: ___ seconds
Total Deployment Time Summary
| Step | Estimated Time | Actual Time |
|---|---|---|
| 1. SSH Login | 10-15 sec | ___ sec |
| 2. Navigate Directory | 5 sec | ___ sec |
| 3. Git Pull | 15-30 sec | ___ sec |
| 4. Deploy users-service | 60-90 sec | ___ sec |
| 5. Deploy products-service | 60-90 sec | ___ sec |
| 6. Deploy orders-service | 60-90 sec | ___ sec |
| 7. Final Verification | 30-45 sec | ___ sec |
| TOTAL | 3-5 minutes | ___ minutes |
Total Downtime: ~30-60 seconds (semua service restart)
Metrics Collected
Manual Intervention Count
Total manual commands yang harus dijalankan:
- SSH login: 1 command
- Navigate: 1 command
- Git pull: 1 command
- users-service: 4 commands (cd, npm install, pm2 restart, verify)
- products-service: 4 commands
- orders-service: 4 commands
- Verification: 2 commands
Total: ~17-21 manual commands
Human Error Points
Potential errors yang bisa terjadi:
- ❌ Typo saat mengetik command
- ❌ Lupa menjalankan npm install
- ❌ Restart service yang salah
- ❌ Lupa verify deployment
- ❌ Network timeout saat git pull
- ❌ Dependency conflict saat npm install
Error Probability: 5-10%
Troubleshooting
Issue 1: Git Pull Failed
Error:
error: Your local changes to the following files would be overwritten by merge
Solution:
# Stash local changes
git stash
# Pull again
git pull origin main
# If needed, apply stash
git stash pop
Issue 2: npm install Failed
Error:
npm ERR! network timeout
Solution:
# Clear npm cache
npm cache clean --force
# Retry
npm install --production
Issue 3: PM2 Service Won't Start
Error:
[PM2][ERROR] Process failed to start
Solution:
# Check logs
pm2 logs users-service --err --lines 50
# Common fixes:
# 1. Port already in use
sudo lsof -i :3001
sudo kill -9 <PID>
# 2. Missing environment variables
pm2 delete users-service
cd users-service
pm2 start npm --name "users-service" -- start
# 3. Dependency issue
rm -rf node_modules package-lock.json
npm install --production
pm2 restart users-service
Issue 4: Health Check Failed
Error:
curl: (7) Failed to connect to localhost port 3001: Connection refused
Solution:
# Check if service is running
pm2 status users-service
# Check logs for startup errors
pm2 logs users-service --lines 100
# Restart if needed
pm2 restart users-service
# Wait 5-10 seconds for service to start
sleep 10
curl http://localhost:3001/health
Rollback Procedure
Jika deployment gagal dan perlu rollback:
Quick Rollback
# 1. Go to application directory
cd /var/www/apps/microservices-app
# 2. Revert to previous commit
git log --oneline -5 # Check recent commits
git revert HEAD # Revert last commit
# 3. Redeploy all services (repeat deployment steps)
cd users-service && npm install && pm2 restart users-service && cd ..
cd products-service && npm install && pm2 restart products-service && cd ..
cd orders-service && npm install && pm2 restart orders-service && cd ..
# 4. Verify
pm2 status
Rollback Time: Additional 3-5 minutes
Best Practices
✅ Pre-Deployment Checklist
- Backup database (if applicable)
- Inform team about deployment
- Test in staging environment first
- Have rollback plan ready
- Schedule deployment during low traffic
✅ During Deployment
- Follow steps sequentially
- Don't skip verification steps
- Document any issues encountered
- Keep terminal history for audit
✅ Post-Deployment
- Monitor logs for 5-10 minutes
- Check error rates
- Verify all features working
- Update deployment log
Deployment Log Template
===========================================
Deployment Log - Manual Deployment
===========================================
Date: YYYY-MM-DD
Time: HH:MM:SS
Deployed by: [Your Name]
Git Commit: [commit hash]
Services Deployed:
- users-service: ✅ Success
- products-service: ✅ Success
- orders-service: ✅ Success
Total Time: ___ minutes
Downtime: ___ seconds
Issues Encountered: None / [Description]
Rollback Performed: No / Yes
Notes:
[Any additional notes]
===========================================
Comparison with CI/CD
| Metric | Manual Deployment | CI/CD (Expected) |
|---|---|---|
| Trigger | Manual SSH | Git push |
| Total Time | 3-5 minutes | <1 minute |
| Manual Steps | 17-21 commands | 1 command |
| Downtime | 30-60 seconds | 0 seconds |
| Error Prone | High (human) | Low (automated) |
| Consistency | Low | High |
| Rollback | Manual (3-5 min) | Automatic (<1 min) |
Conclusion
Manual deployment untuk 3 microservices membutuhkan:
- ⏱️ Time: 3-5 menit per deployment
- 👤 Manual effort: 17-21 commands
- ⏰ Downtime: 30-60 detik total
- ❌ Risk: Human error 5-10%
Hasil pengujian aktual akan didokumentasikan di Test Results untuk dibandingkan dengan CI/CD deployment.
Next Steps
Setelah memahami manual deployment, lihat perbandingan dengan CI/CD:
👉 CI/CD Flow - Automated deployment dengan Gitea Runner 👉 Test Results - Hasil perbandingan deployment time