services:
  postgres:
    image: postgres:16-alpine
    container_name: talkchannel-relay-postgres
    restart: unless-stopped
    ports:
      - '5433:5432'
    environment:
      POSTGRES_DB: ${POSTGRES_DB:-talkchannel_relay}
      POSTGRES_USER: ${POSTGRES_USER:-postgres}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -U ${POSTGRES_USER:-postgres} -d ${POSTGRES_DB:-talkchannel_relay}']
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 10s

  redis:
    image: redis:7-alpine
    container_name: talkchannel-relay-redis
    restart: unless-stopped
    ports:
      - '6379:6379'
    command: ['redis-server', '--appendonly', 'yes']
    volumes:
      - redis_data:/data
    healthcheck:
      test: ['CMD', 'redis-cli', 'ping']
      interval: 10s
      timeout: 5s
      retries: 5

  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: talkchannel-relay-app
    restart: unless-stopped
    ports:
      - '8080:8080'
    environment:
      PORT: 8080
      LOG_LEVEL: ${LOG_LEVEL:-info}
      DATABASE_URL: postgresql://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-postgres}@postgres:5432/${POSTGRES_DB:-talkchannel_relay}
      REDIS_URL: redis://redis:6379
      ADMIN_PASSWORD_HASH: ${ADMIN_PASSWORD_HASH:?Set ADMIN_PASSWORD_HASH (generate with: go run scripts/hash-password.go)}
      ADMIN_SESSION_SECRET: ${ADMIN_SESSION_SECRET:?Set ADMIN_SESSION_SECRET (generate with: openssl rand -base64 32)}
      PORTAL_SESSION_SECRET: ${PORTAL_SESSION_SECRET:?Set PORTAL_SESSION_SECRET (generate with: openssl rand -base64 32)}
      QUEUE_TTL_SECONDS: ${QUEUE_TTL_SECONDS:-900}
      CALLBACK_TTL_SECONDS: ${CALLBACK_TTL_SECONDS:-55}
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy

volumes:
  postgres_data:
    driver: local
  redis_data:
    driver: local
