captainVersion: 4
services:
    $$cap_appname-redis:
        caproverExtra:
            notExposeAsWebApp: 'true'
        image: 'bitnami/redis:6.0.8-debian-10-r6'
        environment:
            REDIS_PASSWORD: $$cap_APP_REDIS_PASSWORD
        volumes:
            - $$cap_appname-redis-data:/bitnami

    $$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

    $$cap_appname-api:
        caproverExtra:
            containerHttpPort: '1337'
        restart: always
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock:rw
        ports:
            - '1337:1337'
        image: ghcr.io/whoopsmonitor/whoopsmonitor/api:$$cap_APP_VERSION
        environment:
            NODE_ENV: production
            CONFIG_CORS_ALLOW_ORIGINS: '*'
            APP_PASSWORD: $$cap_APP_PASSWORD
            MONGO_CONNECTION: mongodb://$$cap_APP_MONGODB_USERNAME:$$cap_APP_MONGODB_PASSWORD@srv-captain--$$cap_appname-mongodb:27017/$$cap_APP_MONGODB_DATABASE?authSource=$$cap_APP_MONGODB_DATABASE
            APP_DATA_ENCRYPTION_KEY: $$cap_APP_DATA_ENCRYPTION_KEY
            APP_REDIS_PASSWORD: $$cap_APP_REDIS_PASSWORD
            APP_REDIS_CONNECTION_HOST: srv-captain--$$cap_appname-redis
            APP_REDIS_CONNECTION_PORT: 6379
            APP_TOKEN: $$cap_APP_TOKEN
            APP_QUEUE_NAME_EXECUTE_CHECK: execute-check
            APP_QUEUE_NAME_CLEANUP_CHECK_STATUS: cleanup-check-status
        depends_on:
            - $$cap_appname-mongodb
            - $$cap_appname-redis

    $$cap_appname-monitor:
        restart: always
        image: ghcr.io/whoopsmonitor/whoopsmonitor/monitor:$$cap_APP_VERSION
        ports:
            - '8080:80'
        environment:
            NODE_ENV: production
            API_TOKEN: $$cap_APP_TOKEN
            APP_API_URL: $$cap_APP_API_URL
        depends_on:
            - $$cap_appname-mongodb
            - $$cap_appname-redis
            - $$cap_appname-api

    $$cap_appname-worker:
        caproverExtra:
            notExposeAsWebApp: 'true'
        restart: always
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock:rw
            - $$cap_appname-worker-data:/whoopsmonitor-worker
        image: ghcr.io/whoopsmonitor/whoopsmonitor/worker:$$cap_APP_VERSION
        environment:
            NODE_ENV: production
            APP_REDIS_PASSWORD: $$cap_APP_REDIS_PASSWORD
            APP_REDIS_HOST: srv-captain--$$cap_appname-redis
            APP_REDIS_PORT: 6379
            APP_API_URL: http://srv-captain--$$cap_appname-api:1337
            APP_QUEUE_NAME_EXECUTE_CHECK: execute-check
            APP_QUEUE_NAME_CLEANUP_CHECK_STATUS: cleanup-check-status
            APP_QUEUE_NAME_ALERTING: alerting
            APP_TOKEN: $$cap_APP_TOKEN
        depends_on:
            - $$cap_appname-mongodb
            - $$cap_appname-redis
            - $$cap_appname-api

    $$cap_appname-alerting:
        caproverExtra:
            notExposeAsWebApp: 'true'
        restart: always
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock:rw
        image: ghcr.io/whoopsmonitor/whoopsmonitor/alerting:1.0
        environment:
            NODE_ENV: production
            APP_REDIS_PASSWORD: $$cap_APP_REDIS_PASSWORD
            APP_REDIS_HOST: srv-captain--$$cap_appname-redis
            APP_REDIS_PORT: 6379
            APP_API_URL: http://srv-captain--$$cap_appname-api:1337
            APP_QUEUE_NAME_ALERTING: alerting
            APP_TOKEN: $$cap_APP_TOKEN
        depends_on:
            - $$cap_appname-mongodb
            - $$cap_appname-redis
            - $$cap_appname-api

    $$cap_appname-image-metadata:
        caproverExtra:
            notExposeAsWebApp: 'true'
        restart: always
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock:rw
        image: ghcr.io/whoopsmonitor/whoopsmonitor/image-metadata:1.0
        environment:
            NODE_ENV: production
            API_URL: http://srv-captain--$$cap_appname-api:1337
            APP_TOKEN: $$cap_APP_TOKEN
        depends_on:
            - $$cap_appname-mongodb
            - $$cap_appname-redis
            - $$cap_appname-api

caproverOneClickApp:
    variables:
        - label: Version
          description: Application version, currently 1.0
          defaultValue: '1.0'
          id: $$cap_APP_VERSION

        - label: '* External API URL'
          description: API URL that is availaible from outside, like via browser. You can re-enter this value later but it is mandatory for "monitor" service.
          defaultValue: 'https://'
          id: $$cap_APP_API_URL

        - label: Redis Password
          description: Redis password.
          defaultValue: $$cap_gen_random_hex(32)
          id: $$cap_APP_REDIS_PASSWORD

        - 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: $$cap_gen_random_hex(32)
          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: $$cap_gen_random_hex(32)
          id: $$cap_APP_MONGODB_DATABASE

        - label: Application Password
          description: Admin for your application. There is no account name. Just the password.
          defaultValue: $$cap_gen_random_hex(16)
          id: $$cap_APP_PASSWORD
        - label: Encryption key
          description: Sensitive data stored in Whoops Monitor are all encrypted. It is a base64 key of some string. You should change the default value.
          defaultValue: a3psdWpZdU40WG9zZTRPVHNpdXkxYTlNS0JqRTdZZUs=
          id: $$cap_APP_DATA_ENCRYPTION_KEY
        - label: API token
          description: API token that is used for securing the communication between API and external services.
          defaultValue: $$cap_gen_random_hex(64)
          id: $$cap_APP_TOKEN

    displayName: Whoops Monitor
    isOfficial: true
    description: A monitoring tool that gives you clarity over your application landscape.
    documentation: https://github.com/whoopsmonitor/whoopsmonitor
    instructions:
        start: |-
            A monitoring tool that gives you clarity over your application landscape.
            GitHub: https://github.com/whoopsmonitor/whoopsmonitor
        end: |-
            You're done! 😄

            Your service is available at http://$$cap_appname.$$cap_root_domain

            The password is $$cap_APP_PASSWORD
