# LeTTo Login-Service und Proxy
networks:
  nw-letto:
    external: true
  nw-proxy:
    external: true

volumes:
  certs:
    name: certs
    external: true
  certs-data:
    name: certs-data
    external: true

# Der Name bestimmt das Projekt und sollte bei jeder yml-Datei unterschiedlich sein - er kann mit -p bei docker-compose überschrieben werden
name: letto

services:
  # login-service
  login:
    image: lettohub/letto-service-login:stable
    restart: always
    networks:
      - nw-letto
    deploy:
      resources:
        limits:
          memory: "${LOGIN_MEMORY_LIMIT:-1G}"
    logging:
      driver: "json-file"
      options:
        max-size: "2m"
        max-file: "3"
    hostname: letto-login
    container_name: letto-login
    volumes:
      - ${VOLUME_LOG:-/opt/letto/docker/storage/log}/login:/log
      - ${VOLUME_LOGIN:-/opt/letto/docker/storage/login}:/opt/letto/login
    environment:
      - TZ=${TIMEZONE:-Europe/Berlin}
      - LC_ALL=${LOCALE:-de_DE.UTF-8}
      - UNHEALTHY_RETRIES=${LOGIN_UNHEALTHY_RETRIES:-${UNHEALTHY_RETRIES:-20}}
      - letto_schulen=${LETTO_SCHULEN}
      - jwt_secret=${JWT_SECRET:-YWJj}
      - server_secret=${SERVER_SECRET:-YWJj}
      - use_http=${USE_HTTP:-0}
      - servername=${SERVER_NAME}
      - 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_license_server=${LETTO_LICENSE_SERVER:-https://license.letto.at/lettolicense}
      - letto_setup_uri=${LETTO_SETUP_URI:-http://letto-setup.nw-letto:8096}
      - JAVA_OPTS=${JAVA_OPTS_LOGIN:--Xms50m -Xmx100m}
      - debug=${DEBUG_LOGIN:-${DEBUG:-false}}
      - logRedisError=${LOG_REDIS_ERROR_LOGIN:-${LOG_REDIS_ERROR:-false}}

      - logging.level.root=${LOGIN_LEVEL:-INFO}
      - logging.level.org.springframework.web=${LOGIN_LEVEL:-INFO}
      - LETTO_PREVIEW_SCHOOLS=${LETTO_PREVIEW_SCHOOLS:-}

      - spring.mail.host=${spring_mail_host:-}
      - spring.mail.port=${spring_mail_port:-}
      - spring.mail.username=${spring_mail_username:-}
      - spring.mail.password=${spring_mail_password:-}
      - spring.mail.smtp.auth=${spring_mail_properties_mail_smtp_auth:-true}
      - spring.mail.properties.mail.smtp.starttls.enable=${spring_mail_properties_mail_smtp_starttls_enable:-true}
      - spring.mail.properties.mail.smtp.ssl.enable=${spring_mail_properties_mail_smtp_ssl_enable:-true}
      - spring.mail.properties.mail.debug=${spring_mail_properties_mail_debug:-false}
      - spring.mail.address.noreply=${spring_mail_address_noreply:-norelpy@schule.com}
      - spring.mail.address.reply=${spring_mail_address_reply:-relpy@schule.com}
      - mail.admin.adress=${EMAIL:-}

      - student_multiple_login=${STUDEND_MULTIPLE_LOGIN:-false}
      - student_fingerprint_check=${STUDENT_FINGERPRINT_CHECK:-false}
      - jwt_expiration=${JWT_EXPIRATION_MS:-600000}
      - jwt_refresh_time=${JWT_REFRESH_TIME_MS:-300000}
      - 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=${LOGIN_MONGO_DEFAULT_DATABASE:-login}
    ports:
    #  - "8095:8095"
      - "${DEBUG_PORT_LOGIN:-5095}:5095"

  # Proxy als ssl-Proxy und als zentraler Zugangspunkt
  proxy:
    image: lettohub/letto-proxy:stable
    restart: always
    networks:
      - nw-letto
      - nw-proxy
    ports:
      - "${HTTP_PORT:-80}:80"
      - "${HTTPS_PORT:-443}:443"
    deploy:
      resources:
        limits:
          memory: "${PROXY_MEMORY_LIMIT:-100M}"
    logging:
      driver: "json-file"
      options:
        max-size: "2m"
        max-file: "3"
    hostname: letto-proxy
    container_name: letto-proxy
    environment:
      - TZ=${TIMEZONE:-Europe/Berlin}
      - LC_ALL=${LOCALE:-de_DE.UTF-8}
      - SERVER_NAME=${SERVER_NAME:-localhost}
      - EMAIL=${EMAIL:-}
      - REDIRECT=${REDIRECT:-public}
      - DOMAIN_ALTERNATIV=${DOMAIN_ALTERNATIV:-}
      - SELF_SIGNED=${SELF_SIGNED:-1}
      - CERT_EXTERN=${CERT_EXTERN:-0}
      - CREATE_HTTPS_CONF=${CREATE_HTTPS_CONF:-1}
      - USE_HTTP=${USE_HTTP:-0}
    volumes:
      # Verzeichnis in dem docker-compose gestartet wurde
      - .:/host
      # Includes der anderen Dienste
      - ${PROXY_PATH:-/opt/letto/docker/proxy}:/etc/nginx/conf.d/include
      # Zertifikate
      - certs:/etc/letsencrypt
      - certs-data:/data/letsencrypt
      - ${DOCKER_BASE:-/opt/letto/docker}/cert:/etc/cert
      - ${VOLUME_IMAGES:-/opt/letto/docker/storage/images}:/var/www/html/images
      - ${VOLUME_PHOTOS:-/opt/letto/docker/storage/photos}:/var/www/html/images/photos
      - ${VOLUME_PLUGINS:-/opt/letto/docker/storage/plugins}:/var/www/html/images/plugins
      - ${VOLUME_PROJEKTE:-/opt/letto/docker/storage/projekte}:/var/www/html/projekte
      - ${VOLUME_PRINT:-/opt/letto/docker/storage/print}:/var/www/html/print
      - ${VOLUME_EXPORT:-/opt/letto/docker/storage/export}:/var/www/html/export
      - ${VOLUME_LOG:-/opt/letto/docker/storage/log}/proxy:/log
      - ${VOLUME_PUBLIC:-/opt/letto/docker/public}:/var/www/html/public
