services:
  postgres:
    image: postgres:17-alpine
    environment:
      POSTGRES_DB: stream_platform
      POSTGRES_USER: stream
      POSTGRES_PASSWORD: stream
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./apps/api/sql/001_init.sql:/docker-entrypoint-initdb.d/001_init.sql:ro
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U stream -d stream_platform"]
      interval: 5s
      timeout: 3s
      retries: 20

  redis:
    image: redis:7.4-alpine
    command: ["redis-server", "--appendonly", "yes"]
    volumes:
      - redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 3s
      retries: 20

  api:
    build:
      context: ./apps/api
    env_file:
      - ./.env
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    restart: unless-stopped

  web:
    image: nginx:1.27-alpine
    depends_on:
      - api
    ports:
      - "8080:80"
    volumes:
      - ./apps/web:/usr/share/nginx/html:ro
      - ./infra/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
    restart: unless-stopped

volumes:
  postgres_data:
  redis_data:
