Spaces:
Sleeping
Sleeping
File size: 7,539 Bytes
4343907 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
# SAAP Deployment Guide
## π Overview
This guide covers deploying SAAP (satware Autonomous Agent Platform) from development to production using Docker and GitHub Actions.
## π Deployment Strategies
### 1. Local Development
**Requirements:**
- Docker & Docker Compose
- Node.js 20+ (for frontend development)
- Python 3.10+ (for backend development)
**Setup:**
```bash
# Clone repository
git clone https://github.com/satwareAG/saap.git
cd saap
# Copy environment template
cp .env.example .env
# Edit .env with your API keys
nano .env
# Start development environment
docker-compose up -d
# Verify services
curl http://localhost:8000/health
curl http://localhost:5173
```
**Services:**
- Backend API: http://localhost:8000
- Frontend: http://localhost:5173
- API Docs: http://localhost:8000/docs
- PostgreSQL: localhost:5432
### 2. Production Deployment
**Production Configuration:**
```bash
# Use production overlay
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
```
**Key Differences:**
- Optimized builds (no dev dependencies)
- Port 80 exposed (not 5173)
- Named volumes for data persistence
- Production CORS settings
- No hot reload
- Uvicorn workers: 4
## π Environment Variables
### Required Variables
```bash
# API Keys (MANDATORY)
COLOSSUS_API_KEY=your-colossus-key
OPENROUTER_API_KEY=your-openrouter-key
# Database
POSTGRES_DB=saap_db
POSTGRES_USER=saap_user
POSTGRES_PASSWORD=strong-password-here
```
### Production Variables
```bash
# Security
ENVIRONMENT=production
DEBUG=false
LOG_LEVEL=WARNING
SECRET_KEY=generate-strong-secret
# CORS (whitelist domains)
CORS_ORIGINS=https://yourdomain.com,https://app.yourdomain.com
# Performance
WORKERS=4
```
## π οΈ CI/CD Pipeline (GitHub Actions)
### Automated Workflow
**Triggers:**
- Push to `main` branch
- Push to `develop` branch
- Pull requests to `main`
**Stages:**
1. **Security Checks**
- Gitleaks secret scanning
- Dependency vulnerability scanning (npm audit)
2. **Linting & Type Checking**
- ESLint (frontend)
- Ruff (backend)
- TypeScript validation
3. **Testing**
- Unit tests
- Integration tests
- Coverage reporting
4. **Build**
- Multi-architecture Docker images (amd64, arm64)
- Optimized production builds
- Image tagging (commit SHA + latest)
5. **Push to Registry**
- GitHub Container Registry (ghcr.io)
- Automatic versioning
### Manual Deployment
**Deploy to production:**
```bash
# SSH into server
ssh [email protected]
# Pull latest images
docker pull ghcr.io/satwareag/saap/backend:latest
docker pull ghcr.io/satwareag/saap/frontend:latest
# Restart services
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
```
## π¦ Container Registry
**Images:**
```
ghcr.io/satwareag/saap/backend:latest
ghcr.io/satwareag/saap/backend:<commit-sha>
ghcr.io/satwareag/saap/frontend:latest
ghcr.io/satwareag/saap/frontend:<commit-sha>
```
**Authentication:**
```bash
# GitHub Personal Access Token required
echo $GITHUB_TOKEN | docker login ghcr.io -u USERNAME --password-stdin
```
## π Health Checks
### Backend Health Check
```bash
# Simple health check (Docker/Kubernetes)
curl http://localhost:8000/health
# Response
{"status":"healthy","timestamp":"2025-11-18T10:00:00"}
# Detailed health check
curl http://localhost:8000/api/v1/health
# Response
{
"status": "healthy",
"services": {
"agent_manager": "active",
"websocket": "active",
"colossus_api": "connected"
}
}
```
### Frontend Health Check
```bash
curl http://localhost/
# Returns Vue.js application
```
## ποΈ Data Persistence
### Development
```yaml
volumes:
- ./backend/logs:/app/logs # Local logs
- ./data/postgres:/var/lib/postgresql/data # Local database
```
### Production
```yaml
volumes:
postgres_data:
driver_opts:
device: /data/saap/postgres # Persistent storage
backend_logs:
driver_opts:
device: /data/saap/logs
```
**Backup Strategy:**
```bash
# Database backup
docker exec saap-postgres-1 pg_dump -U saap_user saap_db > backup.sql
# Restore
docker exec -i saap-postgres-1 psql -U saap_user saap_db < backup.sql
```
## π Security Best Practices
### 1. Secrets Management
**NEVER commit:**
- `.env` files
- API keys
- Database passwords
- SSL certificates
**Use:**
- GitHub Secrets for CI/CD
- Environment variables in production
- Secrets managers (HashiCorp Vault, AWS Secrets Manager)
### 2. Pre-deployment Checklist
```bash
# Security scan
gitleaks detect --source . --verbose
# Dependency audit
npm audit --audit-level=moderate
pip-audit
# Secrets in .env only
grep -r "OPENROUTER_API_KEY" . --exclude-dir=node_modules --exclude=.env
```
### 3. HTTPS Configuration
**Nginx with Let's Encrypt:**
```nginx
server {
listen 443 ssl http2;
server_name yourdomain.com;
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
location / {
proxy_pass http://localhost:80;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /api {
proxy_pass http://localhost:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
```
## π Monitoring
### Application Logs
```bash
# Backend logs
docker logs saap-backend-1 -f
# Frontend logs
docker logs saap-frontend-1 -f
# Database logs
docker logs saap-postgres-1 -f
```
### Metrics
**Health check monitoring:**
```bash
# Cron job for health monitoring
*/5 * * * * curl -f http://localhost:8000/health || systemctl restart saap
```
## π¨ Troubleshooting
### Common Issues
**1. Container won't start:**
```bash
# Check logs
docker-compose logs backend
docker-compose logs frontend
# Rebuild without cache
docker-compose build --no-cache
```
**2. Database connection failed:**
```bash
# Verify PostgreSQL running
docker-compose ps postgres
# Check DATABASE_URL in .env
echo $DATABASE_URL
# Test connection
docker exec -it saap-postgres-1 psql -U saap_user -d saap_db
```
**3. API keys not working:**
```bash
# Verify environment variables loaded
docker exec saap-backend-1 env | grep API_KEY
# Restart backend
docker-compose restart backend
```
**4. CORS errors:**
```bash
# Update CORS_ORIGINS in .env
CORS_ORIGINS=http://localhost:5173,https://yourdomain.com
# Restart backend
docker-compose restart backend
```
## π Update Procedure
### Development
```bash
git pull origin main
docker-compose down
docker-compose build
docker-compose up -d
```
### Production
```bash
# 1. Backup database
docker exec saap-postgres-1 pg_dump -U saap_user saap_db > backup.sql
# 2. Pull new images
docker pull ghcr.io/satwareag/saap/backend:latest
docker pull ghcr.io/satwareag/saap/frontend:latest
# 3. Restart with zero downtime
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d --no-deps --build backend
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d --no-deps --build frontend
# 4. Verify health
curl http://localhost:8000/health
```
## π Additional Resources
- [Docker Documentation](https://docs.docker.com/)
- [GitHub Actions](https://docs.github.com/en/actions)
- [FastAPI Deployment](https://fastapi.tiangolo.com/deployment/)
- [Nginx Configuration](https://nginx.org/en/docs/)
## π Support
- GitHub Issues: https://github.com/satwareAG/saap/issues
- Email: [email protected]
|