204 lines
7.1 KiB
YAML
204 lines
7.1 KiB
YAML
# INOWYA Location History Analyzer - Docker Compose (Redone Version)
|
|
# Self-contained deployment for GPS/location data analysis
|
|
# Supports: Google Takeout, GPX, KML, etc. | Offline-capable | Multi-arch (M1 Mac/x86/ARM)
|
|
# Usage: docker compose up -d | Access: http://localhost:3000 (UI), :8000/docs (API)
|
|
|
|
services:
|
|
# 1. Database: PostgreSQL + PostGIS for spatial queries (raw_points, stops, trips)
|
|
postgres:
|
|
image: postgis/postgis:15-3.4-alpine # Lightweight, ARM64 compatible
|
|
container_name: inowya_postgres
|
|
restart: unless-stopped
|
|
platform: linux/arm64 # For M1 Mac; remove if on x86
|
|
environment:
|
|
POSTGRES_DB: ${POSTGRES_DB:-inowya}
|
|
POSTGRES_USER: ${POSTGRES_USER:-inowya}
|
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-inowya123}
|
|
volumes:
|
|
- postgres_data:/var/lib/postgresql/data
|
|
- ./database:/docker-entrypoint-initdb.d:ro # Auto-run schema.sql on init
|
|
ports:
|
|
- '5432:5432' # Optional: Expose for external tools like pgAdmin
|
|
healthcheck:
|
|
test: ['CMD-SHELL', 'pg_isready -U ${POSTGRES_USER:-inowya} -d ${POSTGRES_DB:-inowya}']
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 5
|
|
start_period: 30s
|
|
command: postgres -c shared_preload_libraries=postgis-3 -c postgis.gdal_enabled_drivers=GTiff,WebP
|
|
|
|
# 2. Cache/Session Store: Redis for heat tiles, WebSocket sessions, Celery broker
|
|
redis:
|
|
image: redis:7-alpine
|
|
container_name: inowya_redis
|
|
restart: unless-stopped
|
|
platform: linux/arm64 # For M1 Mac; remove if on x86
|
|
command: redis-server --appendonly yes --requirepass ${REDIS_PASSWORD:-inowya_redis}
|
|
volumes:
|
|
- redis_data:/data
|
|
ports:
|
|
- '6379:6379' # Optional: Expose for monitoring
|
|
healthcheck:
|
|
test: ['CMD', 'redis-cli', '-a', '${REDIS_PASSWORD:-inowya_redis}', 'ping']
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 5
|
|
|
|
# 3. Map Tiles: Self-hosted OpenMapTiles server (vector tiles, offline with MBTiles)
|
|
tileserver:
|
|
# --- FIX APPLIED HERE: Replaced deprecated overv/openmaptiles-server with maptiler/tileserver-gl ---
|
|
image: maptiler/tileserver-gl:v5.4.0 # Current stable, ARM64 compatible
|
|
container_name: inowya_tileserver
|
|
restart: unless-stopped
|
|
platform: linux/arm64 # For M1 Mac; remove if on x86
|
|
ports:
|
|
- '8080:80'
|
|
volumes:
|
|
- ./maptiles:/data # Mount downloaded MBTiles (e.g., planet.mbtiles ~5GB regional)
|
|
environment:
|
|
- MBTILES=/data/openmaptiles.mbtiles # Customize for your tiles
|
|
- PORT=80
|
|
healthcheck:
|
|
test: ['CMD', 'curl', '-f', 'http://localhost:80/health']
|
|
interval: 30s
|
|
timeout: 10s
|
|
retries: 3
|
|
start_period: 60s # Tileserver takes longer to init
|
|
|
|
# 4. Backend API: FastAPI (REST + WebSocket, OpenAPI docs)
|
|
backend:
|
|
build:
|
|
context: ./backend
|
|
dockerfile: Dockerfile
|
|
args:
|
|
- PYTHON_VERSION=3.11
|
|
container_name: inowya_backend
|
|
restart: unless-stopped
|
|
platform: linux/arm64 # For M1 Mac; remove if on x86
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
redis:
|
|
condition: service_healthy
|
|
environment:
|
|
- DATABASE_URL=postgresql://${POSTGRES_USER:-inowya}:${POSTGRES_PASSWORD:-inowya123}@postgres:5432/${POSTGRES_DB:-inowya}
|
|
- REDIS_URL=redis://:${REDIS_PASSWORD:-inowya_redis}@redis:6379/0
|
|
- CELERY_BROKER_URL=redis://:${REDIS_PASSWORD:-inowya_redis}@redis:6379/0
|
|
- SECRET_KEY=${SECRET_KEY:-your-super-secret-key-change-this}
|
|
- TZ=${TZ:-America/Los_Angeles}
|
|
- NOMINATIM_OFFLINE=${NOMINATIM_OFFLINE:-true}
|
|
volumes:
|
|
- ./backend:/app:ro # Read-only for security
|
|
- ./uploads:/app/uploads # For file uploads
|
|
ports:
|
|
- '8000:8000'
|
|
healthcheck:
|
|
test: ['CMD', 'curl', '-f', 'http://localhost:8000/health']
|
|
interval: 30s
|
|
timeout: 10s
|
|
retries: 3
|
|
start_period: 20s
|
|
user: "1000:1000" # Non-root user (match your host UID for volumes)
|
|
|
|
# 5. Workers: Celery for async tasks (parsing, DBSCAN, XGBoost, enrichment)
|
|
worker:
|
|
build:
|
|
context: ./workers
|
|
dockerfile: Dockerfile
|
|
args:
|
|
- PYTHON_VERSION=3.11
|
|
container_name: inowya_worker
|
|
restart: unless-stopped
|
|
platform: linux/arm64 # For M1 Mac; remove if on x86
|
|
depends_on:
|
|
- backend
|
|
- postgres
|
|
- redis
|
|
environment:
|
|
- DATABASE_URL=postgresql://${POSTGRES_USER:-inowya}:${POSTGRES_PASSWORD:-inowya123}@postgres:5432/${POSTGRES_DB:-inowya}
|
|
- REDIS_URL=redis://:${REDIS_PASSWORD:-inowya_redis}@redis:6379/0
|
|
- CELERY_BROKER_URL=redis://:${REDIS_PASSWORD:-inowya_redis}@redis:6379/0
|
|
- TZ=${TZ:-America/Los_Angeles}
|
|
- TRAIN_MODE=${TRAIN_MODE:-0}
|
|
- PROBUF_GENERATE=${PROBUF_GENERATE:-true}
|
|
volumes:
|
|
- ./workers:/app:ro
|
|
- ./uploads:/app/uploads
|
|
- ./nominatim-data:/app/nominatim-data # Offline geocoding
|
|
- ./srtm-data:/app/srtm-data # Elevation data
|
|
command: celery -A celery_app worker --loglevel=info --concurrency=4 --autoscale=4,2
|
|
healthcheck:
|
|
test: ['CMD-SHELL', 'celery -A celery_app inspect ping']
|
|
interval: 30s
|
|
timeout: 10s
|
|
retries: 3
|
|
start_period: 40s
|
|
user: "1000:1000" # Non-root
|
|
|
|
# 6. Frontend: React PWA (MapLibre, offline-capable)
|
|
frontend:
|
|
build:
|
|
context: ./frontend
|
|
dockerfile: Dockerfile
|
|
args:
|
|
- NODE_VERSION=18
|
|
container_name: inowya_frontend
|
|
restart: unless-stopped
|
|
platform: linux/arm64 # For M1 Mac; remove if on x86
|
|
depends_on:
|
|
- backend
|
|
- tileserver
|
|
environment:
|
|
- REACT_APP_API_URL=${REACT_APP_API_URL:-http://localhost:8000}
|
|
- REACT_APP_TILE_URL=${REACT_APP_TILE_URL:-http://localhost:8080}
|
|
- REACT_APP_WS_URL=ws://localhost:8000/ws
|
|
- I18N_LANG=${I18N_LANG:-en}
|
|
volumes:
|
|
- ./frontend:/app
|
|
- /app/node_modules # Exclude host node_modules for clean build
|
|
ports:
|
|
- '3000:3000' # Dev server (hot reload)
|
|
# For production (static serve via Nginx):
|
|
# ports:
|
|
# - '80:80'
|
|
# command: npm run build && nginx -g 'daemon off;'
|
|
healthcheck:
|
|
test: ['CMD', 'curl', '-f', 'http://localhost:3000']
|
|
interval: 30s
|
|
timeout: 10s
|
|
retries: 3
|
|
start_period: 60s # Build time
|
|
user: "1000:1000" # Non-root
|
|
|
|
# Optional: Reverse Proxy for HTTPS/LAN (Traefik)
|
|
# traefik:
|
|
# image: traefik:v2.10
|
|
# command:
|
|
# - "--api.insecure=true"
|
|
# - "--providers.docker=true"
|
|
# - "--entrypoints.web.address=:80"
|
|
# ports:
|
|
# - "80:80"
|
|
# - "8081:8080" # Dashboard
|
|
# volumes:
|
|
# - /var/run/docker.sock:/var/run/docker.sock
|
|
|
|
volumes:
|
|
postgres_data:
|
|
driver: local
|
|
redis_data:
|
|
driver: local
|
|
|
|
networks:
|
|
default:
|
|
driver: bridge
|
|
name: inowya_network
|
|
|
|
# Deployment Notes:
|
|
# - Min Specs: 4-core CPU, 8GB RAM, 20GB disk
|
|
# - First Run: docker compose build (downloads ~1.5GB)
|
|
# - Offline Maps: Download MBTiles to ./maptiles/ (e.g., from openmaptiles.org)
|
|
# - Security: Change passwords in .env; enable RLS in schema.sql
|
|
# - Scaling: Add more workers via docker compose scale worker=3
|
|
# - Backup: docker compose exec postgres pg_dumpall -U inowya > backup.sql
|
|
# - Cleanup: docker compose down -v && docker system prune |