Files
microdao-daarion/DEPLOY_ON_SERVER.md
Apple 3de3c8cb36 feat: Add presence heartbeat for Matrix online status
- matrix-gateway: POST /internal/matrix/presence/online endpoint
- usePresenceHeartbeat hook with activity tracking
- Auto away after 5 min inactivity
- Offline on page close/visibility change
- Integrated in MatrixChatRoom component
2025-11-27 00:19:40 -08:00

7.3 KiB

DAARION MVP — Production Deployment Guide

Домен: https://app.daarion.space
Сервер: VPS Ubuntu 22.04 LTS
Версія: 1.0.0 MVP


🎯 Quick Start

# 1. Clone repository
git clone https://github.com/yourorg/microdao-daarion.git
cd microdao-daarion

# 2. Configure environment
cp .env.example .env
# Edit .env and fill in all CHANGE_ME_* values

# 3. Run deployment
chmod +x scripts/deploy-prod.sh
./scripts/deploy-prod.sh

# 4. Run smoke tests
# Follow docs/DEPLOY_SMOKETEST_CHECKLIST.md

Estimated time: 30-45 minutes


📚 Detailed Documentation

Pre-deployment:

  1. DNS Setup — Configure DNS records
  2. Environment Config — Set up .env files

Deployment:

  1. SSL/HTTPS Setup — Configure Caddy
  2. Database Migrations — Apply all migrations
  3. Services Deployment — Start all services

Post-deployment:

  1. Smoke Tests — Verify everything works
  2. Monitoring — Set up monitoring
  3. Security — Harden security

🚀 Architecture

Internet
   │
   ├─> Caddy (Port 443) → SSL Termination
   │       │
   │       └─> Gateway (Port 80 internal)
   │               │
   │               ├─> Frontend (React/Vite)
   │               ├─> City Service (Port 7001)
   │               ├─> Agents Service (Port 7002)
   │               ├─> Second Me Service (Port 7003)
   │               ├─> MicroDAO Service (Port 7004)
   │               └─> Auth Service (Port 7000)
   │
   ├─> PostgreSQL (internal only)
   ├─> Redis (internal only)
   ├─> NATS (internal only)
   └─> Grafana (optional: /grafana/)

Prerequisites

Server Requirements:

  • OS: Ubuntu 22.04 LTS
  • CPU: 4+ cores
  • RAM: 16+ GB
  • Disk: 256+ GB NVMe
  • Network: Static IP, ports 80/443 open

Software:

  • Docker 24+
  • Docker Compose 2.20+
  • Git
  • OpenSSL

Domain:

  • Control over DNS records for daarion.space

🔧 Initial Server Setup

# 1. Update system
sudo apt update && sudo apt upgrade -y

# 2. Install Docker
curl -fsSL https://get.docker.com | sh
sudo usermod -aG docker $USER
newgrp docker

# 3. Install Docker Compose
sudo apt install docker-compose-plugin -y

# 4. Configure firewall
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable

# 5. Create deployment directory
sudo mkdir -p /opt/daarion
sudo chown $USER:$USER /opt/daarion
cd /opt/daarion

🌐 DNS Configuration

Required Records:

Type: A, Name: @, Value: <YOUR_SERVER_IP>
Type: A, Name: app, Value: <YOUR_SERVER_IP>

Verification:

dig app.daarion.space +short
# Should return your server IP

See: docs/DEPLOY_DNS_SETUP.md


🔐 Environment Configuration

1. Copy example:

cp .env.example .env

2. Generate secrets:

# JWT Secret
openssl rand -hex 32

# Database Password
openssl rand -base64 32 | tr -d "=+/" | cut -c1-25

# Redis Password
openssl rand -base64 32 | tr -d "=+/" | cut -c1-25

# Grafana Password
openssl rand -base64 16

3. Edit .env:

Replace all CHANGE_ME_* values with generated secrets.

See: docs/DEPLOY_ENV_CONFIG.md


🗄️ Database Migrations

# Run migration script
chmod +x scripts/migrate.sh
./scripts/migrate.sh

Verification:

docker compose -f docker-compose.all.yml exec postgres \
  psql -U daarion_user -d daarion -c "SELECT COUNT(*) FROM city_rooms;"
# Expected: 5

See: docs/DEPLOY_MIGRATIONS.md


🚀 Deployment

Automated:

chmod +x scripts/deploy-prod.sh
./scripts/deploy-prod.sh

Manual:

# 1. Create network
docker network create daarion-network

# 2. Start services
docker compose -f docker-compose.all.yml up -d

# 3. Start Caddy
docker compose -f docker-compose.caddy.yml up -d

# 4. Check status
docker ps | grep daarion

Verification

1. Health Checks:

curl -I https://app.daarion.space/health
# Expected: HTTP/2 200

curl https://app.daarion.space/city/rooms | jq
# Expected: Array of 5 rooms

2. SSL Certificate:

echo | openssl s_client -servername app.daarion.space \
  -connect app.daarion.space:443 2>/dev/null | \
  openssl x509 -noout -dates

3. WebSocket:

Open https://app.daarion.space/city/rooms in browser, check DevTools → Network → WS


🧪 Smoke Tests

Run comprehensive smoke tests:

# Follow checklist
cat docs/DEPLOY_SMOKETEST_CHECKLIST.md

Critical tests:

  • HTTPS works
  • City Rooms API returns data
  • WebSocket connections establish
  • Second Me responds
  • No errors in logs

📊 Monitoring

Docker Stats:

docker stats

Service Logs:

docker logs -f daarion-gateway
docker logs -f daarion-city-service
docker logs -f daarion-caddy

Grafana (optional):

https://app.daarion.space/grafana/
Username: admin
Password: <from .env>

🔒 Security Checklist

  • All secrets changed from defaults
  • PostgreSQL not exposed externally
  • Redis not exposed externally
  • NATS not exposed externally
  • Grafana protected with strong password
  • Firewall configured (ufw)
  • SSL certificate valid
  • Security headers present

See: docs/DEPLOY_SECURITY.md


🛠️ Maintenance

Backup:

# Database backup
docker compose -f docker-compose.all.yml exec postgres \
  pg_dump -U daarion_user daarion > backup_$(date +%Y%m%d).sql
gzip backup_*.sql

Updates:

git pull origin main
docker compose -f docker-compose.all.yml pull
docker compose -f docker-compose.all.yml up -d

Restart:

docker compose -f docker-compose.all.yml restart <service_name>

Stop:

./scripts/stop-prod.sh

🚨 Troubleshooting

Service won't start:

docker logs <container_name>
docker compose -f docker-compose.all.yml config

Database connection fails:

docker compose -f docker-compose.all.yml exec postgres \
  psql -U daarion_user -d daarion -c "SELECT 1;"

SSL certificate issues:

docker logs daarion-caddy | grep -i "acme\|certificate"

WebSocket connection fails:

  • Check Caddy configuration in Caddyfile
  • Verify @websocket directive present
  • Check browser console for errors

📞 Support

  • Documentation: docs/ directory
  • Issues: GitHub Issues
  • Logs: /var/log/daarion/ and docker logs

🎉 Success Criteria

Deployment is successful when:

  1. https://app.daarion.space loads without errors
  2. SSL certificate is valid (Let's Encrypt)
  3. All Docker containers are running (docker ps)
  4. City Rooms API returns 5 default rooms
  5. WebSocket connections work
  6. Second Me responds to prompts
  7. No critical errors in logs
  8. Database has all tables (10 migrations)

Deployed: _______________ (date)
Version: 1.0.0 MVP
Status: Production Ready 🚀