# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: Rallly
spec:
    description: Self-hosted Rallly (Doodle alternative) with PostgreSQL on Zeabur.
    coverImage: https://rallly.co/zh/opengraph-image.png
    icon: https://raw.githubusercontent.com/lukevella/rallly/refs/heads/main/apps/web/public/favicon.ico
    variables:
        - key: BASE_DOMAIN
          type: DOMAIN
          name: Domain
          description: The domain you want to bind for your Rallly instance.
        - key: SECRET_PASSWORD
          type: STRING
          name: Secret Password
          description: 32-character secret key used to encrypt user sessions.
        - key: SUPPORT_EMAIL
          type: STRING
          name: Support Email
          description: Contact email shown in the app for support queries.
        - key: GOOGLE_CLIENT_ID
          type: STRING
          name: Google Client ID
          description: Google OAuth Client ID for authentication.
        - key: GOOGLE_CLIENT_SECRET
          type: STRING
          name: Google Client Secret
          description: Google OAuth Client Secret for authentication.
    tags:
        - Tool
        - Scheduling
        - Collaboration
    readme: |-
        # Rallly

        This template deploys a self-hosted instance of **Rallly** with **PostgreSQL** on Zeabur.

        Rallly is an open-source scheduling and poll tool, similar to Doodle.

        ## Features

        - Create polls to find the best date or option
        - Clean and modern UI
        - Google OAuth authentication

        ## Required Environment Variables

        - `NEXT_PUBLIC_BASE_URL` – Base URL of your instance (includes scheme and domain)
        - `SECRET_PASSWORD` – 32-character secret for session encryption (you can generate one at https://jwtsecrets.com/)
        - `SUPPORT_EMAIL` – Shown as contact email in the UI
        - `DATABASE_URL` – Postgres connection string (auto-generated from the PostgreSQL service)

        ## Authentication Setup

        ### Google OAuth

        1. Go to [Google Cloud Console](https://console.developers.google.com/apis/credentials)
        2. Create a new project or select an existing one
        3. Create OAuth 2.0 Client ID
        4. Set "Authorized redirect URIs" to: `https://DOMAIN.zeabur.app/api/auth/callback/google`
           - Replace `DOMAIN` with your actual domain
        5. Copy the Client ID and Client Secret
        6. Set `GOOGLE_CLIENT_ID` and `GOOGLE_CLIENT_SECRET` environment variables

        For detailed setup instructions, visit: https://support.rallly.co/self-hosting/configuration#google

        ## Additional Configuration

        You can customize more settings including email login and SMTP configuration.

        For more configuration options, please refer to the official documentation:
        https://support.rallly.co/self-hosting/configuration
    services:
        - name: PostgreSQL
          icon: https://raw.githubusercontent.com/zeabur/service-icons/main/marketplace/postgresql.svg
          template: PREBUILT
          spec:
            id: postgresql
            source:
                image: postgres:16
                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: postgres://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${PORT_FORWARDED_HOSTNAME}:${DATABASE_PORT_FORWARDED_PORT}/${POSTGRES_DATABASE}
                - title: PostgreSQL Connect Command
                  content: psql "postgres://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${PORT_FORWARDED_HOSTNAME}:${DATABASE_PORT_FORWARDED_PORT}/${POSTGRES_DATABASE}"
                - title: PostgreSQL username
                  content: ${POSTGRES_USERNAME}
                - title: PostgreSQL password
                  content: ${POSTGRES_PASSWORD}
                - title: PostgreSQL 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: postgres://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DATABASE}
                    expose: true
                POSTGRES_DATABASE:
                    default: ${POSTGRES_DB}
                    expose: true
                POSTGRES_DB:
                    default: rallly
                POSTGRES_HOST:
                    default: ${CONTAINER_HOSTNAME}
                    expose: true
                POSTGRES_PASSWORD:
                    default: ${PASSWORD}
                    expose: true
                POSTGRES_PORT:
                    default: "5432"
                    expose: true
                POSTGRES_URI:
                    default: ${POSTGRES_CONNECTION_STRING}
                    expose: true
                POSTGRES_USER:
                    default: postgres
                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
            healthCheck:
                type: TCP
                port: database
        - name: Rallly
          icon: https://raw.githubusercontent.com/lukevella/rallly/refs/heads/main/apps/web/public/favicon.ico
          dependencies:
            - PostgreSQL
          template: PREBUILT
          spec:
            id: rallly
            source:
                image: lukevella/rallly:latest
            ports:
                - id: web
                  port: 3000
                  type: HTTP
            env:
                DATABASE_URL:
                    default: postgres://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DATABASE}
                EMAIL_LOGIN_ENABLED:
                    default: "false"
                GOOGLE_CLIENT_ID:
                    default: ${GOOGLE_CLIENT_ID}
                GOOGLE_CLIENT_SECRET:
                    default: ${GOOGLE_CLIENT_SECRET}
                NEXT_PUBLIC_BASE_URL:
                    default: https://${BASE_DOMAIN}.zeabur.app
                SECRET_PASSWORD:
                    default: ${SECRET_PASSWORD}
                SUPPORT_EMAIL:
                    default: ${SUPPORT_EMAIL}
          domainKey: BASE_DOMAIN
localization:
    zh-TW:
        description: 自架版 Rallly（類似 Doodle 的開源行程投票工具），搭配 PostgreSQL，一鍵部署到 Zeabur。
        variables:
            - key: BASE_DOMAIN
              type: DOMAIN
              name: 網域
              description: 想要綁定在 Rallly 上的網域。
            - key: SECRET_PASSWORD
              type: STRING
              name: Secret 密鑰
              description: 用於加密使用者 Session 的 32 字元密鑰。
            - key: SUPPORT_EMAIL
              type: STRING
              name: 支援信箱
              description: 在介面中顯示的聯絡 / 支援 Email。
            - key: GOOGLE_CLIENT_ID
              type: STRING
              name: Google Client ID
              description: Google OAuth 用戶端 ID，用於 Google 登入認證。
            - key: GOOGLE_CLIENT_SECRET
              type: STRING
              name: Google Client Secret
              description: Google OAuth 用戶端密鑰，用於 Google 登入認證。
        readme: |-
            # Rallly

            這個模板會在 Zeabur 上部署一個自架的 **Rallly**，並搭配 **PostgreSQL** 資料庫。

            Rallly 是一個類似 Doodle 的開源行程投票工具。

            ## 功能特色

            - 建立投票來找出最佳日期或選項
            - 介面簡潔、現代
            - Google OAuth 認證登入

            ## 重要環境變數

            - `NEXT_PUBLIC_BASE_URL`：Rallly 網站對外的 Base URL（包含協定與網域）
            - `SECRET_PASSWORD`：用於加密 Session 的 32 字元密鑰（可到 https://jwtsecrets.com/ 生成）
            - `SUPPORT_EMAIL`：顯示於系統中的支援 / 聯絡 Email
            - `DATABASE_URL`：PostgreSQL 連線字串（由 PostgreSQL 服務自動產生）

            ## 認證設定

            ### Google OAuth

            1. 前往 [Google Cloud Console](https://console.developers.google.com/apis/credentials)
            2. 建立新專案或選擇現有專案
            3. 建立 OAuth 2.0 用戶端 ID
            4. 設定「已授權的重新導向 URI」為：`https://DOMAIN.zeabur.app/api/auth/callback/google`
               - 請將 `DOMAIN` 替換成你自己的網域
            5. 複製 Client ID 和 Client Secret
            6. 設定 `GOOGLE_CLIENT_ID` 和 `GOOGLE_CLIENT_SECRET` 環境變數

            更多 Google OAuth 設定說明，請參閱：https://support.rallly.co/self-hosting/configuration#google

            ## 進階設定

            你可以調整更多參數，包括啟用 Email 登入或設定 SMTP 等功能。

            更多設定選項請參考官方文件：
            https://support.rallly.co/self-hosting/configuration
