captainVersion: 4

services:
    $$cap_appname-mail:
        image: bytemark/smtp
        restart: always
        environment:
            RELAY_HOST: $$cap_RELAY_HOST
            RELAY_PORT: $$cap_RELAY_PORT
            RELAY_USERNAME: $$cap_RELAY_USERNAME
            RELAY_PASSWORD: $$cap_RELAY_PASSWORD
        caproverExtra:
            notExposeAsWebApp: 'true'

    $$cap_appname-postgres:
        image: postgres:12-alpine
        volumes:
            - $$cap_appname-postgres-data:/var/lib/postgresql/data
        environment:
            POSTGRES_USER: plausible
            POSTGRES_PASSWORD: $$cap_POSTGRES_PASSWORD
        caproverExtra:
            notExposeAsWebApp: 'true'

    $$cap_appname-clickhouse:
        image: yandex/clickhouse-server:20.8.5.45
        volumes:
            - $$cap_appname-clickhouse-data:/var/lib/clickhouse
        caproverExtra:
            notExposeAsWebApp: 'true'

    $$cap_appname-geoip:
        image: maxmindinc/geoipupdate:v4.5
        environment:
            GEOIPUPDATE_ACCOUNT_ID: $$cap_GEOIPUPDATE_ACCOUNT_ID
            GEOIPUPDATE_LICENSE_KEY: $$cap_GEOIPUPDATE_LICENSE_KEY
            GEOIPUPDATE_EDITION_IDS: GeoLite2-Country
            GEOIPUPDATE_FREQUENCY: 168
        volumes:
            - $$cap_appname-geoip-data:/usr/share/GeoIP

    $$cap_appname:
        depends_on:
            - $$cap_appname-postgres
            - $$cap_appname-clickhouse
            - $$cap_appname-mail
        caproverExtra:
            containerHttpPort: '8000'
            dockerfileLines:
                - FROM plausible/analytics:v1.1.1
                - CMD ["sh", "-c", "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh db init-admin && /entrypoint.sh run"]
        environment:
            ADMIN_USER_EMAIL: $$cap_ADMIN_USER_EMAIL
            ADMIN_USER_NAME: $$cap_ADMIN_USER_NAME
            ADMIN_USER_PWD: $$cap_ADMIN_USER_PWD
            BASE_URL: http://$$cap_appname.$$cap_root_domain
            DATABASE_URL: postgres://plausible:$$cap_POSTGRES_PASSWORD@srv-captain--$$cap_appname-postgres:5432/plausible
            CLICKHOUSE_DATABASE_URL: http://srv-captain--$$cap_appname-clickhouse:8123/plausible
            SECRET_KEY_BASE: $$cap_gen_random_hex(64)
            SIGNING_SALT: $$cap_gen_random_hex(24)
            DISABLE_REGISTRATION: 'true'
            DISABLE_SUBSCRIPTION: 'true'
            MAILER_EMAIL: $$cap_RELAY_USERNAME
            SMTP_HOST_ADDR: srv-captain--$$cap_appname-mail
            SMTP_HOST_PORT: '25'
            GEOLITE2_COUNTRY_DB: '/geoip/GeoLite2-Country.mmdb'
        volumes:
            - $$cap_appname-geoip-data:/geoip

caproverOneClickApp:
    variables:
        - defaultValue: 'admin@example.com'
          description: This is the admin email. Please change it.
          id: $$cap_ADMIN_USER_EMAIL
          label: ADMIN_USER_EMAIL
          validRegex: /^([^\s^\/])+$/
        - defaultValue: 'admin'
          description: This is the admin username. Please change it.
          id: $$cap_ADMIN_USER_NAME
          label: ADMIN_USER_NAME
          validRegex: /^([^\s^\/])+$/
        - defaultValue: 'password'
          description: This is the admin password. Please change it.
          id: $$cap_ADMIN_USER_PWD
          label: ADMIN_USER_PWD
          validRegex: /^([^\s^\/])+$/
        - defaultValue: 'plausible'
          description: This is the PostgreSQL password for user 'plausible'. Please change it.
          id: $$cap_POSTGRES_PASSWORD
          label: POSTGRES_PASSWORD
          validRegex: /^([^\s^\/])+$/
        - defaultValue: 'smtp.mailgun.org'
          description: This is the SMTP host for sending email. Use Mailgun or whatever other service.
          id: $$cap_RELAY_HOST
          label: RELAY_HOST
          validRegex: /^([^\s^\/])+$/
        - defaultValue: '587'
          description: This is the port for the SMTP host. Please change it if needed.
          id: $$cap_RELAY_PORT
          label: RELAY_PORT
          validRegex: /^([^\s^\/])+$/
        - description: This is the username for logging into the SMTP host. Please change it according to your host.
          id: $$cap_RELAY_USERNAME
          label: RELAY_USERNAME
          validRegex: /^([^\s^\/])+$/
        - description: This is the password for logging into the SMTP host. Please change it according to your host.
          id: $$cap_RELAY_PASSWORD
          label: RELAY_PASSWORD
          validRegex: /^([^\s^\/])+$/
        - description: Provide your own ACCOUNT_ID, you can sign-up at https://www.maxmind.com/en/geoip2-services-and-databases
          id: $$cap_GEOIPUPDATE_ACCOUNT_ID
          label: GEOIPUPDATE_ACCOUNT_ID
          validRegex: /^([^\s^\/])+$/
        - description: Provide the corresponding License Key for your own ACCOUNT_ID.
          id: $$cap_GEOIPUPDATE_LICENSE_KEY
          label: GEOIPUPDATE_LICENSE_KEY
          validRegex: /^([^\s^\/])+$/
    instructions:
        start: >-
            Plausible is a lightweight and open-source website analytics tool.
            It doesn’t use cookies and is fully compliant with GDPR, CCPA and PECR. Made and hosted in the EU.
            This one click app uses the:
            - official image from https://hub.docker.com/r/plausible/analytics
            - https://hub.docker.com/r/bytemark/smtp, that allows linked containers to send outgoing email
            - official PostgreSQL image based on Alpine Linux
            - ClickHouse image https://hub.docker.com/r/yandex/clickhouse-server, an open-source column-oriented database
            - official image from https://hub.docker.com/r/maxmindinc/geoipupdate, the well known MaxMind GeoIP Update Tool.
        end: >-
            Plausible.io is deployed and available as $$cap_appname.
            In case you add a new domain to your application, remember to set the environment variable BASE_URL accordingly.

            IMPORTANT: It will take up to 2 minutes for Plausible to be ready. Before that, you might see 502 error page.
    displayName: Plausible
    isOfficial: false
    description: Plausible is a lightweight and open-source website analytics tool.
    documentation: Taken from https://plausible.io/.
