Communication Service Deployment
Docker Deployment
Dockerfile
The service includes a production-ready Dockerfile.
Build Image
cd shared/communication
docker build -t communication:latest .
Run Container
docker run -d \
--name communication \
-p 8010:8010 \
-e DATABASE_URL=postgresql://user:pass@postgres:5432/communication \
-e REDIS_URL=redis://redis:6379 \
communication:latest
Docker Compose
The service is included in infra/compose.yml:
communication:
build: ./shared/communication
ports:
- "8010:8010"
environment:
- DATABASE_URL=postgresql://user:pass@postgres:5432/communication
- REDIS_URL=redis://redis:6379
depends_on:
- postgres
- redis
Production Deployment
Prerequisites
- PostgreSQL 14+ database
- Redis instance for Oban
- Environment variables configured
Steps
- Build Release:
cd shared/communication
MIX_ENV=prod mix release
- Run Migrations:
_build/prod/rel/communication/bin/communication eval "Communication.Release.migrate()"
- Start Service:
_build/prod/rel/communication/bin/communication start
Systemd Service
Create /etc/systemd/system/communication.service:
[Unit]
Description=Communication Service
After=network.target postgresql.service redis.service
[Service]
Type=simple
User=communication
WorkingDirectory=/opt/communication
ExecStart=/opt/communication/bin/communication start
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
Health Checks
The service exposes health check endpoints:
GET /health- Basic health checkGET /health/detailed- Detailed health including database and Redis
Monitoring
Metrics
Prometheus metrics are available at /metrics.
Logging
Logs are written to stdout/stderr. Configure log aggregation in production.
Scaling
The service can be horizontally scaled:
- Run multiple instances behind a load balancer
- Ensure all instances connect to the same PostgreSQL and Redis
- Oban will distribute jobs across instances
Backup
Database Backup
pg_dump -h localhost -U user communication > backup.sql
Template Backup
Templates are stored in PostgreSQL, so database backup includes them.