version: "3.4"
services:
  zabbix-server:
    image: zabbix/zabbix-server-mysql:ubuntu-trunk
    container_name: zabbix-server
    environment:
      TZ: "Asia/Tokyo"
      DB_SERVER_HOST: mariadb
      MYSQL_ROOT_PASSWORD: "{{lookup('password', hive_context_dir + '/registry_password length=15 chars=ascii_letters,digits')}}"
      MYSQL_USER: zabbix
      MYSQL_PASSWORD: zabbix
      MYSQL_DATABASE: zabbix
    ports:
      - "10051:10051"
    restart: unless-stopped
    networks:
      default:
        ipv4_address: "{{ hive_safe_zabbix_subnet | ipaddr(2) | ipaddr('address') }}"
  zabbix-web:
    image: zabbix/zabbix-web-nginx-mysql:ubuntu-trunk
    container_name: zabbix-web
    environment:
      TZ: "Asia/Tokyo"
      DB_SERVER_HOST: mariadb
      MYSQL_ROOT_PASSWORD: "{{lookup('password', hive_context_dir + '/registry_password length=15 chars=ascii_letters,digits')}}"
      MYSQL_USER: zabbix
      MYSQL_PASSWORD: zabbix
      MYSQL_DATABASE: zabbix
    ports:
      - "10052:8080"
    restart: unless-stopped
    networks:
      default:
        ipv4_address: "{{ hive_safe_zabbix_subnet | ipaddr(3) | ipaddr('address') }}"
  mariadb:
    image: mariadb:10.4
    container_name: mariadb
    environment:
      TZ: "Asia/Tokyo"
      MYSQL_ROOT_PASSWORD: "{{lookup('password', hive_context_dir + '/registry_password length=15 chars=ascii_letters,digits')}}"
      MYSQL_USER: zabbix
      MYSQL_PASSWORD: zabbix
      MYSQL_DATABASE: zabbix
      # maridb container spend long time to initialize timezone info of the database.
      # it can be skip by following envinronment variable.
      # MYSQL_INITDB_SKIP_TZINFO: "yes"
    volumes:
      - data:/var/lib/mysql
      - config:/etc/mysql/
    hostname: mariadb
    ##  Don't use charset utf8mb4, it cause folloing error for varchar(1024) key field in items table
    ## ** Creating 'zabbix' schema in MySQL
    ## ERROR 1071 (42000) at line 356: Specified key was too long; max key length is 3072 bytes
    command:
    - "--character-set-server=utf8mb3"
    - "--collation-server=utf8mb3_unicode_ci"
    expose:
      - "3306"
    restart: unless-stopped
    networks:
      default:
        ipv4_address: "{{ hive_safe_zabbix_subnet | ipaddr(4) | ipaddr('address') }}"

volumes:
  data:
  config:
networks:
  default:
    ipam:
      config:
      - subnet: "{{ hive_safe_zabbix_subnet }}"
