services:
  dev:
    build:
      args:
        NODE_VERSION: '20'
      context: .
      target: dev
    environment:
    - NODE_ENV=development
    - PORT=${DEV_PORT_1:-3000}
    - BACKEND_PORT=${DEV_PORT_2:-5000}
    ports:
    - ${DEV_PORT_1:-3000}:3000
    - ${DEV_PORT_2:-5000}:5000
    - 9229:9229
    volumes:
    - .:/app:cached
    - node_modules:/app/node_modules
    - npm-cache:/root/.npm
    - ~/.gitconfig:/root/.gitconfig
    - ~/.ssh:/root/.ssh

  owl-db:
    image: postgres:16-alpine
    container_name: owl-stream-db
    restart: unless-stopped
    environment:
      POSTGRES_DB: owl_stream
      POSTGRES_USER: owl_user
      POSTGRES_PASSWORD: ${DB_PASSWORD:-owl_pass_change_me}
    volumes:
      - owl_pg_data:/var/lib/postgresql/data
    ports:
      - "127.0.0.1:5433:5432"
    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"

  owl-backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    container_name: owl-stream-backend
    restart: unless-stopped
    depends_on:
      owl-db:
        condition: service_healthy
    environment:
      DATABASE_URL: postgresql://owl_user:${DB_PASSWORD:-owl_pass_change_me}@owl-db:5432/owl_stream
      JWT_SECRET: ${JWT_SECRET:-change-me-to-random-secret}
      PORT: 3020
      HOST: 0.0.0.0
      ALLOWED_ORIGINS: ${ALLOWED_ORIGINS:-http://localhost:3000}
    ports:
      - "127.0.0.1:3020:3020"
      - "172.18.0.1:3020:3020"
    healthcheck:
      test: ["CMD-SHELL", "wget -qO- http://localhost:3020/api/health || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 3
    logging:
      driver: json-file
      options:
        max-size: "10m"
        max-file: "3"

volumes:
  node_modules: {}
  npm-cache: {}
  pip-cache: {}
  owl_pg_data: {}
