captainVersion: 4

services:
    $$cap_appname:
        depends_on:
            - $$cap_appname-db
        environment:
            DATABASE_URL: 'ecto://postgres:$$cap_postgres_password@srv-captain--$$cap_appname-db/postgres'
            SECRET_KEY_BASE: $$cap_secret_key
            BACKEND_URL: $$cap_appname.$$cap_root_domain
            MIX_ENV: $$cap_mix_env
            REACT_APP_URL: $$cap_appname.$$cap_root_domain
            FROM_ADDRESS: $$cap_email_from_address
            MAILGUN_API_KEY: $$cap_mailgun_api_key
            DOMAIN: $$cap_email_from_domain
            SLACK_BOT_ACCESS_TOKEN: $$cap_slack_bot_access_token
            PAPERCUPS_SLACK_CLIENT_ID: $$cap_slack_client_id
            PAPERCUPS_SLACK_CLIENT_SECRET: $$cap_slack_client_secret
            SENTRY_DSN: $$cap_sentry_dsn
            PAPERCUPS_STRIPE_SECRET: $$cap_stripe_secret
            REACT_APP_GOOGLE_ANALYTICS_ID: $$cap_react_google_analytics_id
            REACT_APP_SLACK_CLIENT_ID: $$cap_react_slack_client_id
            REACT_APP_SENTRY_DSN: $$cap_react_sentry_dsn
            REACT_APP_LOGROCKET_ID: $$cap_react_logrocket_id
            REACT_APP_STRIPE_PUBLIC_KEY: $$cap_react_stripe_public_id
            REACT_APP_FILE_UPLOADS_ENABLED: $$cap_upload_enabled
            CUSTOMER_IO_SITE_ID: $$cap_customer_io_site_id
            CUSTOMER_IO_API_KEY: $$cap_customer_io_api_key
            AWS_ACCESS_KEY_ID: $$cap_aws_access_key_id
            AWS_SECRET_ACCESS_KEY: $$cap_aws_secret_key
            BUCKET_NAME: $$cap_aws_bucket
            AWS_REGION: $$cap_aws_region
            REQUIRE_DB_SSL: $$cap_db_require_ssl

        caproverExtra:
            containerHttpPort: '4000'
            dockerfileLines:
                - FROM papercups/papercups:$$cap_papercups_tag
                - ENTRYPOINT sh -c "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && echo 'running' && /entrypoint.sh run"

    $$cap_appname-db:
        image: postgres:$$cap_postgres_tag
        volume:
            - '$$cap_appname-db-data:/var/lib/postgresql/data'
        environment:
            POSTGRES_PASSWORD: $$cap_postgres_password
        caproverExtra:
            notExposeAsWebApp: true

caproverOneClickApp:
    variables:
        - id: $$cap_papercups_tag
          label: Papercups Tag
          defaultValue: 1.1.0
          description: 'Check out their docker page for the valid tags https://hub.docker.com/r/papercups/papercups/tags'
        - id: $$cap_postgres_tag
          label: Postgres Tag
          defaultValue: 9.6-alpine
          description: 'Check out their docker page for the valid tags https://hub.docker.com/_/postgres?tab=tags'
        - id: $$cap_postgres_password
          label: Postgres Password
          defaultValue: $$cap_gen_random_hex(16)
        - id: $$cap_secret_key
          label: Papercups Secret Key
          defaultValue: $$cap_gen_random_hex(64)
          validRegex: /.{64,}/
          description: 'Must be at least 64 bytes'
        - id: $$cap_mix_env
          label: Mix Env
          defaultValue: prod
          description: 'Learn more at https://hexdocs.pm/mix/Mix.html#module-environments'
        - id: $$cap_upload_enabled
          label: Enable Papercups Upload
          defaultValue: 1
        - id: $$cap_email_from_address
          label: Email From Address
          defaultValue: 'noreply@mail.papercups.io'
        - id: $$cap_mailgun_api_key
          label: Mailgun API Key
          defaultValue: ''
        - id: $$cap_email_from_domain
          label: Email From Domain
          defaultValue: '$$cap_appname.$$cap_root_domain'
        - id: $$cap_slack_bot_access_token
          label: Slack Bot Access Token
          defaultValue: ''
        - id: $$cap_slack_client_id
          label: Slack Bot Client ID
          defaultValue: ''
        - id: $$cap_slack_client_secret
          label: Slack Bot Client Secret
          defaultValue: ''
        - id: $$cap_sentry_dsn
          label: Sentry DSN
          defaultValue: ''
        - id: $$cap_stripe_secret
          label: Stripe Secret
          defaultValue: ''
        - id: $$cap_react_google_analytics_id
          label: Google Analytics ID
          defaultValue: ''
        - id: $$cap_react_slack_client_id
          label: Papercups's React Slack Client ID
          defaultValue: ''
        - id: $$cap_react_sentry_dsn
          label: Papercups's React Sentry DSN
          defaultValue: ''
        - id: $$cap_react_logrocket_id
          label: Papercups's React LogRocket ID
          defaultValue: ''
        - id: $$cap_react_stripe_public_id
          label: Papercups's React Stripe Public ID
          defaultValue: ''
        - id: $$cap_customer_io_site_id
          label: Customer.io Site ID
          defaultValue: ''
        - id: $$cap_customer_io_api_key
          label: Customer.io API Key
          defaultValue: ''
        - id: $$cap_aws_access_key_id
          label: AWS Access Key ID
          defaultValue: ''
        - id: $$cap_aws_secret_key
          label: AWS Secret Key ID
          defaultValue: ''
        - id: $$cap_aws_bucket
          label: AWS Bucket
          defaultValue: ''
        - id: $$cap_aws_region
          label: AWS Region
          defaultValue: ''
        - id: $$cap_db_require_ssl
          label: DB Require SSL
          defaultValue: 'false'
    instructions:
        start: >-
            Papercups is an open source live customer chat web app written in Elixir.
            For more info visit https://papercups.io/
        end: |-
            Papercups has been successfully deployed!

            --------------------------------------------

            Before you proceed, you must:
            1. Enable HTTPS
            2. Enable Websocket Support

            --------------------------------------------            

            App is available as http://$$cap_appname.$$cap_root_domain
    displayName: Papercups
    isOfficial: false
    description: >-
        Papercups is an open source live customer chat web app written in Elixir.
    documentation: >-
        This docker-compose is taken from https://github.com/papercups-io/papercups/blob/master/docker-compose.prod.yml
        Papercups's example environment https://github.com/papercups-io/papercups/blob/master/.env.example
