# 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:
  nacos:
    image: nacos/nacos-server:2.0.0
    environment:
      - PREFER_HOST_MODE=hostname
      - MODE=standalone
      - NACOS_AUTH_ENABLE=true
      - JVM_XMS=512m
      - JVM_XMX=512m
      - JVM_XMN=256m

  seata-mysql:
    image: mysql:5.7
    environment:
      - MYSQL_DATABASE=seata-demo
      - MYSQL_ROOT_PASSWORD=helloworld
    expose:
      - 3306
    volumes:
      - ${_basedir}/deploy/docker-compose/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:latest
    environment:
      - SEATA_PORT=8091
      - STORE_MODE=file
    expose:
      - 8091
    depends_on:
      - seata-mysql

  storage-service:
    type: app
    basedir: dubbo-samples-seata-storage
    mainClass: org.apache.dubbo.samples.seata.StorageApplication
    systemProps:
      - nacos.address=nacos
      - nacos.port=8848
      - seata.address=seata-server
    jvmFlags:
      - "--add-opens java.base/java.lang.reflect=ALL-UNNAMED"
    waitPortsBeforeRun:
      - nacos:8848
      - seata-mysql:3306
      - seata-server:8091
    checkLog: "Current Spring Boot Application is await"
    checkPorts:
      - 20884
    depends_on:
      - seata-mysql
      - seata-server
      - nacos

  account-service:
    type: app
    basedir: dubbo-samples-seata-account
    mainClass: org.apache.dubbo.samples.seata.AccountApplication
    systemProps:
      - nacos.address=nacos
      - nacos.port=8848
      - seata.address=seata-server
    jvmFlags:
      - "--add-opens java.base/java.lang.reflect=ALL-UNNAMED"
    waitPortsBeforeRun:
      - nacos:8848
      - seata-mysql:3306
      - seata-server:8091
    checkLog: "Current Spring Boot Application is await"
    checkPorts:
      - 20881
    depends_on:
      - nacos
      - seata-mysql
      - seata-server

  order-service:
    type: app
    basedir: dubbo-samples-seata-order
    mainClass: org.apache.dubbo.samples.seata.OrderApplication
    systemProps:
      - nacos.address=nacos
      - nacos.port=8848
      - seata.address=seata-server
    jvmFlags:
      - "--add-opens java.base/java.lang.reflect=ALL-UNNAMED"
    waitPortsBeforeRun:
      - nacos:8848
      - seata-mysql:3306
      - seata-server:8091
    checkLog: "Current Spring Boot Application is await"
    checkPorts:
      - 20883
    depends_on:
      - nacos
      - seata-mysql
      - seata-server
      - account-service

  business-test:
    type: test
    basedir: dubbo-samples-seata-business
    tests:
      - "**/*IT.class"
    systemProps:
      - nacos.address=nacos
      - nacos.port=8848
      - seata.address=seata-server
    jvmFlags:
      - "--add-opens java.base/java.lang.reflect=ALL-UNNAMED"
    waitPortsBeforeRun:
      - nacos:8848
      - seata-mysql:3306
      - seata-server:8091
      - storage-service:20884
      - account-service:20881
      - order-service:20883
    depends_on:
      - nacos
      - seata-mysql
      - seata-server
      - order-service
      - account-service
      - storage-service

