
services:
  # ────────────────────────────────────────────
  # PostgreSQL
  # ────────────────────────────────────────────
  db:
    image: postgres:15
    container_name: lims_db
    environment:
      POSTGRES_DB: postgres          # BD catálogo
      POSTGRES_USER: odoo            # rol que usará Odoo
      POSTGRES_PASSWORD: supersegura # contraseña del rol
    volumes:
      - db_data:/var/lib/postgresql/data
    restart: unless-stopped

  # ────────────────────────────────────────────
  # Job de inicialización (se ejecuta una vez)
  # ────────────────────────────────────────────
  odoo_init:
    image: odoo:18.0
    depends_on: [db]
    volumes:
      - ./lims_management:/mnt/extra-addons/lims_management
      - ./odoo.conf:/etc/odoo/odoo.conf
      - ./init_odoo.py:/app/init_odoo.py
      - ./test/create_lab_requests.py:/app/create_lab_requests.py
      - ./test:/app/test
      - ./scripts:/app/scripts
    command: ["/usr/bin/python3", "/app/init_odoo.py"]
    environment:
      HOST: db
      PORT: "5432"
      USER: odoo
      PASSWORD: supersegura
    restart: "no"


  # ────────────────────────────────────────────
  # Odoo (servicio de larga vida)
  # ────────────────────────────────────────────
  odoo:
    image: odoo:18.0
    container_name: lims_odoo
    depends_on:
      db:
        condition: service_started
      odoo_init:
        condition: service_completed_successfully
    environment:
      HOST: db
      PORT: "5432"
      USER: odoo
      PASSWORD: supersegura
      MASTER_PASSWORD: admin123
    command: ["/usr/bin/python3", "/app/wait_and_start_odoo.py"]
    ports:
      - "8069:8069"
    volumes:
      - ./lims_management:/mnt/extra-addons/lims_management
      - ./odoo.conf:/etc/odoo/odoo.conf
      - ./wait_and_start_odoo.py:/app/wait_and_start_odoo.py
    restart: unless-stopped

volumes:
  db_data: {}
