# Copyright Broadcom, Inc. All Rights Reserved.
# SPDX-License-Identifier: APACHE-2.0

services:
  mysql-master:
    image: docker.io/bitnami/mysql:9.6
    ports:
      - '3306'
    volumes:
      - 'mysql_master_data:/bitnami/mysql/data'
    environment:
      - MYSQL_REPLICATION_MODE=master
      - MYSQL_REPLICATION_USER=repl_user
      - MYSQL_USER=my_user
      - MYSQL_DATABASE=my_database
      # ALLOW_EMPTY_PASSWORD is recommended only for development.
      - ALLOW_EMPTY_PASSWORD=yes
      - MYSQL_ROOT_PASSWORD=my_root_password
    healthcheck:
      test: ['CMD', '/opt/bitnami/scripts/mysql/healthcheck.sh']
      interval: 15s
      timeout: 5s
      retries: 6

  mysql-slave:
    image: docker.io/bitnami/mysql:9.6
    ports:
      - '3306'
    depends_on:
      - mysql-master
    environment:
      - MYSQL_REPLICATION_MODE=slave
      - MYSQL_REPLICATION_USER=repl_user
      - MYSQL_USER=my_user
      - MYSQL_DATABASE=my_database
      - MYSQL_MASTER_HOST=mysql-master
      - MYSQL_MASTER_PORT_NUMBER=3306
      - MYSQL_MASTER_ROOT_PASSWORD=my_root_password
      # ALLOW_EMPTY_PASSWORD is recommended only for development.
      - ALLOW_EMPTY_PASSWORD=yes
      # In case of missing binary files on master, use `true` to reset those binary files. Creating a previous backup is recommended.
      - MYSQL_REPLICATION_SLAVE_DUMP=false
    healthcheck:
      test: ['CMD', '/opt/bitnami/scripts/mysql/healthcheck.sh']
      interval: 15s
      timeout: 5s
      retries: 6

volumes:
  mysql_master_data:
    driver: local
