networks:
  nw-letto:
    external: true

services:
  setup:
    image: lettohub/letto-setup:stable
    restart: always
    networks:
      - nw-letto
    deploy:
      resources:
        limits:
          memory: "${MEMORY_LIMIT:-1G}"
    logging:
      driver: "json-file"
      options:
        max-size: "2m"
        max-file: "3"
    hostname: letto-setup
    container_name: letto-setup
    healthcheck:
      test: ["CMD", "bash", "/scripts/healthcheck.sh"]
      interval: 1m30s
      timeout: 20s
      retries: 3
      start_period: 300s
    environment:
      - TZ=${TIMEZONE:-Europe/Berlin}
      - UNHEALTHY_RETRIES=${SETUP_UNHEALTHY_RETRIES:-${UNHEALTHY_RETRIES:-20}}
      - ADMIN_PASSWORD=${ADMIN_PASSWORD:-}
      - ADMIN_PASSWORD_ENCRYPTED=${ADMIN_PASSWORD_ENCRYPTED:-}
      - LETTO_UID=${LETTO_UID:-1000}
      - RUN_AS_ROOT=${RUN_AS_ROOT:-true}
      - letto_local_restkey=${LETTO_RESTKEY:-}
      - jwt_secret=${JWT_SECRET:-YWJj}
      - jwt_expiration=${JWT_EXPIRATION_MS:-600000}
      - jwt_refresh_time=${JWT_REFRESH_TIME_MS:-300000}
      - server_secret=${SERVER_SECRET:-YWJj}
      - letto_local_privatkey=${LETTO_LOCAL_PRIVATE_KEY:-}
      - letto_local_publickey=${LETTO_LOCAL_PUBLIC_KEY:-}
      - letto_user_user_password=${SERVICE_USER_PASSWORD:-}
      - letto_user_gast_password=${SERVICE_GAST_PASSWORD:-}
      - letto_user_admin_password=${SERVICE_ADMIN_PASSWORD:-}
      - letto_login_uri=${LETTO_LOGIN_URI:-http://letto-login.nw-letto:8095}
      - letto_license_server=${LETTO_LICENSE_SERVER:-https://license.letto.at}
      - JAVA_OPTS=${JAVA_OPTS_SETUP:--Xms50m -Xmx300m}
      - setup_debug=${DEBUG:-false}
      - setup_stable=${STABLE:-false}
      - setup_agent=false
      - debug=${DEBUG_SETUP:-${DEBUG:-false}}
      - springdoc.api-docs.path=/config/v3/api-docs
      - springdoc.swagger-ui.path=/config/swagger-ui.html
      - WATCHDOG=${WATCHDOG:-ON}
      - WATCHDOG_MAX_CPU=${WATCHDOG_MAX_CPU:-400}
      - WATCHDOG_MAX_TIME=${WATCHDOG_MAX_TIME:-130}
      - REDIS_PASSWORD=${REDIS_PASSWORD:-${MYSQL_ROOT_PASSWORD}}
      - REDIS_DEFAULT_DATABASE=${LOGIN_REDIS_DEFAULT_DATABASE:-1}
      - MONGO_ROOT_PASSWORD=${MONGO_ROOT_PASSWORD:-${MYSQL_ROOT_PASSWORD}}
      - MONGO_DEFAULT_DATABASE=${SETUP_MONGO_DEFAULT_DATABASE:-setup}
      - BACKUP_DATABASES_ADDITIONAL=${BACKUP_DATABASES_ADDITIONAL:-}

    ports:
      - "${PORT_SETUP:-3096}:9096"
      - "${DEBUG_PORT_SETUP:-5096}:5096"

    volumes:
      # Verzeichnis in dem docker-compose gestartet wurde
      - ${SETUP_COMPOSE:-.}:/host
      # Zugriff auf /opt/letto des Host über /opt/letto
      - ${LETTO_PATH:-/opt/letto}:/opt/letto
      # Zugriff auf das Compose-Verzeichnis für letto
      - ${LETTO_COMPOSE:-/opt/letto/docker/compose/letto}:/letto_compose
      # Verbindung zu Docker vom Host um aus dem Setup heraus eine Container starten zu können
      - /var/run/docker.sock:/var/run/docker.sock
      # Logfiles vom Setup-Service
      - ${VOLUME_LOG:-/opt/letto/docker/storage/log}/setup:/opt/letto/log