Add deployment documentation and scripts

This commit is contained in:
austindebest
2026-04-20 00:03:32 +01:00
parent d62468adf9
commit 0665a66288
3 changed files with 451 additions and 0 deletions

205
DEPLOYMENT.md Normal file
View File

@@ -0,0 +1,205 @@
# 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

138
MANUAL_DEPLOYMENT.md Normal file
View File

@@ -0,0 +1,138 @@
# Manual Deployment Instructions
## Quick Deployment to Dev Server
Since Git authentication is having issues, here's the manual deployment process:
### Step 1: Create Deployment Package (On Your Local Machine)
```bash
# Create archive excluding unnecessary files
tar -czf sdi-deploy.tar.gz \
--exclude='node_modules' \
--exclude='.git' \
--exclude='dist' \
--exclude='*.log' \
.
```
### Step 2: Upload to Server
```bash
# Upload the archive
scp sdi-deploy.tar.gz root@102.69.243.165:/tmp/
```
Password: `clonii@@2014`
### Step 3: Deploy on Server
SSH into the server:
```bash
ssh root@102.69.243.165
```
Then run these commands:
```bash
# Create deployment directory
mkdir -p /var/www/sdi-saas
cd /var/www/sdi-saas
# Extract files
tar -xzf /tmp/sdi-deploy.tar.gz
# Install Node.js 20 (if not installed)
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt-get install -y nodejs
# Install pnpm
npm install -g pnpm@8.15.0
# Install dependencies
pnpm install
# Set up environment files
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 for Docker networking
sed -i 's/localhost/postgres/g' apps/api/.env
sed -i 's/localhost/postgres/g' apps/worker/.env
sed -i 's/localhost/postgres/g' packages/database/.env
# Generate Prisma client
cd packages/database
pnpm db:generate
# Start Docker services
cd /var/www/sdi-saas
docker-compose up -d
# Wait for database to be ready
sleep 15
# Run migrations
cd packages/database
pnpm db:migrate
# Seed demo data
pnpm db:seed
# Check services are running
cd /var/www/sdi-saas
docker-compose ps
```
### Step 4: Verify Deployment
Access the API:
- **API**: http://102.69.243.165:3000
- **API Docs**: http://102.69.243.165:3000/api/docs
Check logs:
```bash
docker-compose logs -f
```
## Alternative: Git Push (If Authentication Works)
If you can fix the Git authentication issue:
```bash
# On local machine
git remote set-url origin https://git.votcloud.com/austindebest/sdi.git
git push -u origin main
# Enter username: austindebest
# Enter password: VcG_3xwbEUyDcMqgKwTTLJP4KoEp!Q9
# On server
cd /var/www
git clone https://git.votcloud.com/austindebest/sdi.git sdi-saas
cd sdi-saas
# Follow deployment steps above
```
## For Future Updates
```bash
# Create new deployment package
tar -czf sdi-deploy.tar.gz --exclude='node_modules' --exclude='.git' --exclude='dist' .
# Upload
scp sdi-deploy.tar.gz root@102.69.243.165:/tmp/
# SSH and update
ssh root@102.69.243.165
cd /var/www/sdi-saas
tar -xzf /tmp/sdi-deploy.tar.gz
pnpm install
cd packages/database && pnpm db:generate
cd /var/www/sdi-saas
docker-compose up -d --build
```
---
**Ready to proceed with Phase 1 development once deployed!**

108
deploy-dev.sh Normal file
View File

@@ -0,0 +1,108 @@
#!/bin/bash
# SDI SaaS Platform - Deployment Script for Dev Server
# Server: 102.69.243.165
# User: root
set -e
echo "🚀 SDI SaaS Platform - Dev Server Deployment"
echo "=============================================="
# Configuration
SERVER_IP="102.69.243.165"
SERVER_USER="root"
DEPLOY_PATH="/var/www/sdi-saas"
APP_NAME="sdi-saas"
echo "📦 Step 1: Preparing deployment package..."
# Create deployment archive (excluding node_modules and .git)
tar -czf sdi-deploy.tar.gz \
--exclude='node_modules' \
--exclude='.git' \
--exclude='dist' \
--exclude='*.log' \
--exclude='.env' \
.
echo "✅ Deployment package created"
echo "📤 Step 2: Uploading to server..."
# Upload to server
scp sdi-deploy.tar.gz ${SERVER_USER}@${SERVER_IP}:/tmp/
echo "✅ Files uploaded"
echo "🔧 Step 3: Deploying on server..."
# SSH into server and deploy
ssh ${SERVER_USER}@${SERVER_IP} << 'ENDSSH'
set -e
echo "Creating deployment directory..."
mkdir -p /var/www/sdi-saas
cd /var/www/sdi-saas
echo "Extracting files..."
tar -xzf /tmp/sdi-deploy.tar.gz -C /var/www/sdi-saas
echo "Installing dependencies..."
# Install Node.js 20 if not present
if ! command -v node &> /dev/null; then
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt-get install -y nodejs
fi
# Install pnpm if not present
if ! command -v pnpm &> /dev/null; then
npm install -g pnpm@8.15.0
fi
# Install dependencies
pnpm install --frozen-lockfile
echo "Setting up environment..."
# Copy environment files
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 for production
sed -i 's/localhost/postgres/g' apps/api/.env
sed -i 's/localhost/postgres/g' apps/worker/.env
sed -i 's/localhost/postgres/g' packages/database/.env
echo "Generating Prisma client..."
cd packages/database
pnpm db:generate
echo "Starting services with Docker Compose..."
cd /var/www/sdi-saas
docker-compose up -d
echo "Waiting for database to be ready..."
sleep 10
echo "Running database migrations..."
cd packages/database
pnpm db:migrate
echo "Seeding database..."
pnpm db:seed
echo "✅ Deployment complete!"
echo "API: http://102.69.243.165:3000"
echo "API Docs: http://102.69.243.165:3000/api/docs"
ENDSSH
echo "🎉 Deployment successful!"
echo ""
echo "Access your application:"
echo " API: http://102.69.243.165:3000"
echo " API Docs: http://102.69.243.165:3000/api/docs"
echo ""
echo "To check logs:"
echo " ssh root@102.69.243.165 'cd /var/www/sdi-saas && docker-compose logs -f'"