services: db: image: postgres:15-alpine command: ["postgres", "-c", "max_connections=1000"] environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres POSTGRES_DB: hackathon_db ports: - "5432:5432" volumes: - postgres_data:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U postgres"] interval: 5s timeout: 5s retries: 5 restart: unless-stopped redis: image: redis:7-alpine healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 5s timeout: 5s retries: 5 restart: unless-stopped app-1: &app-base build: . environment: - DATABASE_HOST=db - DATABASE_USER=postgres - DATABASE_PASSWORD=postgres - DATABASE_NAME=hackathon_db - DATABASE_PORT=5432 - REDIS_URL=redis://redis:6379/0 - ENABLE_STARTUP_SEED=true depends_on: db: condition: service_healthy redis: condition: service_healthy restart: unless-stopped app-2: <<: *app-base environment: - DATABASE_HOST=db - DATABASE_USER=postgres - DATABASE_PASSWORD=postgres - DATABASE_NAME=hackathon_db - DATABASE_PORT=5432 - REDIS_URL=redis://redis:6379/0 - ENABLE_STARTUP_SEED=false # Only one replica seeds the DB app-3: <<: *app-base environment: - DATABASE_HOST=db - DATABASE_USER=postgres - DATABASE_PASSWORD=postgres - DATABASE_NAME=hackathon_db - DATABASE_PORT=5432 - REDIS_URL=redis://redis:6379/0 - ENABLE_STARTUP_SEED=false nginx: image: nginx:alpine ports: - "8000:80" volumes: - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro depends_on: - app-1 - app-2 - app-3 restart: unless-stopped prometheus: image: prom/prometheus:latest ports: - "9090:9090" volumes: - ./monitoring/prometheus:/etc/prometheus:ro - prometheus_data:/prometheus command: - "--config.file=/etc/prometheus/prometheus.yml" - "--storage.tsdb.retention.time=7d" depends_on: - app-1 restart: unless-stopped alertmanager: image: prom/alertmanager:latest ports: - "9093:9093" volumes: - ./monitoring/alertmanager:/etc/alertmanager:ro environment: - SLACK_WEBHOOK_URL=${SLACK_WEBHOOK_URL:-http://example.com/slack} - DISCORD_WEBHOOK_URL=${DISCORD_WEBHOOK_URL:-http://example.com/discord} entrypoint: - /bin/sh - -c - "sed \"s|SLACK_WEBHOOK_URL_PLACEHOLDER|$$SLACK_WEBHOOK_URL|g\" /etc/alertmanager/alertmanager.yml | sed \"s|DISCORD_WEBHOOK_URL_PLACEHOLDER|$$DISCORD_WEBHOOK_URL|g\" > /tmp/am.yml && exec /bin/alertmanager --config.file=/tmp/am.yml" restart: unless-stopped volumes: postgres_data: prometheus_data: