version: '3.7'
services:
  dd-apps-moodle:
    build:
      context: ${BUILD_APPS_ROOT_PATH}/docker/moodle
      dockerfile: Dockerfile
      args:
        - IMG=${MOODLE_IMG}
    container_name: dd-apps-moodle
    restart: unless-stopped
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ${DATA_FOLDER}/moodle:/var/www/moodledata:rw
      - ${SRC_FOLDER}/moodle:/var/www/html:rw
    depends_on:
      - dd-apps-postgresql
    environment:
      #- LANG=en_US.UTF-8
      #- LANGUAGE=en_US:en
      - MOODLE_VERSION=${MOODLE_VERSION}
      - DOMAIN=${DOMAIN}
      - SITE_URL=https://moodle.${DOMAIN}
      - DB_TYPE=pgsql
      - DB_HOST=dd-apps-postgresql
      - DB_PORT=5432
      - DB_NAME=moodle
      - DB_USER=${MOODLE_POSTGRES_USER}
      - DB_PASS=${MOODLE_POSTGRES_PASSWORD}
      - DB_PREFIX=mdl_
      - SSLPROXY=true
      - MOODLE_EMAIL=${MOODLE_EMAIL} #
      - MOODLE_LANGUAGE=${LANGUAGE_CODE} #
      - MOODLE_SITENAME=${TITLE} #
      - MOODLE_SHORTSITENAME=${TITLE_SHORT} #
      - MOODLE_USERNAME=${MOODLE_ADMIN_USER}
      - MOODLE_PASSWORD=${MOODLE_ADMIN_PASSWORD}
      - SMTP_HOST=${SMTP_HOST}
      - SMTP_PORT=${SMTP_PORT}
      - SMTP_USER=${SMTP_USER}
      - SMTP_PASSWORD=${SMTP_PASSWORD}
      - SMTP_PROTOCOL=${SMTP_PROTOCOL}
      - MOODLE_MAIL_NOREPLY_ADDRESS=${MOODLE_MAIL_NOREPLY_ADDRESS}
      - MOODLE_MAIL_PREFIX=${MOODLE_MAIL_PREFIX}
      - client_max_body_size=${MOODLE_MAX_FILESIZE_UPLOAD}
      - post_max_size=${MOODLE_MAX_FILESIZE_UPLOAD}
      - upload_max_filesize=${MOODLE_MAX_FILESIZE_UPLOAD}
      - max_input_vars=5000
      - max_execution_time=${MOODLE_MAX_EXECUTION_TIME}
      - memory_limit=${MOODLE_MEMORY_LIMIT}
    healthcheck:
        test: |
          curl -L --max-redirs 1 \
            --proxy-basic 'http://localhost:8080' \
            -sw '%{redirect_url}' \
            'http://moodle.${DOMAIN}/' | grep -q 'https://sso.${DOMAIN}'
        interval: 30s
        timeout: 10s
        retries: 5
    networks:
      - dd_net
