206 lines
3.5 KiB
Markdown
206 lines
3.5 KiB
Markdown
# Deployment Guide - SDI SaaS Platform
|
|
|
|
## Prerequisites on Dev Server
|
|
|
|
The dev server (102.69.243.165) needs:
|
|
- Docker & Docker Compose
|
|
- Node.js 20+
|
|
- pnpm 8+
|
|
- Git (optional)
|
|
|
|
## Deployment Options
|
|
|
|
### Option 1: Automated Deployment Script (Recommended)
|
|
|
|
```bash
|
|
# Make script executable
|
|
chmod +x deploy-dev.sh
|
|
|
|
# Run deployment (will prompt for SSH password)
|
|
./deploy-dev.sh
|
|
```
|
|
|
|
The script will:
|
|
1. Create deployment package
|
|
2. Upload to server via SCP
|
|
3. Extract and install dependencies
|
|
4. Set up Docker containers
|
|
5. Run database migrations
|
|
6. Seed demo data
|
|
7. Start all services
|
|
|
|
### Option 2: Manual Deployment via Git
|
|
|
|
If Git authentication works:
|
|
|
|
```bash
|
|
# On dev server
|
|
ssh root@102.69.243.165
|
|
|
|
# Clone repository
|
|
cd /var/www
|
|
git clone https://git.votcloud.com/austindebest/sdi.git sdi-saas
|
|
cd sdi-saas
|
|
|
|
# Install dependencies
|
|
pnpm install
|
|
|
|
# Set up environment
|
|
cp apps/api/.env.example apps/api/.env
|
|
cp apps/worker/.env.example apps/worker/.env
|
|
cp packages/database/.env.example packages/database/.env
|
|
|
|
# Update DATABASE_URL in .env files to use 'postgres' instead of 'localhost'
|
|
|
|
# Generate Prisma client
|
|
cd packages/database
|
|
pnpm db:generate
|
|
|
|
# Start infrastructure
|
|
cd ../..
|
|
docker-compose up -d
|
|
|
|
# Wait for database
|
|
sleep 10
|
|
|
|
# Run migrations
|
|
cd packages/database
|
|
pnpm db:migrate
|
|
|
|
# Seed data
|
|
pnpm db:seed
|
|
|
|
# Services should now be running
|
|
```
|
|
|
|
### Option 3: Manual SCP Upload
|
|
|
|
```bash
|
|
# Create archive locally
|
|
tar -czf sdi-deploy.tar.gz \
|
|
--exclude='node_modules' \
|
|
--exclude='.git' \
|
|
--exclude='dist' \
|
|
.
|
|
|
|
# Upload to server
|
|
scp sdi-deploy.tar.gz root@102.69.243.165:/tmp/
|
|
|
|
# SSH to server and extract
|
|
ssh root@102.69.243.165
|
|
mkdir -p /var/www/sdi-saas
|
|
cd /var/www/sdi-saas
|
|
tar -xzf /tmp/sdi-deploy.tar.gz
|
|
|
|
# Follow manual deployment steps above
|
|
```
|
|
|
|
## Accessing the Application
|
|
|
|
Once deployed:
|
|
- **API**: http://102.69.243.165:3000
|
|
- **API Documentation**: http://102.69.243.165:3000/api/docs
|
|
- **Database Studio**: SSH tunnel required
|
|
|
|
## Managing Services
|
|
|
|
```bash
|
|
# SSH to server
|
|
ssh root@102.69.243.165
|
|
|
|
# View logs
|
|
cd /var/www/sdi-saas
|
|
docker-compose logs -f
|
|
|
|
# Restart services
|
|
docker-compose restart
|
|
|
|
# Stop services
|
|
docker-compose down
|
|
|
|
# Rebuild and restart
|
|
docker-compose up -d --build
|
|
```
|
|
|
|
## Troubleshooting
|
|
|
|
### Database Connection Issues
|
|
```bash
|
|
# Check if PostgreSQL is running
|
|
docker-compose ps
|
|
|
|
# Check database logs
|
|
docker-compose logs postgres
|
|
|
|
# Restart database
|
|
docker-compose restart postgres
|
|
```
|
|
|
|
### API Not Starting
|
|
```bash
|
|
# Check API logs
|
|
docker-compose logs api
|
|
|
|
# Check environment variables
|
|
cat apps/api/.env
|
|
|
|
# Rebuild API container
|
|
docker-compose up -d --build api
|
|
```
|
|
|
|
### Worker Not Processing Jobs
|
|
```bash
|
|
# Check worker logs
|
|
docker-compose logs worker
|
|
|
|
# Check Redis connection
|
|
docker-compose logs redis
|
|
|
|
# Restart worker
|
|
docker-compose restart worker
|
|
```
|
|
|
|
## Updating the Application
|
|
|
|
```bash
|
|
# SSH to server
|
|
ssh root@102.69.243.165
|
|
cd /var/www/sdi-saas
|
|
|
|
# Pull latest changes (if using Git)
|
|
git pull
|
|
|
|
# Or upload new archive and extract
|
|
|
|
# Reinstall dependencies
|
|
pnpm install
|
|
|
|
# Regenerate Prisma client
|
|
cd packages/database
|
|
pnpm db:generate
|
|
|
|
# Run new migrations
|
|
pnpm db:migrate
|
|
|
|
# Rebuild and restart
|
|
cd ../..
|
|
docker-compose up -d --build
|
|
```
|
|
|
|
## Security Notes
|
|
|
|
- Change default passwords in production
|
|
- Set up firewall rules (UFW)
|
|
- Use SSL/TLS certificates (Let's Encrypt)
|
|
- Implement proper authentication
|
|
- Set up monitoring and logging
|
|
- Regular backups of database
|
|
|
|
## Next Steps After Deployment
|
|
|
|
1. Verify API is accessible
|
|
2. Test API endpoints via Swagger docs
|
|
3. Check database has seed data
|
|
4. Monitor logs for errors
|
|
5. Begin Phase 1 development
|