captainVersion: 4

services:
    $$cap_appname:
        image: registry.rocket.chat/rocketchat/rocket.chat:$$cap_app_version
        volumes:
            - $$cap_appname-data:/app/uploads
        depends_on: [$$cap_appname-db]
        environment:
            PORT: 3000
            ROOT_URL: http://$$cap_appname.$$cap_root_domain
            MONGO_URL: mongodb://$$cap_mongodb_db_username:$$cap_mongodb_db_password@srv-captain--$$cap_appname-db:27017/rocketchat?replicaSet=rs0
            MONGO_OPLOG_URL: mongodb://$$cap_mongodb_root_username:$$cap_mongodb_root_password@srv-captain--$$cap_appname-db:27017/local?replicaSet=rs0&authSource=admin

            ADMIN_NAME: $$cap_admin_name
            ADMIN_USERNAME: $$cap_admin_username
            ADMIN_PASS: $$cap_admin_password

            OVERWRITE_SETTING_Site_Url: http://$$cap_appname.$$cap_root_domain

            DEPLOY_METHOD: docker
            DEPLOY_PLATFORM: caprover
        caproverExtra:
            containerHttpPort: 3000

    $$cap_appname-db:
        image: bitnami/mongodb:$$cap_app_db_version
        restart: on-failure
        volumes:
            - $$cap_appname-db-data:/bitnami/mongodb
        environment:
            MONGODB_REPLICA_SET_MODE: primary
            MONGODB_REPLICA_SET_NAME: rs0
            MONGODB_PORT_NUMBER: 27017
            MONGODB_INITIAL_PRIMARY_HOST: srv-captain--$$cap_appname-db
            MONGODB_INITIAL_PRIMARY_PORT_NUMBER: 27017
            MONGODB_ADVERTISED_HOSTNAME: srv-captain--$$cap_appname-db
            MONGODB_REPLICA_SET_KEY: $$cap_mongodb_db_replicaset_key
            # root account
            MONGODB_ROOT_USER: $$cap_mongodb_root_username
            MONGODB_ROOT_PASSWORD: $$cap_mongodb_root_password
            # rocketchat database account
            MONGODB_USERNAME: $$cap_mongodb_db_username
            MONGODB_PASSWORD: $$cap_mongodb_db_password
            MONGODB_DATABASE: rocketchat
        caproverExtra:
            notExposeAsWebApp: true

caproverOneClickApp:
    variables:
        - id: $$cap_app_version
          label: Rocket.Chat Version
          description: See version numbers at https://hub.docker.com/r/library/rocket-chat/tags/ or https://github.com/RocketChat/Rocket.Chat/releases. Version must be >=4.x.y
          defaultValue: '4.2.1'
          # enforcing deployment of v4+
          validRegex: /^[4-9](\.[0-9](\.[0-9])?)?$/

        - id: $$cap_admin_name
          label: Rocket.Chat Admin Real Name
          defaultValue: Captain
          description: Real name of your Rocket.Chat instance's Admin user
          validRegex: /^[a-zA-Z0-9\.-\s]+$/

        - id: $$cap_admin_username
          label: Rocket.Chat Admin Username
          defaultValue: captain
          description: Username of your Rocket.Chat instance's Admin user
          validRegex: /^[a-zA-Z0-9\.-]+$/

        - id: $$cap_admin_password
          label: Rocket.Chat Admin Password
          defaultValue: $$cap_gen_random_hex(16)
          description: Password of your Rocket.Chat instance's Admin user. Must be at least 8 characters long
          validRegex: /.{8,}/

        - id: $$cap_app_db_version
          label: MongoDB Version
          description: See https://docs.rocket.chat/quick-start/installing-and-updating/manual-installation/mongo-versions for supported MongoDB versions. See https://hub.docker.com/r/bitnami/mongodb/tags/ for MongoDB image tags. Version must be >=4.x.y but please prefer >=4.4.z
          defaultValue: '4.4'
          # ensuring v4+ is used
          validRegex: /^[4-9](\.[0-9](\.[0-9])?)?(-debian-[0-9]+-r[0-9]+)?$/

        - id: $$cap_mongodb_root_username
          label: MongoDB root user's username
          defaultValue: root
          validRegex: /^[a-zA-Z0-9]+$/

        - id: $$cap_mongodb_root_password
          label: MongoDB root user password
          description: Must be at least 8 characters long. Recommended to leave the default generated
          defaultValue: $$cap_gen_random_hex(24)
          validRegex: /^[^\@]{8,}$/

        - id: $$cap_mongodb_db_username
          label: MongoDB user with permissions to Rocket.Chat database
          defaultValue: rocketchat
          validRegex: /^[a-zA-Z0-9]+$/

        - id: $$cap_mongodb_db_password
          label: Password of the MongoDB user with permissions to Rocket.Chat database
          description: Must be at least 8 characters long. Recommended to leave the default generated
          defaultValue: $$cap_gen_random_hex(24)
          validRegex: /^[^\@]{8,}$/

        - id: $$cap_mongodb_db_replicaset_key
          label: MongoDB replicaset key
          description: Must be at least 5 characters long. Recommended to leave the default generated
          defaultValue: $$cap_gen_random_hex(32)
          validRegex: /.{5,}/

    instructions:
        start: |-
            Deploy your own Rocket.Chat instance with this one click.
            For more information see https://github.com/RocketChat/Rocket.Chat
        end: |-
            Your Rocket.Chat instance is now available at http://$$cap_appname.$$cap_root_domain
            Log in to your newly deployed Rocket.Chat instance with the default admin account, username: "captain" and password: "$$cap_admin_password"
            If you face any issues, you can reach out at,
            Forum: https://forums.rocket.chat
            Open Community Server: https://open.rocket.chat/channel/support

    displayName: Rocket.Chat
    isOfficial: true
    description: Slack like online chat, built with Meteor. Real-time conversations with your colleagues, other companies or customers.
    documentation: https://github.com/RocketChat/Rocket.Chat
