captainVersion: 4
services:
    # Pangalinker
    $$cap_appname:
        depends_on:
            - $$cap_appname-mongodb
        image: andris9/pangalink:$$cap_pangalink_version
        restart: always
        environment:
            NODE_ENV: production
            WAIT_HOSTS: srv-captain--$$cap_appname-mongodb:27017
            PL_MONGO_URL: mongodb://$$cap_APP_MONGODB_USERNAME:$$cap_APP_MONGODB_PASSWORD@srv-captain--$$cap_appname-mongodb:27017/$$cap_APP_MONGODB_DATABASE?authSource=$$cap_APP_MONGODB_DATABASE
            PL_HOSTNAME: $$cap_appname.$$cap_root_domain
            PL_PROTO: https
            PL_SMTP_DIRECT: 'false'
            PL_SMTP_HOST: $$cap_SMTP_HOST
            PL_SMTP_PORT: $$cap_SMTP_PORT
            PL_SMTP_TLS: $$cap_SMTP_TLS
            PL_SMTP_USER: $$cap_SMTP_USER
            PL_SMTP_PASS: $$cap_SMTP_PASS
            PL_SMTP_SENDER: $$cap_SMTP_SENDER
        caproverExtra:
            containerHttpPort: '3480'

    # MongoDB
    $$cap_appname-mongodb:
        caproverExtra:
            notExposeAsWebApp: 'true'
        image: bitnami/mongodb:4.4.1-debian-10-r8
        ports:
            - '27017:27017'
        volumes:
            - $$cap_appname-mongodb-data:/bitnami
        environment:
            MONGODB_ROOT_PASSWORD: $$cap_APP_MONGODB_ROOT_PASSWORD
            MONGODB_DATABASE: $$cap_APP_MONGODB_DATABASE
            MONGODB_USERNAME: $$cap_APP_MONGODB_USERNAME
            MONGODB_PASSWORD: $$cap_APP_MONGODB_PASSWORD

caproverOneClickApp:
    variables:
        - id: $$cap_pangalink_version
          label: Pangalinker Version
          defaultValue: 'v2.1.2'
          description: Check out their docker page for the valid tags https://hub.docker.com/r/andris9/pangalink/tags
          validRegex: /^([^\s^\/])+$/
        - label: Mongo - root password
          description: Root password for Mongo DB.
          defaultValue: $$cap_gen_random_hex(32)
          id: $$cap_APP_MONGODB_ROOT_PASSWORD
        - label: Mongo - database username
          description: Mongo DB username.
          defaultValue: pangalink
          id: $$cap_APP_MONGODB_USERNAME
        - label: Mongo - database password
          description: Mongo DB password.
          defaultValue: $$cap_gen_random_hex(32)
          id: $$cap_APP_MONGODB_PASSWORD
        - label: Mongo - database name
          description: Name of the database.
          defaultValue: pangalink
          id: $$cap_APP_MONGODB_DATABASE
        - label: SMTP - sender address
          description: The 'From' address for sent emails.
          defaultValue: 'pangalink@example.com'
          id: $$cap_SMTP_SENDER
        - label: SMTP - server name
          description: Name of the SMTP server for sending emails.
          defaultValue: smtp.example.com
          id: $$cap_SMTP_HOST
        - label: SMTP - port number
          description: Port number for the SMTP server.
          defaultValue: 465
          id: $$cap_SMTP_PORT
        - label: SMTP - username
          description: Username for the SMTP server.
          defaultValue: ''
          id: $$cap_SMTP_USER
        - label: SMTP - password
          description: Password for the SMTP server.
          defaultValue: ''
          id: $$cap_SMTP_PASS
        - label: SMTP - use TLS
          description: Use TLS for SMTP. Usually 'true' only when using port 465, set it to 'false' for any other ports to fall back to using STARTTLS.
          defaultValue: 'true'
          id: $$cap_SMTP_TLS

    instructions:
        start: >-
            Testing service for Estonian pangalink protocols
            GitHub: https://github.com/andris9/Pangalink.net
        end: |-
            You're done! 🤗

            Your Pangalinker instance is available at https://$$cap_appname.$$cap_root_domain

            You must enable HTTPS for Pangalinker before using it!
    displayName: 'Pangalink'
    isOfficial: true
    description: Self-hosted application to test Estonian pangalink protocols
    documentation: Taken from https://hub.docker.com/r/andris9/pangalink
