version: "3"

services:
  romm:
    image: zurdi15/romm:2.3.1
    container_name: romm
    environment:
      - ROMM_DB_DRIVER=mariadb
      - DB_HOST=romm-db
      - DB_PORT=3306
      - DB_USER=tipi
      - DB_NAME=romm
      - DB_PASSWD=${ROMM_MYSQL_PASSWORD}
      - IGDB_CLIENT_ID=${ROMM_IGDB_CLIENT_ID}
      - IGDB_CLIENT_SECRET=${ROMM_IGDB_CLIENT_SECRET}
      - STEAMGRIDDB_API_KEY="${ROMM_STEAMGRIDDB_API_KEY}"
    restart: unless-stopped
    volumes:
      - ${ROOT_FOLDER_HOST}/media/data/roms:/romm/library
      - ${APP_DATA_DIR}/data/romm-resources:/romm/resources
      - ${APP_DATA_DIR}/data/config.yml:/romm/config.yml
    ports:
      - ${APP_PORT}:8080
    depends_on:
      - romm-db
    networks:
      - tipi_main_network
    labels:
      # Main
      traefik.enable: true
      traefik.http.middlewares.romm-web-redirect.redirectscheme.scheme: https
      traefik.http.services.romm.loadbalancer.server.port: 8080
      # Web
      traefik.http.routers.romm-insecure.rule: Host(`${APP_DOMAIN}`)
      traefik.http.routers.romm-insecure.entrypoints: web
      traefik.http.routers.romm-insecure.service: romm
      traefik.http.routers.romm-insecure.middlewares: romm-web-redirect
      # Websecure
      traefik.http.routers.romm.rule: Host(`${APP_DOMAIN}`)
      traefik.http.routers.romm.entrypoints: websecure
      traefik.http.routers.romm.service: romm
      traefik.http.routers.romm.tls.certresolver: myresolver
      # Local domain
      traefik.http.routers.romm-local-insecure.rule: Host(`romm.${LOCAL_DOMAIN}`)
      traefik.http.routers.romm-local-insecure.entrypoints: web
      traefik.http.routers.romm-local-insecure.service: romm
      traefik.http.routers.romm-local-insecure.middlewares: romm-web-redirect
      # Local domain secure
      traefik.http.routers.romm-local.rule: Host(`romm.${LOCAL_DOMAIN}`)
      traefik.http.routers.romm-local.entrypoints: websecure
      traefik.http.routers.romm-local.service: romm
      traefik.http.routers.romm-local.tls: true

  romm-db:
    image: lscr.io/linuxserver/mariadb:latest
    container_name: romm-db
    environment:
      - MYSQL_ROOT_PASSWORD=${ROMM_MYSQL_PASSWORD}
      - MYSQL_DATABASE=romm
      - MYSQL_USER=tipi
      - MYSQL_PASSWORD=${ROMM_MYSQL_PASSWORD}
    volumes:
      - ${APP_DATA_DIR}/data/mysql/config:/config
    restart: "unless-stopped"
    networks:
      - tipi_main_network
