# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: Plausible
spec:
    description: Plausible is intuitive, lightweight and open source web analytics.
    coverImage: https://camo.githubusercontent.com/745ee7f1da884405bab758c7f532002a0bc58981cc237af3a0da44e1af463a3e/68747470733a2f2f706c61757369626c652e696f2f646f63732f696d672f706c61757369626c652d616e616c79746963732e706e67
    icon: https://asset.brandfetch.io/id2ceYC7ck/idkMMiHKhK.png
    variables:
        - key: DOMAIN
          type: DOMAIN
          name: Domain
          description: What is the domain of your Plausible?
    tags:
        - Monitoring
        - Tool
    readme: |-
        Plausible Analytics is an easy to use, lightweight (< 1 KB), open source and privacy-friendly alternative to Google Analytics. It doesn’t use cookies and is fully compliant with GDPR, CCPA and PECR.

        We are dedicated to making web analytics more privacy-friendly. Our mission is to reduce corporate surveillance by providing an alternative web analytics tool which doesn’t come from the AdTech world. We are completely independent and solely funded by our subscribers.
    services:
        - name: postgresql
          icon: https://raw.githubusercontent.com/zeabur/service-icons/main/marketplace/postgresql.svg
          template: PREBUILT
          spec:
            source:
                image: postgres:16-alpine
                command:
                    - docker-entrypoint.sh
                    - -c
                    - config_file=/etc/postgresql/postgresql.conf
            ports:
                - id: database
                  port: 5432
                  type: TCP
            volumes:
                - id: data
                  dir: /var/lib/postgresql/data
            instructions:
                - title: Connection String
                  content: postgresql://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${PORT_FORWARDED_HOSTNAME}:${DATABASE_PORT_FORWARDED_PORT}/${POSTGRES_DATABASE}
                - title: PostgreSQL Connect Command
                  content: psql "postgresql://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${PORT_FORWARDED_HOSTNAME}:${DATABASE_PORT_FORWARDED_PORT}/${POSTGRES_DATABASE}"
                - title: PostgreSQL username
                  content: ${POSTGRES_USERNAME}
                - title: PostgresSQL password
                  content: ${POSTGRES_PASSWORD}
                - title: PostgresSQL database
                  content: ${POSTGRES_DATABASE}
                - title: PostgreSQL host
                  content: ${PORT_FORWARDED_HOSTNAME}
                - title: PostgreSQL port
                  content: ${DATABASE_PORT_FORWARDED_PORT}
            env:
                PGDATA:
                    default: /var/lib/postgresql/data/pgdata
                POSTGRES_CONNECTION_STRING:
                    default: postgresql://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DATABASE}
                    expose: true
                POSTGRES_DATABASE:
                    default: ${POSTGRES_DB}
                    expose: true
                POSTGRES_DB:
                    default: zeabur
                POSTGRES_HOST:
                    default: ${CONTAINER_HOSTNAME}
                    expose: true
                POSTGRES_PASSWORD:
                    default: ${PASSWORD}
                    expose: true
                POSTGRES_PORT:
                    default: ${DATABASE_PORT}
                    expose: true
                POSTGRES_URI:
                    default: ${POSTGRES_CONNECTION_STRING}
                    expose: true
                POSTGRES_USER:
                    default: root
                POSTGRES_USERNAME:
                    default: ${POSTGRES_USER}
                    expose: true
            configs:
                - path: /etc/postgresql/postgresql.conf
                  template: |
                    # https://github.com/postgres/postgres/blob/master/src/backend/utils/misc/postgresql.conf.sample
                    listen_addresses = '*'
                    max_connections = 100
                    shared_buffers = 128MB
                    dynamic_shared_memory_type = posix
                    max_wal_size = 1GB
                    min_wal_size = 80MB
                    log_timezone = 'Etc/UTC'
                    datestyle = 'iso, mdy'
                    timezone = 'Etc/UTC'
                    lc_messages = 'en_US.utf8'
                    lc_monetary = 'en_US.utf8'
                    lc_numeric = 'en_US.utf8'
                    lc_time = 'en_US.utf8'
                    default_text_search_config = 'pg_catalog.english'
                  permission: null
                  envsubst: null
        - name: clickhouse
          icon: https://avatars.githubusercontent.com/u/54801242
          template: PREBUILT
          spec:
            source:
                image: clickhouse/clickhouse-server:24.3.3.102-alpine
            ports:
                - id: web
                  port: 8123
                  type: HTTP
            volumes:
                - id: data
                  dir: /var/lib/clickhouse
            instructions:
                - title: Clickhouse HTTP interface URL
                  content: ${ZEABUR_WEB_URL}
                - title: Clickhouse username
                  content: ${CLICKHOUSE_USER}
                - title: Clickhouse password
                  content: ${CLICKHOUSE_PASSWORD}
                - title: Clickhouse database
                  content: ${CLICKHOUSE_DB}
            env:
                CLICKHOUSE_DB:
                    default: zeabur
                    expose: true
                CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT:
                    default: "1"
                CLICKHOUSE_PASSWORD:
                    default: ${PASSWORD}
                    expose: true
                CLICKHOUSE_USER:
                    default: zeabur
                    expose: true
                PORT:
                    default: "8123"
            configs:
                - path: /etc/clickhouse-server/config.d/docker_related_config.xml
                  template: |-
                    <clickhouse>
                         <!-- Listen wildcard address to allow accepting connections from other containers and host network. -->
                        <listen_host>::</listen_host>
                        <listen_host>0.0.0.0</listen_host>
                        <listen_try>1</listen_try>

                        <logger>
                            <level>information</level>
                            <console>1</console>
                        </logger>
                    </clickhouse>
                  permission: null
                  envsubst: null
        - name: plausible
          icon: https://asset.brandfetch.io/id2ceYC7ck/idkMMiHKhK.png
          template: PREBUILT
          spec:
            source:
                image: ghcr.io/plausible/community-edition:v3.0.1
                command:
                    - sh
                args:
                    - -c
                    - sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh run
            ports:
                - id: web
                  port: 8000
                  type: HTTP
            env:
                BASE_URL:
                    default: ${ZEABUR_WEB_URL}
                CLICKHOUSE_DATABASE_URL:
                    default: http://${CLICKHOUSE_USER}:${CLICKHOUSE_PASSWORD}@clickhouse.zeabur.internal:8123/${CLICKHOUSE_DB}
                DATABASE_URL:
                    default: postgres://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DATABASE}
                SECRET_KEY_BASE:
                    default: ${PASSWORD}${PASSWORD}${PASSWORD}${PASSWORD}
                TOTP_VAULT_KEY:
                    default: dsxvbn3jxDd16az2QpsX5B8O+llxjQ2SJE2i5Bzx38I=
          domainKey: DOMAIN
