version: "3"

volumes:
  conf:
  vhost:
  html:
  dhparam:
  certs:

services:
  nginx-proxy:
    image: jwilder/nginx-proxy
    container_name: gamedash_nginx-proxy
    restart: unless-stopped
    labels:
      - "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - conf:/etc/nginx/conf.d
      - vhost:/etc/nginx/vhost.d
      - html:/usr/share/nginx/html
      - dhparam:/etc/nginx/dhparam
      - certs:/etc/nginx/certs:ro
      - /var/run/docker.sock:/tmp/docker.sock:ro
    depends_on:
      - backend
      - frontend

  letsencrypt:
    image: jrcs/letsencrypt-nginx-proxy-companion
    container_name: gamedash_nginx-proxy-le
    restart: unless-stopped
    volumes:
      - conf:/etc/nginx/conf.d
      - vhost:/etc/nginx/vhost.d
      - html:/usr/share/nginx/html
      - dhparam:/etc/nginx/dhparam
      - certs:/etc/nginx/certs:rw
      - /var/run/docker.sock:/var/run/docker.sock:ro
    depends_on:
      - nginx-proxy

  mysql:
    image: mysql
    command: --default-authentication-plugin=mysql_native_password
    container_name: gamedash_db
    restart: unless-stopped
    volumes:
      - ./db/data:/var/lib/mysql
      - ./db/config.cnf:/etc/mysql/conf.d/mysql.cnf
    environment:
      - MYSQL_ROOT_PASSWORD=${DB_MYSQL_ROOT_PASS}
      - MYSQL_DATABASE=${DB_MYSQL_DATABASE}
      - MYSQL_USER=${DB_MYSQL_USER}
      - MYSQL_PASSWORD=${DB_MYSQL_PASS}

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: phpmyadmin
    environment:
     - PMA_ARBITRARY=1
    restart: always
    ports:
     - 1337:80
    volumes:
     - /sessions
     - ./config/phpmyadmin/config.php:/var/www/html/config.inc.php

  backend:
    image: gamedash/backend:latest
    container_name: gamedash_backend
    restart: unless-stopped
    volumes:
      - ./config/backend/production.json:/var/www/html/config/production.json
      - ./config/backend/development.json:/var/www/html/config/development.json
      - ./logs/backend:/var/log/gamedash
      - ./sdk/modules/installed:/home/sdk/module/installed
      - ./translation/languages:/var/www/html/userland/translation/language/languages
      - ./storage/backend/persistent:/home/storage/persistent
    environment:
      - IS_DOCKER=true
      - VIRTUAL_HOST=${BACKEND_HOST}
      - LETSENCRYPT_HOST=${BACKEND_HOST}
      - FRONTEND_HOST=${FRONTEND_HOST}
      - BACKEND_HOST=${BACKEND_HOST}
      - RELAY_HOST=${RELAY_HOST}
      - RELAY_HOST_SOCKET_PORT=443
      - RELAY_HOST_API_PORT=2152
      - SDK_INSTALLED_MODULE_DIRECTORY=/home/sdk/module/installed
      - MODE=${MODE}
      - IS_SECURE=true
      - DB_MYSQL_ROOT_PASSWORD=${DB_MYSQL_ROOT_PASS}
      - DB_MYSQL_DATABASE=${DB_MYSQL_DATABASE}
      - DB_MYSQL_USER=${DB_MYSQL_USER}
      - DB_MYSQL_PASSWORD=${DB_MYSQL_PASS}
    depends_on:
      - mysql

  frontend:
    image: gamedash/frontend:latest
    container_name: gamedash_frontend
    restart: unless-stopped
    volumes:
      - ./config/frontend/config.json:/var/www/html/config/config.json
      - ./config/frontend/preloaded.js:/var/www/html/config/preloaded.js
      - ./assets/favicon:/var/www/html/favicon
    environment:
      - VIRTUAL_HOST=${FRONTEND_HOST}
      - LETSENCRYPT_HOST=${FRONTEND_HOST}
      - IS_SECURE=true
      - API_DOMAIN=${BACKEND_HOST}
      - COOKIE_DOMAIN=.${FRONTEND_HOST}
    depends_on:
      - backend

  relay:
    image: gamedash/relay:latest
    container_name: gamedash_relay
    restart: unless-stopped
    ports:
      - "2152:2152"
    environment:
      - VIRTUAL_HOST=${RELAY_HOST}
      - LETSENCRYPT_HOST=${RELAY_HOST}
      - VIRTUAL_PORT=2148
      - RELAY_JAVA_ARGS=${RELAY_JAVA_ARGS}

  backend_redis:
    image: redis
    container_name: gamedash_backend_redis
    restart: unless-stopped
    volumes:
      - ./config/backend/redis.conf:/usr/local/etc/redis/redis.conf
    command:
      - /usr/local/etc/redis/redis.conf
