version: '3'

services:
  mysql:
    image: mysql
    # https://dev.mysql.com/doc/refman/8.0/en/mysql-acid.html
    # https://dev.mysql.com/doc/refman/8.0/en/innodb-parameters.html#sysvar_innodb_flush_method
    # nosync only for unix, edit for local start on other systems
    command: --default-authentication-plugin=mysql_native_password --sync_binlog=0 --innodb_doublewrite=OFF  --innodb-flush-log-at-trx-commit=0 --innodb-flush-method=nosync
    ports:
      - '23306:3306'
    environment:
      - MYSQL_ROOT_PASSWORD=testrootpassword
      - MYSQL_DATABASE=knex_test
      - MYSQL_USER=testuser
      - MYSQL_PASSWORD=testpassword
    healthcheck:
      test:
        [
          'CMD',
          '/usr/bin/mysql',
          '-hlocalhost',
          '-utestuser',
          '-ptestpassword',
          '-e',
          'SELECT 1',
        ]
      interval: 30s
      timeout: 5s
      retries: 3
    restart: always
    volumes:
      - mysql_data:/var/lib/mysql
  waitmysql:
    image: mysql
    links:
      - mysql
    depends_on:
      - mysql
    entrypoint:
      - bash
      - -c
      - 'until /usr/bin/mysql -hmysql -utestuser -ptestpassword -e "SELECT 1"; do sleep 5; done'

volumes:
  mysql_data:
    driver_opts:
      type: tmpfs
      device: tmpfs
