# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: TP Internal Colanode
spec:
    description: Colanode for ThinkingPower internal communication and collaboration.
    icon: https://raw.githubusercontent.com/colanode/colanode/main/apps/web/public/favicon.svg
    variables:
        - key: WEB_DOMAIN
          type: DOMAIN
          name: Web domain
          description: Public Colanode web domain.
        - key: API_DOMAIN
          type: DOMAIN
          name: API domain
          description: Public Colanode API domain.
    tags:
        - Communication
        - Collaboration
    readme: |-
        # TP Internal Colanode

        This template deploys Colanode with Postgres, Valkey, a server API, and a web client.
        Secrets are generated by Zeabur at deploy time.
    services:
        - name: colanode-postgres
          template: PREBUILT
          spec:
            id: colanode-postgres
            source:
                image: pgvector/pgvector:pg17
            ports:
                - id: database
                  port: 5432
                  type: TCP
            volumes:
                - id: data
                  dir: /var/lib/postgresql/data
            env:
                COLANODE_POSTGRES_HOST:
                    default: ${CONTAINER_HOSTNAME}
                    expose: true
                COLANODE_POSTGRES_PORT:
                    default: ${DATABASE_PORT}
                    expose: true
                COLANODE_POSTGRES_URL:
                    default: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${COLANODE_POSTGRES_HOST}:${COLANODE_POSTGRES_PORT}/${POSTGRES_DB}
                    expose: true
                POSTGRES_DB:
                    default: colanode_db
                    expose: true
                POSTGRES_PASSWORD:
                    default: ${PASSWORD}
                    expose: true
                POSTGRES_USER:
                    default: colanode_user
                    expose: true
        - name: colanode-valkey
          template: PREBUILT
          spec:
            id: colanode-valkey
            source:
                image: valkey/valkey:8.1
            ports:
                - id: database
                  port: 6379
                  type: TCP
            volumes:
                - id: data
                  dir: /data
            env:
                COLANODE_REDIS_URL:
                    default: redis://${COLANODE_VALKEY_HOST}:${COLANODE_VALKEY_PORT}/0
                    expose: true
                COLANODE_VALKEY_HOST:
                    default: ${CONTAINER_HOSTNAME}
                    expose: true
                COLANODE_VALKEY_PORT:
                    default: ${DATABASE_PORT}
                    expose: true
        - name: colanode-server
          template: PREBUILT
          spec:
            id: colanode-server
            source:
                image: ghcr.io/colanode/server:latest
            ports:
                - id: web
                  port: 3000
                  type: HTTP
            volumes:
                - id: storage
                  dir: /var/lib/colanode/storage
            env:
                CONFIG:
                    default: /config.json
                NODE_ENV:
                    default: production
                PORT:
                    default: "3000"
                POSTGRES_URL:
                    default: ${COLANODE_POSTGRES_URL}
                REDIS_URL:
                    default: ${COLANODE_REDIS_URL}
            configs:
                - path: /config.json
                  template: |-
                    {
                      "name": "ThinkingPower Colanode",
                      "mode": "standalone",
                      "cors": {
                        "origin": ["https://${WEB_DOMAIN}"],
                        "maxAge": 7200
                      },
                      "storage": {
                        "provider": {
                          "type": "file",
                          "directory": "/var/lib/colanode/storage"
                        }
                      }
                    }
                  permission: null
                  envsubst: true
          domainKey: API_DOMAIN
        - name: colanode-web
          template: PREBUILT
          spec:
            id: colanode-web
            source:
                image: ghcr.io/colanode/web:latest
            ports:
                - id: web
                  port: 80
                  type: HTTP
            env:
                SERVER_URL:
                    default: https://${API_DOMAIN}
          domainKey: WEB_DOMAIN
