x-defaults: &defaults
  restart: unless-stopped
  logging:
    driver: json-file
    options:
      max-size: 100m
      max-file: '3'

services:
  odoo:
    <<: *defaults
    image: ${GLOBAL_REGISTRY:-}odoo:${ODOO_VERSION:-19.0}
    depends_on:
      odoo-db:
        condition: service_healthy
    ports:
      - '${ODOO_PORT_OVERRIDE:-8069}:8069'
    volumes:
      - odoo_web_data:/var/lib/odoo
      - odoo_addons:/mnt/extra-addons
    environment:
      - TZ=${TZ:-UTC}
      - HOST=odoo-db
      - USER=${POSTGRES_USER:-odoo}
      - PASSWORD=${POSTGRES_PASSWORD:-odoopass}
      - DB_PORT=5432
      - DB_NAME=${POSTGRES_DB:-postgres}
    deploy:
      resources:
        limits:
          cpus: ${ODOO_CPU_LIMIT:-2.0}
          memory: ${ODOO_MEMORY_LIMIT:-2G}
        reservations:
          cpus: ${ODOO_CPU_RESERVATION:-0.1}
          memory: ${ODOO_MEMORY_RESERVATION:-1G}
    healthcheck:
      test:
        - CMD
        - wget
        - --no-verbose
        - --tries=1
        - --spider
        - 'http://localhost:8069/'

      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s

  odoo-db:
    <<: *defaults
    image: ${GLOBAL_REGISTRY:-}postgres:${POSTGRES_VERSION:-17-alpine}
    environment:
      - TZ=${TZ:-UTC}
      - POSTGRES_USER=${POSTGRES_USER:-odoo}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-odoopass}
      - POSTGRES_DB=${POSTGRES_DB:-postgres}
      - PGDATA=/var/lib/postgresql/data/pgdata
    volumes:
      - odoo_db_data:/var/lib/postgresql/data
    deploy:
      resources:
        limits:
          cpus: ${ODOO_DB_CPU_LIMIT:-1.0}
          memory: ${ODOO_DB_MEMORY_LIMIT:-1G}
        reservations:
          cpus: ${ODOO_DB_CPU_RESERVATION:-0.1}
          memory: ${ODOO_DB_MEMORY_RESERVATION:-512M}
    healthcheck:
      test: [CMD-SHELL, 'pg_isready -U ${POSTGRES_USER:-odoo}']
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 30s

volumes:
  odoo_web_data:
  odoo_addons:
  odoo_db_data:
