#ident "@(#)$Format:LocalFoodAI:app.py:%an:%ae:%ad:%cn:%ce:%cd:%H:%D:%N$"
services:
  mysql:
    build:
      context: ./docker/mysql
    ports:
      - "3326:3306" # Shifted +20 (Original: 3306:3306)
    volumes:
      - mysql_data:/var/lib/mysql
      - ./my.cnf:/etc/mysql/conf.d/custom_ai_app.cnf
      - ./init.sql:/docker-entrypoint-initdb.d/1-init.sql
    environment:
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      interval: 10s
      timeout: 5s
      retries: 20
    restart: always
    logging:
      driver: "json-file"
      options:
        max-size: "50m"
        max-file: "3"

  ingest:
    build:
      context: .
      dockerfile: docker/ingest/Dockerfile
    environment:
      - DB_HOST=mysql
      - DB_USER=food_loader
      - DB_PASS=${DB_LOADER_PASS}
    volumes:
      - ./:/app
    profiles:
      - manual

  ollama:
    image: ollama/ollama:latest
    volumes:
      - ollama_data:/root/.ollama
    restart: always
    logging:
      driver: "json-file"
      options:
        max-size: "50m"
        max-file: "3"

  searxng:
    image: searxng/searxng:latest
    ports:
      - "8105:8080" # Shifted +20 (Original: 8085:8080)
    volumes:
      - ./searxng:/etc/searxng
    environment:
      - SEARXNG_BASE_URL=http://localhost:8080/
    restart: always
    logging:
      driver: "json-file"
      options:
        max-size: "50m"
        max-file: "3"

  app:
    build:
      context: .
      dockerfile: docker/app/Dockerfile
    ports:
      - "8522:8501" # Shifted +20 (Original: 8502:8501)
    environment:
      - DB_HOST=mysql
      - DB_USER=food_reader
      - DB_PASS=${DB_READER_PASS}
      - APP_AUTH_USER=food_app_auth
      - APP_AUTH_PASS=${DB_APP_AUTH_PASS}
      - OLLAMA_HOST=http://ollama:11434
      - SEARXNG_HOST=http://searxng:8080
    restart: always
    logging:
      driver: "json-file"
      options:
        max-size: "50m"
        max-file: "3"

  nginx:
    image: nginx:latest
    ports:
      - "100:80" # Shifted +20 (Original: 80:80). Note: If port 100 requires root or conflicts, you can use "8020:80".
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
    restart: always
    logging:
      driver: "json-file"
      options:
        max-size: "50m"
        max-file: "3"

  zabbix-server:
    image: zabbix/zabbix-server-mysql:ubuntu-7.0-latest
    environment:
      - DB_SERVER_HOST=mysql
      - MYSQL_USER=zabbix
      - MYSQL_PASSWORD=${MYSQL_ZABBIX_PASSWORD}
      - ZBX_SNMPTRAPPER=1
    restart: always
    logging:
      driver: "json-file"
      options:
        max-size: "50m"
        max-file: "3"
    ports:
      - "10071:10051" # Shifted +20 (Original: 10051:10051)

  zabbix-web:
    image: zabbix/zabbix-web-nginx-mysql:ubuntu-7.0-latest
    ports:
      - "8101:8080" # Shifted +20 (Original: 8081:8080)
      - "8464:8443" # Shifted +20 (Original: 8444:8443)
    environment:
      - DB_SERVER_HOST=mysql
      - MYSQL_USER=zabbix
      - MYSQL_PASSWORD=${MYSQL_ZABBIX_PASSWORD}
      - ZBX_SERVER_HOST=zabbix-server
      - PHP_TZ=Europe/Paris
    restart: always
    logging:
      driver: "json-file"
      options:
        max-size: "50m"
        max-file: "3"

  zabbix-agent:
    image: zabbix/zabbix-agent:ubuntu-7.0-latest
    environment:
      - ZBX_HOSTNAME=DistributedNode
      - ZBX_SERVER_HOST=zabbix-server
    privileged: true
    pid: "host"
    volumes:
      - /var/run:/var/run
    restart: always
    logging:
      driver: "json-file"
      options:
        max-size: "50m"
        max-file: "3"

  airflow-webserver:
    image: apache/airflow:2.8.1
    environment:
      - AIRFLOW__CORE__EXECUTOR=SequentialExecutor
      - AIRFLOW__DATABASE__SQL_ALCHEMY_CONN=sqlite:////opt/airflow/data/airflow.db
      - AIRFLOW__CORE__LOAD_EXAMPLES=False
    ports:
      - "8102:8080" # Shifted +20 (Original: 8082:8080)
    volumes:
      - ./dags:/opt/airflow/dags
      - ./logs:/opt/airflow/logs
      - ./data:/opt/airflow/data
      - /var/run/docker.sock:/var/run/docker.sock
    command: webserver
    restart: always
    logging:
      driver: "json-file"
      options:
        max-size: "50m"
        max-file: "3"

  airflow-scheduler:
    image: apache/airflow:2.8.1
    environment:
      - AIRFLOW__CORE__EXECUTOR=SequentialExecutor
      - AIRFLOW__DATABASE__SQL_ALCHEMY_CONN=sqlite:////opt/airflow/data/airflow.db
      - AIRFLOW__CORE__LOAD_EXAMPLES=False
    volumes:
      - ./dags:/opt/airflow/dags
      - ./logs:/opt/airflow/logs
      - ./data:/opt/airflow/data
      - /var/run/docker.sock:/var/run/docker.sock
    command: bash -c "airflow db migrate && airflow users create --role Admin --username admin --email admin --firstname admin --lastname admin --password admin && airflow scheduler"
    restart: always
    logging:
      driver: "json-file"
      options:
        max-size: "50m"
        max-file: "3"

volumes:
  mysql_data:
  ollama_data: