version: "3.8"

services:
  db:
    image: postgres:15-alpine
    container_name: dine360_saas_db
    environment:
      POSTGRES_DB: postgres
      POSTGRES_USER: odoo
      POSTGRES_PASSWORD: odoo_master_pass_2026
    volumes:
      - pgdata:/var/lib/postgresql/data
      - ./postgresql.conf:/etc/postgresql/postgresql.conf
    command: "postgres -c config_file=/etc/postgresql/postgresql.conf"
    ports:
      - "5432:5432"
    restart: always
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U odoo"]
      interval: 10s
      timeout: 5s
      retries: 5

  redis:
    image: redis:7-alpine
    container_name: dine360_saas_redis
    volumes:
      - redisdata:/data
      - ./redis.conf:/usr/local/etc/redis/redis.conf
    command: "redis-server /usr/local/etc/redis/redis.conf"
    ports:
      - "6379:6379"
    restart: always

  pgbouncer:
    image: edoburu/pgbouncer:latest
    container_name: dine360_saas_pgbouncer
    environment:
      - DB_USER=odoo
      - DB_PASSWORD=odoo_master_pass_2026
      - DB_HOST=db
      - DB_PORT=5432
      - MAX_CLIENT_CONN=10000
      - DEFAULT_POOL_SIZE=50
      - MIN_POOL_SIZE=10
      - POOL_MODE=transaction
    ports:
      - "6432:6432"
    depends_on:
      - db
    restart: always

  web:
    image: odoo:17.0
    container_name: dine360_saas_web
    depends_on:
      - db
      - redis
      - pgbouncer
    ports:
      - "8069:8069"
      - "8072:8072"
    volumes:
      - odoo_data:/var/lib/odoo
      - ../addons:/mnt/extra-addons
    environment:
      - HOST=pgbouncer
      - PORT=6432
      - USER=odoo
      - PASSWORD=odoo_master_pass_2026
    command: >
      odoo 
      --workers=9 
      --max-cron-threads=0 
      --db-filter=^%d$$ 
      --proxy-mode 
      --limit-time-cpu=600 
      --limit-time-real=1200 
      --session-store=redis
    restart: always

  cron:
    image: odoo:17.0
    container_name: dine360_saas_cron
    depends_on:
      - db
      - redis
      - pgbouncer
    volumes:
      - odoo_data:/var/lib/odoo
      - ../addons:/mnt/extra-addons
    environment:
      - HOST=pgbouncer
      - PORT=6432
      - USER=odoo
      - PASSWORD=odoo_master_pass_2026
    command: >
      odoo 
      --workers=0 
      --max-cron-threads=4 
      --db-filter=^%d$$ 
      --proxy-mode
    restart: always

volumes:
  pgdata:
  redisdata:
  odoo_data:
