# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

timeout: 300

# global system props for all service
systemProps:
  - mysql.address=seata-mysql
  - mysql.port=3306

services:
  zookeeper:
    image: zookeeper:latest
    expose:
      - 2181

  seata-mysql:
    image: mysql:5.7
    environment:
      - MYSQL_DATABASE=seata-demo
      - MYSQL_ROOT_PASSWORD=helloworld
    expose:
      - 3306
    volumes:
      - ${_basedir}/src/main/resources/docker/mysql/sql:/docker-entrypoint-initdb.d
    healthcheck:
      # mysql host MUST be ip address, if the host is localhost, may connect via socket file, the port will be ignored
      test: ["CMD", "mysqladmin" ,"ping", "-h", "127.0.0.1"]
      interval: 5s
      timeout: 5s
      retries: 20

  seata-server:
    #build: ${_basedir}/src/main/resources/docker/seata
    #removeOnExit: true
    image: seataio/seata-server:${seata.version}
    volumes:
      - ${_basedir}/src/main/resources/docker/seata/conf:/root/seata-config
    expose:
      - 8091
    depends_on:
      - seata-mysql

  storage-service:
    type: app
    basedir: .
    mainClass: org.apache.dubbo.samples.starter.DubboStorageServiceStarter
    systemProps:
      - zookeeper.address=zookeeper
      - zookeeper.port=2181
      - seata.address=seata-server:8091
    waitPortsBeforeRun:
      - zookeeper:2181
      - seata-mysql:3306
      - seata-server:8091
    checkPorts:
      - 20882
    checkLog: 'storage service started'
    depends_on:
      - seata-mysql
      - seata-server

  account-service:
    type: app
    basedir: .
    mainClass: org.apache.dubbo.samples.starter.DubboAccountServiceStarter
    systemProps:
      - zookeeper.address=zookeeper
      - zookeeper.port=2181
      - seata.address=seata-server:8091
    waitPortsBeforeRun:
      - zookeeper:2181
      - seata-mysql:3306
      - seata-server:8091
    checkPorts:
      - 20881
    checkLog: 'account service started'
    depends_on:
      - seata-mysql
      - seata-server

  order-service:
    type: app
    basedir: .
    mainClass: org.apache.dubbo.samples.starter.DubboOrderServiceStarter
    systemProps:
      - zookeeper.address=zookeeper
      - zookeeper.port=2181
      - seata.address=seata-server:8091
    waitPortsBeforeRun:
      - zookeeper:2181
      - seata-mysql:3306
      - seata-server:8091
    checkPorts:
      - 20883
    checkLog: 'order service started'
    depends_on:
      - seata-mysql
      - seata-server
      - account-service

  transaction-test:
    type: test
    basedir: .
    tests:
      - "**/*IT.class"
    systemProps:
      - zookeeper.address=zookeeper
      - zookeeper.port=2181
      - seata.address=seata-server:8091
    waitPortsBeforeRun:
      - zookeeper:2181
      - storage-service:20882
      - account-service:20881
      - order-service:20883
      - seata-mysql:3306
      - seata-server:8091
    depends_on:
      - order-service
      - account-service
      - storage-service

