services:
  myddleware:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - ${myddleware_port:-30080}:80
    environment:
      - MYSQL_HOST=mysql
      - MYSQL_DATABASE=myddleware
      - MYSQL_ROOT_PASSWORD=${mysql_root_password:-secret}
    depends_on:
      mysql:
        condition: service_healthy
    restart: always

  mysql:
    image: mysql:5.7.33
    environment:
      - MYSQL_DATABASE=myddleware
      - MYSQL_ROOT_PASSWORD=${mysql_root_password:-secret}
      - MYSQL_USER=myddleware
      - MYSQL_PASSWORD=${mysql_password:-secret}
    command: 
      - --max_allowed_packet=524288000
      - --wait_timeout=100
      - --innodb_buffer_pool_size=1G
      - --innodb_flush_method=O_DIRECT
      - --innodb_flush_log_at_trx_commit=2
      - --innodb_buffer_pool_instances=4
      - --innodb_read_io_threads=4
      - --innodb_write_io_threads=4
    volumes:
      - mysql_data:/var/lib/mysql:delegated
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      interval: 10s
      timeout: 5s
      retries: 5
    restart: always

volumes:
  mysql_data: null