captainVersion: 4
services:
    # Mayan EDMS
    $$cap_appname:
        depends_on:
            - $$cap_appname-db
            - $$cap_appname-redis
        image: mayanedms/mayanedms:$$cap_app_version
        restart: always
        environment:
            MAYAN_CELERY_BROKER_URL: 'redis://:$$cap_redis_pass@srv-captain--$$cap_appname-redis:6379/0'
            MAYAN_CELERY_RESULT_BACKEND: 'redis://:$$cap_redis_pass@srv-captain--$$cap_appname-redis:6379/1'
            MAYAN_DATABASES: "{'default':{'ENGINE':'django.db.backends.postgresql','NAME':'$$cap_dbname','PASSWORD':'$$cap_dbpass','USER':'$$cap_dbuser','HOST':'srv-captain--$$cap_appname-db'}}"
            MAYAN_LOCK_MANAGER_BACKEND: 'mayan.apps.lock_manager.backends.redis_lock.RedisLock'
            MAYAN_LOCK_MANAGER_BACKEND_ARGUMENTS: "{'redis_url':'redis://:$$cap_redis_pass@srv-captain--$$cap_appname-redis:6379/2'}"
            MAYAN_SEARCH_BACKEND: 'mayan.apps.dynamic_search.backends.whoosh.WhooshSearchBackend'
            MAYAN_APT_INSTALLS: '$$cap_ocr_langs'
            MAYAN_DOCKER_WAIT: srv-captain--$$cap_appname-db:5432 srv-captain--$$cap_appname-redis:6379
            MAYAN_DOCUMENTS_LANGUAGE: $$cap_default_document_lang
            MAYAN_TIME_ZONE: $$cap_timezone
            MAYAN_AUTOADMIN_EMAIL: $$cap_email
            MAYAN_AUTOADMIN_PASSWORD: $$cap_password
            MAYAN_AUTOADMIN_USERNAME: $$cap_username
            MAYAN_COMMON_PROJECT_TITLE: $$cap_project_title
        volumes:
            - $$cap_appname-data:/var/lib/mayan
        caproverExtra:
            containerHttpPort: '8000'

    # Redis
    $$cap_appname-redis:
        volumes:
            - $$cap_appname-redis-data:/data
        restart: always
        caproverExtra:
            dockerfileLines:
                - FROM redis:$$cap_redis_version
                - CMD exec redis-server --appendonly 'no' --databases '3' --maxmemory 100mb --maxclients '500' --maxmemory-policy allkeys-lru --save '' --requirepass $$cap_redis_pass
            notExposeAsWebApp: 'true'

    #PostgreSQL
    $$cap_appname-db:
        image: postgres:$$cap_postgres_version
        volumes:
            - $$cap_appname-db-data:/var/lib/postgresql/data
        restart: always
        environment:
            POSTGRES_DB: $$cap_dbname
            POSTGRES_USER: $$cap_dbuser
            POSTGRES_PASSWORD: $$cap_dbpass
        caproverExtra:
            notExposeAsWebApp: 'true'

caproverOneClickApp:
    variables:
        - id: $$cap_app_version
          label: Mayan EDMS version
          defaultValue: 's4.2'
          description: Check out their docker page for the valid tags https://hub.docker.com/r/mayanedms/mayanedms/tags

        - id: $$cap_postgres_version
          label: PostgreSQL version
          defaultValue: '12.9-alpine'
          description: Check out their Docker page for the valid tags https://hub.docker.com/r/library/postgres/tags/
          validRegex: /^([^\s^\/])+$/

        - id: $$cap_redis_version
          label: Redis version
          defaultValue: '6.2.1-alpine'
          description: Check out their Docker page for the valid tags https://hub.docker.com/_/redis?tab=tags
          validRegex: /^([^\s^\/])+$/

        - id: $$cap_redis_pass
          label: Redis password
          defaultValue: mayanredispassword
          validRegex: /^([^\s^\/])+$/

        - id: $$cap_dbname
          label: Database Name
          defaultValue: 'mayan'
          validRegex: /^([^\s^\/])+$/

        - id: $$cap_dbuser
          label: Database User
          defaultValue: 'mayandbuser'
          validRegex: /^([^\s^\/])+$/

        - id: $$cap_dbpass
          label: Database Password
          defaultValue: $$cap_gen_random_hex(64)
          validRegex: /^([^\s^\/])+$/

        - id: $$cap_default_document_lang
          label: Default document language
          defaultValue: eng
          description: Use the ISO 639-3 code (https://en.wikipedia.org/wiki/ISO_639). Will default to *eng* if left blank.

        - id: $$cap_language_code
          label: Default language for the installation
          defaultValue: en-us
          description: Mayan EDMS UI will default to this language if the user's locale is not found. Will default to *en-us* if left blank

        - id: $$cap_ocr_langs
          label: Extra packages
          defaultValue: 'tesseract-ocr-spa'
          description: Use to add extra languagues for OCR (English is installed by default). Insert as many packages as you need, separated by a space, as *tesseract-ocr-CODE*. Language codes in https://tesseract-ocr.github.io/tessdoc/Data-Files-in-different-versions.html

        - id: $$cap_timezone
          label: Time Zone
          defaultValue: UTC
          description: Leave blank if you'd rather change it in System => Setup => Settings

        - id: $$cap_username
          label: Admin username
          defaultValue: admin
          description: Username for your first login

        - id: $$cap_email
          label: Admin email
          defaultValue: example@example.com

        - id: $$cap_pass
          label: Admin password
          defaultValue: $$cap_gen_random_hex(16)
          validRegex: /^([^\s^\/])+$/
          description: It will be prompted to you at startup and can be changed, but copy it just in case.

        - id: $$cap_project_title
          label: Project Title (Site's name)
          defaultValue: 'Mayan EDMS'
          description: Title and header of your site

    instructions:
        start: >-
            Mayan EDMS is an open source web-based Document Management System (More info at https://www.mayan-edms.com/)
            Most settings can be set inside the app, but environment variables will override them.
            Minimum requirements 2GB RAM and 2vCPUs. Recommended 4GB RAM and 4vCPUs
        end: >-
            Done!
            Your service is available at http://$$cap_appname.$$cap_root_domain
    displayName: 'Mayan EDMS'
    isOfficial: false
    description: Mayan EDMS is an open source web-based Document Management System with many advanced features.
    documentation: https://www.mayan-edms.com/
