captainVersion: 4
services:
    $$cap_appname-postgres:
        image: postgres:12
        volumes:
            - $$cap_appname-postgres-data:/var/lib/postgresql/data
        restart: always
        environment:
            POSTGRES_USER: chaskiq
            POSTGRES_PASSWORD: $$cap_chaskiq_postgres_password
            POSTGRES_DB: chaskiq
        caproverExtra:
            notExposeAsWebApp: 'true'
    $$cap_appname-redis:
        volumes:
            - $$cap_appname-redis-data:/data
        restart: always
        environment:
            REDIS_PASSWORD: $$cap_chaskiq_redis_password
        caproverExtra:
            dockerfileLines:
                - FROM redis:alpine
                - CMD exec redis-server --requirepass "$$cap_chaskiq_redis_password"
            notExposeAsWebApp: 'true'
    $$cap_appname-web:
        restart: always
        environment:
            HOST: https://$$cap_appname-web.$$cap_root_domain
            WS: wss://$$cap_appname-web.$$cap_root_domain/cable
            RAILS_ENV: production
            RAILS_LOG_TO_STDOUT: 'true'
            RAILS_SERVE_STATIC_FILES: 'true'
            SECRET_KEY_BASE: $$cap_chaskiq_secret_key_base
            ADMIN_EMAIL: $$cap_ADMIN_USER_EMAIL
            ADMIN_PASSWORD: $$cap_ADMIN_PASSWORD
            DATABASE_URL: postgres://chaskiq:$$cap_chaskiq_postgres_password@srv-captain--$$cap_appname-postgres:5432/chaskiq
            REDIS_URL: redis://default:$$cap_chaskiq_redis_password@srv-captain--$$cap_appname-redis:6379
            AWS_ACCESS_KEY_ID: $$cap_chaskiq_aws_key_id
            AWS_SECRET_ACCESS_KEY: $$cap_chaskiq_aws_access_key
            AWS_S3_BUCKET: $$cap_chaskiq_aws_s3_bucket
            AWS_S3_REGION: $$cap_chaskiq_aws_s3_region
            GEOCODER_API_KEY: $$cap_chaskiq_geocoder_api_key
            DEFAULT_GEOCODER_SERVICE: $$cap_chaskiq_geocoder_service
            SCOUT_KEY: $$cap_chaskiq_scoutapp_key
            DEFAULT_OUTGOING_EMAIL_DOMAIN: $$cap_chaskiq_default_ongoing_domain
            DEFAULT_SENDER_EMAIL: $$cap_chaskiq_default_sender_email

        caproverExtra:
            containerHttpPort: '3000'
            dockerfileLines:
                - FROM chaskiq/chaskiq:$$cap_chaskiq_version
                - EXPOSE 3000
                - CMD bundle exec rails db:setup; bundle exec rails admin_generator; bundle exec rails s -b 0.0.0.0 -p 3000
    $$cap_appname-worker:
        restart: always
        environment:
            HOST: https://$$cap_appname.$$cap_root_domain
            WS: wss://$$cap_appname.$$cap_root_domain/cable
            RAILS_ENV: production
            RAILS_LOG_TO_STDOUT: 'true'
            SECRET_KEY_BASE: $$cap_chaskiq_secret_key_base
            ADMIN_EMAIL: $$cap_ADMIN_USER_EMAIL
            ADMIN_PASSWORD: $$cap_ADMIN_PASSWORD
            DATABASE_URL: postgres://chaskiq:$$cap_chaskiq_postgres_password@srv-captain--$$cap_appname-postgres:5432/chaskiq
            REDIS_URL: redis://default:$$cap_chaskiq_redis_password@srv-captain--$$cap_appname-redis:6379
            AWS_ACCESS_KEY_ID: $$cap_chaskiq_aws_key_id
            AWS_SECRET_ACCESS_KEY: $$cap_chaskiq_aws_access_key
            AWS_S3_BUCKET: $$cap_chaskiq_aws_s3_bucket
            AWS_S3_REGION: $$cap_chaskiq_aws_s3_region
            GEOCODER_API_KEY: $$cap_chaskiq_geocoder_api_key
            DEFAULT_GEOCODER_SERVICE: $$cap_chaskiq_geocoder_service
            SCOUT_KEY: $$cap_chaskiq_scoutapp_key
            DEFAULT_OUTGOING_EMAIL_DOMAIN: $$cap_chaskiq_default_ongoing_domain
            DEFAULT_SENDER_EMAIL: $$cap_chaskiq_default_sender_email

        caproverExtra:
            dockerfileLines:
                - FROM chaskiq/chaskiq:$$cap_chaskiq_version
                - CMD bundle exec sidekiq -C config/sidekiq.yml
            notExposeAsWebApp: 'true'
caproverOneClickApp:
    variables:
        - id: $$cap_chaskiq_version
          label: Chaskiq Version Tag
          description: You can use latest tag or check version builds on https://hub.docker.com/r/chaskiq/chaskiq/tags
          defaultValue: 9009088
        - defaultValue: 'admin@example.com'
          description: This is the admin email. Please change it.
          id: $$cap_ADMIN_USER_EMAIL
          label: Admin Email
          validRegex: /^([^\s^\/])+$/
        - id: $$cap_ADMIN_PASSWORD
          description: This is the admin password. Change it if you will.
          defaultValue: $$cap_gen_random_hex(12)
          label: Admin Password
          validRegex: /^[^\@]{12,}$/
        - id: $$cap_chaskiq_default_sender_email
          label: Default sender email
          description: 'Default email sender, like: notifications@mail.yourapp.com'
          validRegex: /^([^\s^\/])+$/
        - id: $$cap_chaskiq_default_ongoing_domain
          label: Default deliver domain
          description: For multiple email deliver tasks, like mail.yourdomain.com
        - id: $$cap_chaskiq_secret_key_base
          defaultValue: $$cap_gen_random_hex(64)
          label: Chaskiq Secret Key Base
          description: The randomized string which is used to verify the integrity of signed cookies. Please use a string with more than 26 characters
          validRegex: /^[^\@]{26,}$/
        - id: $$cap_chaskiq_postgres_password
          defaultValue: $$cap_gen_random_hex(12)
          label: Postgres Password
          description: Password must be at least 12 characters.  Please use a random string.
          validRegex: /^[^\@]{12,}$/
        - id: $$cap_chaskiq_redis_password
          defaultValue: $$cap_gen_random_hex(12)
          label: Redis Password
          description: Password must be at least 12 characters. Please use a random string.
          validRegex: /^[^\@]{12,}$/
        - id: $$cap_chaskiq_aws_key_id
          label: AWS access key id
          description: Amazon access key id (for file storage and email dispatching S3 / SES / SNS)
        - id: $$cap_chaskiq_aws_access_key
          label: AWS access key
          description: Amazon access key (for file storage and email dispatching S3 / SES / SNS)
        - id: $$cap_chaskiq_aws_s3_bucket
          label: AWS S3 bucket
          description: Amazon S3 bucket name
        - id: $$cap_chaskiq_aws_s3_region
          label: AWS bucket region
          description: 'AWS S3 bucket region like: us-east-1'
        - id: $$cap_chaskiq_aws_sns_configuration_set
          label: SNS configuration set
          description: This is important for chaskiq to receive emails (optional)
        - id: $$cap_chaskiq_scoutapp_key
          label: Scout app key
          description: Scout AMP key, for performance & error monitoring (optional)
        - id: $$cap_chaskiq_bugsnag_key
          label: Bugsnag API key
          description: Bugsnag API key for error reporting (optional)
        - id: $$cap_chaskiq_geocoder_service
          defaultValue: maxmind_local
          label: Geocoder service name, like (maxmind, ip_info, baidu, yandex)
          description: The complete list of services can be found at https://github.com/alexreisner/geocoder/tree/master/lib/geocoder/lookups
        - id: $$cap_chaskiq_geocoder_api_key
          label: Geocoder API key
          description: leave this empty if maxmind_local service is set

    instructions:
        start: A full featured Live Chat, Support & Marketing platform https://chaskiq.io
        end: >-
            Your Chaskiq instance is now successfully deployed. 
            The admin account was created, just log in with those credentials.
            The app will need to be served over SSL, activate HTTPS on the domain and websocket support.

    displayName: Chaskiq
    isOfficial: true
    description: A full-featured Live Chat, Support & Marketing platform
    documentation: 'Read more at: https://dev.chaskiq.io'
