name: owl-stream

services:
  owl-db:
    image: postgres:16-alpine
    container_name: owl-db
    restart: unless-stopped
    environment:
      POSTGRES_DB: owl_stream
      POSTGRES_USER: owl_user
      POSTGRES_PASSWORD: ${DB_PASSWORD:?DB_PASSWORD must be set in .env}
    volumes:
      - owl_pg_data:/var/lib/postgresql/data
    networks:
      - owl-network
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U owl_user -d owl_stream"]
      interval: 10s
      timeout: 5s
      retries: 5
    logging:
      driver: json-file
      options:
        max-size: "10m"
        max-file: "3"
    deploy:
      resources:
        limits:
          memory: 256M

  owl-backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    container_name: owl-backend
    restart: unless-stopped
    depends_on:
      owl-db:
        condition: service_healthy
    environment:
      DATABASE_URL: postgresql://owl_user:${DB_PASSWORD:?DB_PASSWORD required}@owl-db:5432/owl_stream
      JWT_SECRET: ${JWT_SECRET:?JWT_SECRET required}
      PORT: 3020
      HOST: 0.0.0.0
      ALLOWED_ORIGINS: ${ALLOWED_ORIGINS:-https://owls.bizzle.cloud,http://localhost:8089}
    ports:
      - "127.0.0.1:3020:3020"
    networks:
      - owl-network
    healthcheck:
      test: ["CMD-SHELL", "node -e 'require(\"http\").get(\"http://localhost:3020/api/stats\",r=>{process.exit(r.statusCode===200?0:1)}).on(\"error\",()=>process.exit(1))'"]
      interval: 30s
      timeout: 10s
      retries: 3
    logging:
      driver: json-file
      options:
        max-size: "10m"
        max-file: "3"
    deploy:
      resources:
        limits:
          memory: 512M

  owl-frontend:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: owl-frontend
    restart: unless-stopped
    depends_on:
      owl-backend:
        condition: service_healthy
    environment:
      - NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL:-http://127.0.0.1:3020}
    ports:
      - "127.0.0.1:8110:8089"
      - "172.18.0.1:8110:8089"
    networks:
      - owl-network
    healthcheck:
      test: ["CMD-SHELL", "wget -qO- http://0.0.0.0:8089/ || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 3
    logging:
      driver: json-file
      options:
        max-size: "10m"
        max-file: "3"
    deploy:
      resources:
        limits:
          memory: 256M

networks:
  owl-network:
    driver: bridge

volumes:
  owl_pg_data:
