x-go-build-args: &go-build-args
  GOPROXY: "${GOPROXY:-https://goproxy.cn|https://proxy.golang.org|direct}"
  GOSUMDB: "${GOSUMDB:-sum.golang.org}"

services:
  gateway-service:
    build:
      context: .
      dockerfile: services/gateway-service/Dockerfile
      args: *go-build-args
    container_name: gateway-service
    environment:
      TZ: UTC
    ports:
      - "13000:13000"
    depends_on:
      room-service:
        condition: service_healthy
      user-service:
        condition: service_healthy
      game-service:
        condition: service_healthy
      redis:
        condition: service_healthy
    healthcheck:
      test: ["CMD-SHELL", "wget -q -O - http://127.0.0.1:13000/healthz/ready >/dev/null"]
      interval: 5s
      timeout: 3s
      retries: 20
      start_period: 10s

  room-service:
    build:
      context: .
      dockerfile: services/room-service/Dockerfile
      args: *go-build-args
    container_name: room-service
    environment:
      TZ: UTC
    ports:
      - "13001:13001"
      - "13101:13101"
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_healthy
      wallet-service:
        condition: service_healthy
    healthcheck:
      test: ["CMD-SHELL", "wget -q -O - http://127.0.0.1:13101/healthz/ready >/dev/null"]
      interval: 5s
      timeout: 3s
      retries: 20
      start_period: 10s

  wallet-service:
    build:
      context: .
      dockerfile: services/wallet-service/Dockerfile
      args: *go-build-args
    container_name: wallet-service
    environment:
      TZ: UTC
    ports:
      - "13004:13004"
      - "13104:13104"
    depends_on:
      mysql:
        condition: service_healthy
      user-service:
        condition: service_healthy
      activity-service:
        condition: service_healthy
    healthcheck:
      test: ["CMD-SHELL", "wget -q -O - http://127.0.0.1:13104/healthz/ready >/dev/null"]
      interval: 5s
      timeout: 3s
      retries: 20
      start_period: 10s

  user-service:
    build:
      context: .
      dockerfile: services/user-service/Dockerfile
      args: *go-build-args
    container_name: user-service
    environment:
      TZ: UTC
    ports:
      - "13005:13005"
      - "13105:13105"
    depends_on:
      mysql:
        condition: service_healthy
    healthcheck:
      test: ["CMD-SHELL", "wget -q -O - http://127.0.0.1:13105/healthz/ready >/dev/null"]
      interval: 5s
      timeout: 3s
      retries: 20
      start_period: 10s

  activity-service:
    build:
      context: .
      dockerfile: services/activity-service/Dockerfile
      args: *go-build-args
    container_name: activity-service
    environment:
      TZ: UTC
    ports:
      - "13006:13006"
      - "13106:13106"
    depends_on:
      mysql:
        condition: service_healthy
      user-service:
        condition: service_healthy
    healthcheck:
      test: ["CMD-SHELL", "wget -q -O - http://127.0.0.1:13106/healthz/ready >/dev/null"]
      interval: 5s
      timeout: 3s
      retries: 20
      start_period: 10s

  cron-service:
    build:
      context: .
      dockerfile: services/cron-service/Dockerfile
      args: *go-build-args
    container_name: cron-service
    environment:
      TZ: UTC
    ports:
      - "13007:13007"
      - "13107:13107"
    depends_on:
      mysql:
        condition: service_healthy
      user-service:
        condition: service_healthy
      activity-service:
        condition: service_healthy
    healthcheck:
      test: ["CMD-SHELL", "wget -q -O - http://127.0.0.1:13107/healthz/ready >/dev/null"]
      interval: 5s
      timeout: 3s
      retries: 20
      start_period: 10s

  game-service:
    build:
      context: .
      dockerfile: services/game-service/Dockerfile
      args: *go-build-args
    container_name: game-service
    environment:
      TZ: UTC
    ports:
      - "13008:13008"
      - "13108:13108"
    depends_on:
      mysql:
        condition: service_healthy
      wallet-service:
        condition: service_healthy
      user-service:
        condition: service_healthy
    healthcheck:
      test: ["CMD-SHELL", "wget -q -O - http://127.0.0.1:13108/healthz/ready >/dev/null"]
      interval: 5s
      timeout: 3s
      retries: 20
      start_period: 10s

  mysql:
    image: mysql:8.4
    container_name: hyapp-mysql
    command:
      - "--character-set-server=utf8mb4"
      - "--collation-server=utf8mb4_unicode_ci"
      - "--default-time-zone=+00:00"
    environment:
      TZ: UTC
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: hyapp_room
      MYSQL_USER: hyapp
      MYSQL_PASSWORD: hyapp
    ports:
      - "23306:3306"
    volumes:
      - mysql-data:/var/lib/mysql
      - ./services/room-service/deploy/mysql/initdb/001_room_service.sql:/docker-entrypoint-initdb.d/001_room_service.sql:ro
      - ./services/user-service/deploy/mysql/initdb/001_user_service.sql:/docker-entrypoint-initdb.d/002_user_service.sql:ro
      - ./services/wallet-service/deploy/mysql/initdb/001_wallet_service.sql:/docker-entrypoint-initdb.d/003_wallet_service.sql:ro
      - ./services/activity-service/deploy/mysql/initdb/001_activity_service.sql:/docker-entrypoint-initdb.d/004_activity_service.sql:ro
      - ./deploy/mysql/initdb/005_utf8mb4_chinese_support.sql:/docker-entrypoint-initdb.d/005_utf8mb4_chinese_support.sql:ro
      - ./deploy/mysql/initdb/006_admin_database.sql:/docker-entrypoint-initdb.d/006_admin_database.sql:ro
      - ./deploy/mysql/initdb/007_resource_group_wallet_asset_items.sql:/docker-entrypoint-initdb.d/007_resource_group_wallet_asset_items.sql:ro
      - ./services/cron-service/deploy/mysql/initdb/001_cron_service.sql:/docker-entrypoint-initdb.d/008_cron_service.sql:ro
      - ./services/game-service/deploy/mysql/initdb/001_game_service.sql:/docker-entrypoint-initdb.d/009_game_service.sql:ro
      - ./deploy/mysql/initdb/999_local_grants.sql:/docker-entrypoint-initdb.d/999_local_grants.sql:ro
    healthcheck:
      test: ["CMD-SHELL", "mysqladmin ping -h 127.0.0.1 -uroot -proot --silent"]
      interval: 5s
      timeout: 3s
      retries: 30

  redis:
    image: redis:7.4-alpine
    container_name: hyapp-redis
    environment:
      TZ: UTC
    ports:
      - "13379:6379"
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 3s
      retries: 30

volumes:
  mysql-data:
