# Deployment Checklist

## Pre-Deployment

### 1. Configuration Files
- [ ] Copy `.env.example` to `.env`
- [ ] Update `SECRET_KEY` in `.env` with a secure random string
- [ ] Update database password in `.env`
- [ ] Update database password in `docker-compose.yml` to match

### 2. Caddy Integration
- [ ] Find Caddy network name: `docker network ls`
- [ ] Update `docker-compose.yml` with Caddy network name (lines 20 and 28-29)
- [ ] Add TestArena configuration to Caddyfile
- [ ] Reload Caddy configuration

### 3. Security
- [ ] Generate strong SECRET_KEY (use: `python -c "import secrets; print(secrets.token_hex(32))"`)
- [ ] Set strong database password
- [ ] Review firewall rules
- [ ] Ensure only Caddy exposes ports to internet

## Deployment

### 4. Build and Start
- [ ] Run: `docker-compose up -d --build`
- [ ] Wait 30 seconds for database initialization
- [ ] Check containers are running: `docker ps`
- [ ] Check logs for errors: `docker-compose logs`

### 5. Verify Services
- [ ] Database container is running
- [ ] Web container is running
- [ ] Web container is on both networks (testarena_network and caddy_network)
- [ ] No error messages in logs

### 6. Test Access
- [ ] Access via domain: https://testarena.nabd-co.com
- [ ] Login page loads correctly
- [ ] Logo displays properly
- [ ] CSS styles are applied

## Post-Deployment

### 7. Initial Setup
- [ ] Login with default credentials (admin/admin123)
- [ ] Change admin password immediately
- [ ] Create test user account
- [ ] Test user login
- [ ] Verify admin can see admin dashboard
- [ ] Verify regular user cannot see admin dashboard

### 8. Functionality Tests
- [ ] Admin: Create new user
- [ ] Admin: Reset user password
- [ ] Admin: Delete user
- [ ] User: Access dashboard
- [ ] User: Start job submission workflow
- [ ] User: Complete all 5 steps of submission
- [ ] User: View job in dashboard
- [ ] User: Click job to see details

### 9. Security Hardening
- [ ] All default passwords changed
- [ ] Database not accessible from internet
- [ ] Only Caddy exposes ports
- [ ] HTTPS working correctly
- [ ] Security headers configured in Caddy

### 10. Monitoring Setup
- [ ] Set up log rotation
- [ ] Configure backup schedule for database
- [ ] Set up monitoring alerts
- [ ] Document backup restoration procedure

## Verification Commands

```bash
# Check all containers
docker ps

# Check logs
docker-compose logs -f

# Check web container networks
docker inspect testarena_web | grep -A 10 Networks

# Check database connection
docker exec testarena_web python -c "from app import create_app, db; app = create_app(); app.app_context().push(); print('DB OK')"

# Test HTTP response
curl -I http://localhost:5000

# Test HTTPS response
curl -I https://testarena.nabd-co.com
```

## Rollback Plan

If deployment fails:

```bash
# Stop containers
docker-compose down

# Remove volumes (WARNING: deletes data)
docker-compose down -v

# Check for issues
docker-compose logs

# Fix configuration
# ... make changes ...

# Retry deployment
docker-compose up -d --build
```

## Backup Procedure

### Database Backup
```bash
# Create backup
docker exec testarena_db pg_dump -U testarena_user testarena > backup_$(date +%Y%m%d).sql

# Restore backup
docker exec -i testarena_db psql -U testarena_user testarena < backup_20240101.sql
```

### Full Backup
```bash
# Backup volumes
docker run --rm -v testarena_postgres_data:/data -v $(pwd):/backup alpine tar czf /backup/db_backup.tar.gz /data
docker run --rm -v testarena_test_results:/data -v $(pwd):/backup alpine tar czf /backup/results_backup.tar.gz /data
```

## Troubleshooting

### Container won't start
1. Check logs: `docker-compose logs web`
2. Verify database is ready: `docker-compose logs db`
3. Check environment variables in docker-compose.yml

### Can't access via domain
1. Verify DNS: `nslookup testarena.nabd-co.com`
2. Check Caddy: `docker logs caddy_container_name`
3. Verify network: `docker network inspect caddy_network`

### Database connection error
1. Check DATABASE_URL format
2. Verify database container is running
3. Check database logs: `docker-compose logs db`

### 502 Bad Gateway
1. Web container not ready - wait 30 seconds
2. Check web logs: `docker-compose logs web`
3. Verify Gunicorn is running: `docker exec testarena_web ps aux`

## Success Criteria

✅ All containers running
✅ No errors in logs
✅ Login page accessible via HTTPS
✅ Admin can login and manage users
✅ Regular user can login and access dashboard
✅ Job submission workflow completes
✅ Jobs appear in dashboard
✅ Job details display correctly

## Post-Deployment Tasks

- [ ] Document any configuration changes
- [ ] Update team on new system
- [ ] Schedule training session
- [ ] Plan Phase 2 implementation
- [ ] Set up regular maintenance schedule

## Maintenance Schedule

### Daily
- Check logs for errors
- Verify all containers running

### Weekly
- Database backup
- Review disk usage
- Check for security updates

### Monthly
- Update Docker images
- Review user accounts
- Clean up old test results (automated)
- Performance review

## Support Contacts

- System Admin: [Your contact]
- Database Admin: [Your contact]
- Development Team: [Your contact]

---

**Deployment Date:** _______________
**Deployed By:** _______________
**Verified By:** _______________
