version: "3"

networks:
  traefik-proxy:
    external: true
  default:
    external: false

services:
  workadventure-front:
    container_name: workadventure-front
    image: thecodingmachine/nodejs:14
    restart: unless-stopped
    environment:
      DEBUG_MODE: "$DEBUG_MODE"
      JITSI_URL: "meet.jit.si"
      JITSI_PRIVATE_MODE: "$JITSI_PRIVATE_MODE"
      HOST: "0.0.0.0"
      NODE_ENV: development
      PUSHER_URL: //wa_pusher.warpzone.ms
      UPLOADER_URL: //wa_uploader.warpzone.ms
      ADMIN_URL: //workadventure.warpzone.ms
      STARTUP_COMMAND_1: ./templater.sh
      STARTUP_COMMAND_2: yarn install
      DISABLE_NOTIFICATIONS: "$DISABLE_NOTIFICATIONS"
      SKIP_RENDER_OPTIMIZATIONS: "$SKIP_RENDER_OPTIMIZATIONS"
      # Use TURN_USER/TURN_PASSWORD if your Coturn server is secured via hard coded credentials.
      # Advice: you should instead use Coturn REST API along the TURN_STATIC_AUTH_SECRET in the Back container
#      TURN_USER: ""
#      TURN_PASSWORD: ""
#      STUN_SERVER: "stun:stun.t-online.de:3478"
#      TURN_SERVER: "turn:turn.anyfirewall.com:443?transport=tcp,turns:turn.anyfirewall.com:443?transport=tcp"
#      TURN_USER: webrtc
#      TURN_PASSWORD: webrtc
      TURN_SERVER: "turn:coturn.workadventu.re:443,turns:coturn.workadventu.re:443"
      TURN_USER: workadventure
      TURN_PASSWORD: WorkAdventure123
      START_ROOM_URL: "$START_ROOM_URL"
      MAX_PER_GROUP: "$MAX_PER_GROUP"
      MAX_USERNAME_LENGTH: "$MAX_USERNAME_LENGTH"
    networks:
      - traefik-proxy
      - default
    command: yarn run start
    volumes:
      - ./front:/usr/src/app
    labels:
      - "traefik.enable=true"
      - "traefik.http.services.workadventure-front.loadbalancer.server.port=8080"
      - "traefik.http.routers.workadventure-front.rule=Host(`play.warpzone.ms`)"
      - "traefik.http.routers.workadventure-front.entryPoints=websecure"
      - "traefik.http.routers.workadventure-front.tls.certresolver=hetzner"
      - "traefik.http.routers.workadventure-front.service=workadventure-front"
      - "traefik.http.routers.link.rule= Host(`workadventure.warpzone.ms`)"
      - "traefik.http.routers.link.entryPoints=websecure"
      - "traefik.http.routers.link.tls.certresolver=hetzner"
      - "traefik.docker.network=traefik-proxy"


  workadventure-pusher:
    container_name: workadventure-pusher
    image: thecodingmachine/nodejs:14
    restart: unless-stopped
    command: yarn dev
    environment:
      DEBUG: "socket:*"
      STARTUP_COMMAND_1: yarn install
      SECRET_JITSI_KEY: "$SECRET_JITSI_KEY"
      SECRET_KEY: yourSecretKey
      ADMIN_API_TOKEN: "$ADMIN_API_TOKEN"
      API_URL: workadventure-back:50051
      JITSI_URL: $JITSI_URL
      JITSI_ISS: $JITSI_ISS
      FRONT_URL: https://play.warpzone.ms
      OPID_CLIENT_ID: $OPID_CLIENT_ID
      OPID_CLIENT_SECRET: $OPID_CLIENT_SECRET
      OPID_CLIENT_ISSUER: $OPID_CLIENT_ISSUER
    networks:
      - traefik-proxy
      - default
    volumes:
      - ./pusher:/usr/src/app
    labels:
      - "traefik.enable=true"
      - "traefik.http.services.workadventure-pusher.loadbalancer.server.port=8080"
      - "traefik.http.routers.workadventure-pusher.rule=Host(`wa_pusher.warpzone.ms`)"
      - "traefik.http.routers.workadventure-pusher.entryPoints=websecure"
      - "traefik.http.routers.workadventure-pusher.tls.certresolver=hetzner"
      - "traefik.http.routers.workadventure-pusher.service=workadventure-pusher"
      - "traefik.docker.network=traefik-proxy"

  workadventure-maps:
    container_name: workadventure-maps
    image: thecodingmachine/nodejs:12-apache
    restart: unless-stopped
    environment:
      DEBUG_MODE: "$DEBUG_MODE"
      HOST: "0.0.0.0"
      NODE_ENV: development
      #APACHE_DOCUMENT_ROOT: dist/
      #APACHE_EXTENSIONS: headers
      #APACHE_EXTENSION_HEADERS: 1
      STARTUP_COMMAND_0: sudo a2enmod headers
      STARTUP_COMMAND_1: yarn install
      STARTUP_COMMAND_2: yarn run dev &
    networks:
      - traefik-proxy
      - default
    volumes:
      - ./maps:/var/www/html
    labels:
      - "traefik.enable=true"
      - "traefik.http.services.workadventure-maps.loadbalancer.server.port=80"
      - "traefik.http.routers.workadventure-maps.rule=Host(`maps.warpzone.ms`)"
      - "traefik.http.routers.workadventure-maps.entryPoints=websecure"
      - "traefik.http.routers.workadventure-maps.tls.certresolver=hetzner"
      - "traefik.http.routers.workadventure-maps.service=workadventure-maps"
#      - "traefik.http.routers.workadventure-maps.middlewares=maps"
#      - "traefik.http.middlewares.maps.addprefix.prefix=/party"
      - "traefik.docker.network=traefik-proxy"

  workadventure-back:
    container_name: workadventure-back
    image: thecodingmachine/nodejs:12
    restart: unless-stopped
    command: yarn dev
    #command: yarn run profile
    environment:
      DEBUG: "*"
      STARTUP_COMMAND_1: yarn install
      SECRET_KEY: yourSecretKey
      SECRET_JITSI_KEY: "$SECRET_JITSI_KEY"
      ALLOW_ARTILLERY: "true"
      ADMIN_API_TOKEN: "$ADMIN_API_TOKEN"
      JITSI_URL: $JITSI_URL
      JITSI_ISS: $JITSI_ISS
      TURN_STATIC_AUTH_SECRET: SomeStaticAuthSecret
      MAX_PER_GROUP: "MAX_PER_GROUP"
      REDIS_HOST: redis
      NODE_ENV: development
    networks:
      - traefik-proxy
      - default
    volumes:
      - ./back:/usr/src/app
    labels:
      - "traefik.enable=true"
      - "traefik.http.services.workadventure-back.loadbalancer.server.port=8080"
      - "traefik.http.routers.workadventure-back.rule=Host(`wa_api.warpzone.ms`)"
      - "traefik.http.routers.workadventure-back.entryPoints=websecure"
      - "traefik.http.routers.workadventure-back.tls.certresolver=hetzner"
      - "traefik.http.routers.workadventure-back.service=workadventure-back"
      - "traefik.docker.network=traefik-proxy"

  workadventure-uploader:
    container_name: workadventure-uploader
    image: thecodingmachine/nodejs:12
    restart: unless-stopped
    command: yarn dev
    #command: yarn run profile
    environment:
      DEBUG: "*"
      STARTUP_COMMAND_1: yarn install
    networks:
      - traefik-proxy
      - default
    volumes:
      - ./uploader:/usr/src/app
    labels:
      - "traefik.enable=true"
      - "traefik.http.services.workadventure-uploader.loadbalancer.server.port=8080"
      - "traefik.http.routers.workadventure-uploader.rule=Host(`wa_uploader.warpzone.ms`)"
      - "traefik.http.routers.workadventure-uploader.entryPoints=websecure"
      - "traefik.http.routers.workadventure-uploader.tls.certresolver=hetzner"
      - "traefik.http.routers.workadventure-uploader.service=workadventure-uploader"

  workadventure-messages:
    container_name: workadventure-messages
    #image: thecodingmachine/nodejs:14
    image: thecodingmachine/workadventure-back-base:latest
    restart: unless-stopped
    environment:
      #STARTUP_COMMAND_0: sudo apt-get install -y inotify-tools
      STARTUP_COMMAND_1: yarn install
      STARTUP_COMMAND_2: yarn run proto:watch
    networks:
      - traefik-proxy
      - default
    volumes:
      - ./messages:/usr/src/app
      - ./back:/usr/src/back
      - ./front:/usr/src/front
      - ./pusher:/usr/src/pusher

  redis:
    image: redis:6

  redisinsight:
    image: redislabs/redisinsight:latest
    labels:
      - "traefik.http.routers.redisinsight.rule=Host(`redis.workadventure.localhost`)"
      - "traefik.http.routers.redisinsight.entryPoints=web"
      - "traefik.http.services.redisinsight.loadbalancer.server.port=8001"
      - "traefik.http.routers.redisinsight-ssl.rule=Host(`redis.workadventure.localhost`)"
      - "traefik.http.routers.redisinsight-ssl.entryPoints=websecure"
      - "traefik.http.routers.redisinsight-ssl.tls=true"
      - "traefik.http.routers.redisinsight-ssl.service=redisinsight"

#  coturn:
#    image: coturn/coturn:4.5.2
#    command:
#      - turnserver
#      #- -c=/etc/coturn/turnserver.conf
#      - --log-file=stdout
#      - --external-ip=$$(detect-external-ip)
#      - --listening-port=3478
#      - --min-port=10000
#      - --max-port=10010
#      - --tls-listening-port=5349
#      - --listening-ip=0.0.0.0
#      - --realm=coturn.workadventure.localhost
#      - --server-name=coturn.workadventure.localhost
#      - --lt-cred-mech
#      # Enable Coturn "REST API" to validate temporary passwords.
#      #- --use-auth-secret
#      #- --static-auth-secret=SomeStaticAuthSecret
#      #- --userdb=/var/lib/turn/turndb
#      - --user=workadventure:WorkAdventure123
#      # use real-valid certificate/privatekey files
#      #- --cert=/root/letsencrypt/fullchain.pem
#      #- --pkey=/root/letsencrypt/privkey.pem
#    network_mode: host

