services:
 mysql-server:
  image: "${MYSQL_IMAGE}:${MYSQL_IMAGE_TAG}"
  command:
   - mysqld
   - --skip-mysqlx
   - --character-set-server=utf8mb4
   - --collation-server=utf8mb4_bin
# Only during upgrade from versions prior 6.4 and new installations (schema deployment)
   - --log_bin_trust_function_creators=1
# Use TLS encryption for connections to database
#   - --require-secure-transport
#   - --ssl-ca=/run/secrets/root-ca.pem
#   - --ssl-cert=/run/secrets/server-cert.pem
#   - --ssl-key=/run/secrets/server-key.pem
  restart: "${RESTART_POLICY}"
  attach: false
  volumes:
   - ${DATA_DIRECTORY}/var/lib/mysql:/var/lib/mysql:rw
   - ${ENV_VARS_DIRECTORY}/mysql_init/init_proxy_db.sql:/docker-entrypoint-initdb.d/mysql_init_proxy.sql:ro
#   - mysql_socket:/var/run/mysqld/
  env_file:
   - path: ${ENV_VARS_DIRECTORY}/.env_db_mysql
     required: true
   - path: ${ENV_VARS_DIRECTORY}/.env_db_mysql_override
     required: false
  environment:
   - MYSQL_ROOT_PASSWORD_FILE=/run/secrets/MYSQL_ROOT_PASSWORD
  secrets:
   - MYSQL_USER
   - MYSQL_PASSWORD
   - MYSQL_ROOT_PASSWORD
#   - server-key.pem
#   - server-cert.pem
#   - root-ca.pem
  stop_grace_period: 1m
  networks:
   database:
    aliases:
     - mysql-server

 postgres-server:
  image: "${POSTGRESQL_IMAGE}:${POSTGRESQL_IMAGE_TAG}"
#  command: -c ssl=on -c ssl_cert_file=/run/secrets/server-cert.pem -c ssl_key_file=/run/secrets/server-key.pem -c ssl_ca_file=/run/secrets/root-ca.pem
  restart: "${RESTART_POLICY}"
  attach: false
  volumes:
   - ${DATA_DIRECTORY}/var/lib/postgresql/data:/var/lib/postgresql/data:rw
   - ${ENV_VARS_DIRECTORY}/.ZBX_DB_CA_FILE:/run/secrets/root-ca.pem:ro
   - ${ENV_VARS_DIRECTORY}/.ZBX_DB_CERT_FILE:/run/secrets/server-cert.pem:ro
   - ${ENV_VARS_DIRECTORY}/.ZBX_DB_KEY_FILE:/run/secrets/server-key.pem:ro
#   - pgsql_socket:/var/run/postgresql/
  env_file:
   - path: ${ENV_VARS_DIRECTORY}/.env_db_pgsql
     required: true
   - path: ${ENV_VARS_DIRECTORY}/.env_db_pgsql_override
     required: false
  secrets:
   - POSTGRES_USER
   - POSTGRES_PASSWORD
  stop_grace_period: 1m
  networks:
   database:
    aliases:
     - postgres-server

 db-data-mysql:
  image: "${BUSYBOX_IMAGE}:${BUSYBOX_IMAGE_TAG}"
  volumes:
   - ${DATA_DIRECTORY}/var/lib/mysql:/var/lib/mysql:rw

 db-data-pgsql:
  image: "${BUSYBOX_IMAGE}:${BUSYBOX_IMAGE_TAG}"
  attach: false
  volumes:
   - ${DATA_DIRECTORY}/var/lib/postgresql/data:/var/lib/postgresql/data:rw

 elasticsearch:
  image: "${ELASTICSEARCH_IMAGE}:${ELASTICSEARCH_IMAGE_TAG}"
  restart: "${RESTART_POLICY}"
  attach: false
  profiles:
   - elasticsearch
  environment:
   - transport.host=0.0.0.0
   - discovery.zen.minimum_master_nodes=1
  networks:
   database:
    aliases:
     - elasticsearch
