x-params: &default-params
  image: ghcr.io/giongto35/cloud-game/cloud-game:${IMAGE_TAG:-master}
  network_mode: "host"
  privileged: true
  restart: always
  security_opt:
    - seccomp=unconfined
  logging:
    driver: "journald"
x-worker: &worker
  depends_on:
    - coordinator
  command: ./worker
  volumes:
    - ${APP_DIR:-/cloud-game}/cache:/usr/local/share/cloud-game/assets/cache
    - ${APP_DIR:-/cloud-game}/cores:/usr/local/share/cloud-game/assets/cores
    - ${APP_DIR:-/cloud-game}/games:/usr/local/share/cloud-game/assets/games
    - ${APP_DIR:-/cloud-game}/libretro:/usr/local/share/cloud-game/libretro
    - ${APP_DIR:-/cloud-game}/home:/root/.cr
    - x11:/tmp/.X11-unix
  healthcheck:
    test: curl -f https://cloudretro.io/echo || exit 1
    interval: 1m
    timeout: 10s
    retries: 3
    start_period: 40s
    start_interval: 5s

services:

  coordinator:
    <<: *default-params
    command: ./coordinator
    environment:
      - CLOUD_GAME_LIBRARY_BASEPATH=/usr/local/share/cloud-game/assets/games
    volumes:
      - ${APP_DIR:-/cloud-game}/cache:/usr/local/share/cloud-game/assets/cache
      - ${APP_DIR:-/cloud-game}/games:/usr/local/share/cloud-game/assets/games
      - ${APP_DIR:-/cloud-game}/home:/root/.cr

  worker01:
    <<: [ *default-params, *worker ]
    environment:
      - DISPLAY=:99
      - MESA_GL_VERSION_OVERRIDE=4.5
      - CLOUD_GAME_LIBRARY_BASEPATH=/usr/local/share/cloud-game/assets/games
      - CLOUD_GAME_EMULATOR_LIBRETRO_CORES_PATHS_LIBS=/usr/local/share/cloud-game/assets/cores
      - CLOUD_GAME_WORKER_SERVER_TLS_DOMAIN=cloudretro.io
      - CLOUD_GAME_WORKER_SERVER_TLS_ADDRESS=:444
    healthcheck:
      test: curl -f https://cloudretro.io:444/echo || exit 1
  worker02:
    <<: [ *default-params, *worker ]
    environment:
      - CLOUD_GAME_WORKER_SERVER_TLS_ADDRESS=:445
      - DISPLAY=:99
      - MESA_GL_VERSION_OVERRIDE=4.5
      - CLOUD_GAME_LIBRARY_BASEPATH=/usr/local/share/cloud-game/assets/games
      - CLOUD_GAME_EMULATOR_LIBRETRO_CORES_PATHS_LIBS=/usr/local/share/cloud-game/assets/cores
      - CLOUD_GAME_WORKER_SERVER_TLS_DOMAIN=cloudretro.io
    healthcheck:
      test: curl -f https://cloudretro.io:445/echo || exit 1
  worker03:
    <<: [ *default-params, *worker ]
    environment:
      - DISPLAY=:99
      - MESA_GL_VERSION_OVERRIDE=4.5
      - CLOUD_GAME_LIBRARY_BASEPATH=/usr/local/share/cloud-game/assets/games
      - CLOUD_GAME_EMULATOR_LIBRETRO_CORES_PATHS_LIBS=/usr/local/share/cloud-game/assets/cores
      - CLOUD_GAME_WORKER_SERVER_TLS_DOMAIN=cloudretro.io
      - CLOUD_GAME_WORKER_SERVER_TLS_ADDRESS=:446
    healthcheck:
      test: curl -f https://cloudretro.io:446/echo || exit 1
  worker04:
    <<: [ *default-params, *worker ]
    environment:
      - DISPLAY=:99
      - MESA_GL_VERSION_OVERRIDE=4.5
      - CLOUD_GAME_LIBRARY_BASEPATH=/usr/local/share/cloud-game/assets/games
      - CLOUD_GAME_EMULATOR_LIBRETRO_CORES_PATHS_LIBS=/usr/local/share/cloud-game/assets/cores
      - CLOUD_GAME_WORKER_SERVER_TLS_DOMAIN=cloudretro.io
      - CLOUD_GAME_WORKER_SERVER_TLS_ADDRESS=:447
    healthcheck:
      test: curl -f https://cloudretro.io:447/echo || exit 1

  xvfb:
    image: kcollins/xvfb:latest
    volumes:
      - x11:/tmp/.X11-unix
    command: [ ":99", "-screen", "0", "320x240x16" ]

volumes:
  x11:
