# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: Astron RPA Server Stack
spec:
    description: Open-source Astron RPA backend stack with API gateway, auth, resource services, object storage and supporting infrastructure. Desktop client is not included.
    coverImage: https://raw.githubusercontent.com/iflytek/astron-rpa/main/docs/images/icon_128px.png
    icon: https://raw.githubusercontent.com/iflytek/astron-rpa/main/docs/images/icon.png
    variables:
        - key: PUBLIC_DOMAIN
          type: DOMAIN
          name: Gateway Domain
          description: Public domain bound to the OpenResty API gateway.
        - key: CASDOOR_DOMAIN
          type: DOMAIN
          name: Casdoor Domain
          description: Public domain bound to the Casdoor authentication service.
        - key: DATABASE_PASSWORD
          type: STRING
          name: MySQL Root Password
          description: Password for the bundled MySQL instance.
        - key: MINIO_AK
          type: STRING
          name: MinIO Access Key
          description: Access key for the bundled MinIO service.
        - key: MINIO_SK
          type: STRING
          name: MinIO Secret Key
          description: Secret key for the bundled MinIO service.
        - key: AICHAT_BASE_URL
          type: STRING
          name: AIChat Base URL
          description: OpenAI-compatible chat endpoint for AI features.
        - key: AICHAT_API_KEY
          type: STRING
          name: AIChat API Key
          description: API key for the configured AIChat endpoint.
    tags:
        - RPA
        - Automation
        - AI
        - Backend
    readme: |
        # Astron RPA Server Stack

        This template deploys the **server-side stack** of Astron RPA to Zeabur:
        gateway, auth, AI service, OpenAPI service, robot service, resource service,
        MySQL, Redis, MinIO and Casdoor.

        ## What This Template Includes

        - `gateway`: OpenResty API gateway
        - `casdoor`: authentication service
        - `mysql`, `redis`, `minio`: infrastructure
        - `ai-service`, `openapi-service`, `resource-service`, `robot-service`, `rpa-auth`

        ## Important Scope

        - This is **not** the full Astron RPA desktop product.
        - The upstream project includes Electron / desktop components that still need
          to be obtained separately.
        - This template focuses on the deployable backend services and public APIs.

        ## Deployment Notes

        1. Bind `PUBLIC_DOMAIN` to `gateway`.
        2. Bind `CASDOOR_DOMAIN` to `casdoor`.
        3. Set `AICHAT_BASE_URL` and `AICHAT_API_KEY` if you want AI chat features.
        4. After deploy, verify:
           - `https://<PUBLIC_DOMAIN>/health`
           - `https://<CASDOOR_DOMAIN>`
        5. The template bootstraps MySQL schema, seed data, Casdoor init data and
           gateway config from the upstream GitHub repository at startup.

        ## Source

        - Repository: https://github.com/iflytek/astron-rpa
    resourceRequirement:
        minConfig:
            cpu: 4
            ram: 8
        recommendedConfig:
            cpu: 8
            ram: 16
    services:
        - name: mysql
          icon: https://raw.githubusercontent.com/zeabur/service-icons/main/marketplace/mysql.svg
          template: PREBUILT_V2
          spec:
            id: mysql
            source:
                image: mysql:8.4.6
            ports:
                - id: database
                  port: 3306
                  type: TCP
            volumes:
                - id: data
                  dir: /var/lib/mysql
            env:
                MYSQL_DATABASE:
                    default: rpa
                    expose: true
                MYSQL_ROOT_PASSWORD:
                    default: ${DATABASE_PASSWORD}
            configs:
                - path: /entrypoint.sh
                  template: |
                    #!/bin/bash
                    set -e
                    mkdir -p /docker-entrypoint-initdb.d
                    cat >/docker-entrypoint-initdb.d/00-create-casdoor.sql <<'SQL'
                    CREATE DATABASE IF NOT EXISTS casdoor DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
                    SQL
                    base="https://raw.githubusercontent.com/iflytek/astron-rpa/main/docker/volumes/mysql"
                    wget -qO /docker-entrypoint-initdb.d/01-schema.sql "${base}/schema.sql"
                    wget -qO /docker-entrypoint-initdb.d/02-init_app_market_dict_data.sql "${base}/init_app_market_dict_data.sql"
                    wget -qO /docker-entrypoint-initdb.d/04-init_his_data_enum_data.sql "${base}/init_his_data_enum_data.sql"
                    wget -qO /docker-entrypoint-initdb.d/05-init_sample_template_data.sql "${base}/init_sample_template_data.sql"
                    wget -qO /docker-entrypoint-initdb.d/06-init_c_atom_meta_new_data.sql "${base}/init_c_atom_meta_new_data.sql"
                    exec docker-entrypoint.sh mysqld
                  permission: 493
                  envsubst: null
        - name: atlas
          icon: https://raw.githubusercontent.com/iflytek/astron-rpa/main/docs/images/icon.png
          template: PREBUILT_V2
          spec:
            id: atlas
            source:
                image: arigaio/atlas:latest
            env:
                DATABASE_PASSWORD:
                    default: ${DATABASE_PASSWORD}
        - name: redis
          icon: https://raw.githubusercontent.com/zeabur/service-icons/main/marketplace/redis.svg
          template: PREBUILT_V2
          spec:
            id: redis
            source:
                image: redis:7-alpine
                command:
                    - redis-server
                    - --appendonly
                    - "yes"
            ports:
                - id: database
                  port: 6379
                  type: TCP
            volumes:
                - id: data
                  dir: /data
        - name: minio
          icon: https://raw.githubusercontent.com/zeabur/service-icons/main/marketplace/minio.svg
          template: PREBUILT_V2
          spec:
            id: minio
            source:
                image: minio/minio:RELEASE.2025-06-13T11-33-47Z-cpuv1
            ports:
                - id: api
                  port: 9000
                  type: HTTP
                - id: console
                  port: 9001
                  type: HTTP
            volumes:
                - id: data
                  dir: /data
            env:
                MINIO_ROOT_PASSWORD:
                    default: ${MINIO_SK}
                MINIO_ROOT_USER:
                    default: ${MINIO_AK}
        - name: casdoor
          icon: https://raw.githubusercontent.com/zeabur/service-icons/main/marketplace/casdoor.svg
          template: PREBUILT_V2
          spec:
            id: casdoor
            source:
                image: casbin/casdoor:v2.67.0
            ports:
                - id: web
                  port: 8000
                  type: HTTP
            env:
                CASDOOR_ENABLE_HTTP_WEBHOOK:
                    default: "true"
                DATABASE_PASSWORD:
                    default: ${DATABASE_PASSWORD}
                dataSourceName:
                    default: root:${DATABASE_PASSWORD}@tcp(mysql.zeabur.internal:3306)/
                driverName:
                    default: mysql
            configs:
                - path: /entrypoint.sh
                  template: |
                    #!/bin/sh
                    set -e
                    wget -qO /init_data.json "https://raw.githubusercontent.com/iflytek/astron-rpa/main/docker/volumes/casdoor/init_data_dump.json"
                    exec /server --createDatabase=true
                  permission: 493
                  envsubst: null
          domainKey: CASDOOR_DOMAIN
        - name: ai-service
          icon: https://raw.githubusercontent.com/iflytek/astron-rpa/main/docs/images/icon.png
          template: PREBUILT_V2
          spec:
            id: ai-service
            source:
                image: ghcr.io/iflytek/astron-rpa/ai-service:latest
            ports:
                - id: web
                  port: 8010
                  type: HTTP
            env:
                AICHAT_API_KEY:
                    default: ${AICHAT_API_KEY}
                AICHAT_BASE_URL:
                    default: ${AICHAT_BASE_URL}
                AICHAT_POINTS_COST:
                    default: "100"
                CUA_API_KEY:
                    default: ""
                CUA_BASE_URL:
                    default: ""
                DATABASE_NAME:
                    default: rpa
                DATABASE_PASSWORD:
                    default: ${DATABASE_PASSWORD}
                DATABASE_URL:
                    default: mysql+aiomysql://root:${DATABASE_PASSWORD}@mysql.zeabur.internal:3306/rpa
                DATABASE_USERNAME:
                    default: root
                JFBYM_API_TOKEN:
                    default: ""
                JFBYM_ENDPOINT:
                    default: ""
                JFBYM_POINTS_COST:
                    default: "10"
                LOG_DIR:
                    default: /app/log
                LOG_LEVEL:
                    default: INFO
                MONTHLY_GRANT_AMOUNT:
                    default: "100000"
                OCR_GENERAL_POINTS_COST:
                    default: "50"
                REDIS_DB:
                    default: "0"
                REDIS_HOST:
                    default: redis.zeabur.internal
                REDIS_PORT:
                    default: "6379"
                REDIS_URL:
                    default: redis://redis.zeabur.internal:6379/0
                XFYUN_API_KEY:
                    default: ""
                XFYUN_API_SECRET:
                    default: ""
                XFYUN_APP_ID:
                    default: ""
        - name: openapi-service
          icon: https://raw.githubusercontent.com/iflytek/astron-rpa/main/docs/images/icon.png
          template: PREBUILT_V2
          spec:
            id: openapi-service
            source:
                image: ghcr.io/iflytek/astron-rpa/openapi-service:latest
            ports:
                - id: web
                  port: 8020
                  type: HTTP
            env:
                API_VERSION:
                    default: "1.0"
                APP_NAME:
                    default: RPA OpenAPI
                DATABASE_PASSWORD:
                    default: ${DATABASE_PASSWORD}
                DATABASE_URL:
                    default: mysql+aiomysql://root:${DATABASE_PASSWORD}@mysql.zeabur.internal:3306/rpa
                DATABASE_USERNAME:
                    default: root
                LOG_DIR:
                    default: /var/log/rpa-openapi
                LOG_LEVEL:
                    default: INFO
                REDIS_URL:
                    default: redis://redis.zeabur.internal:6379/0
        - name: resource-service
          icon: https://raw.githubusercontent.com/iflytek/astron-rpa/main/docs/images/icon.png
          template: PREBUILT_V2
          spec:
            id: resource-service
            source:
                image: ghcr.io/iflytek/astron-rpa/resource-service:latest
            ports:
                - id: web
                  port: 8030
                  type: HTTP
            env:
                DATABASE_HOST:
                    default: mysql.zeabur.internal
                DATABASE_NAME:
                    default: rpa
                DATABASE_PASSWORD:
                    default: ${DATABASE_PASSWORD}
                DATABASE_PORT:
                    default: "3306"
                DATABASE_USERNAME:
                    default: root
                MINIO_AK:
                    default: ${MINIO_AK}
                MINIO_BUCKET:
                    default: rpa-resource
                MINIO_SK:
                    default: ${MINIO_SK}
                MINIO_URL:
                    default: http://minio.zeabur.internal:9000
                REDIS_DB:
                    default: "0"
                REDIS_HOST:
                    default: redis.zeabur.internal
                REDIS_PASSWORD:
                    default: ""
                REDIS_PORT:
                    default: "6379"
        - name: robot-service
          icon: https://raw.githubusercontent.com/iflytek/astron-rpa/main/docs/images/icon.png
          template: PREBUILT_V2
          spec:
            id: robot-service
            source:
                image: ghcr.io/iflytek/astron-rpa/robot-service:latest
            ports:
                - id: web
                  port: 8040
                  type: HTTP
            env:
                DATABASE_HOST:
                    default: mysql.zeabur.internal
                DATABASE_NAME:
                    default: rpa
                DATABASE_PASSWORD:
                    default: ${DATABASE_PASSWORD}
                DATABASE_PORT:
                    default: "3306"
                DATABASE_USERNAME:
                    default: root
                REDIS_DB:
                    default: "0"
                REDIS_HOST:
                    default: redis.zeabur.internal
                REDIS_PASSWORD:
                    default: ""
                REDIS_PORT:
                    default: "6379"
        - name: rpa-auth
          icon: https://raw.githubusercontent.com/iflytek/astron-rpa/main/docs/images/icon.png
          template: PREBUILT_V2
          spec:
            id: rpa-auth
            source:
                image: ghcr.io/iflytek/astron-rpa/rpa-auth:latest
            ports:
                - id: web
                  port: 10251
                  type: HTTP
            env:
                CASDOOR_APPLICATION_NAME:
                    default: example-app
                CASDOOR_CLIENT_ID:
                    default: e3ba6fec42cfe996121f
                CASDOOR_CLIENT_SECRET:
                    default: 0c18bf2a11ffbb756ec6ce47dae9e09bdd48e3dd
                CASDOOR_DATABASE_HOST:
                    default: mysql.zeabur.internal
                CASDOOR_DATABASE_PASSWORD:
                    default: ${DATABASE_PASSWORD}
                CASDOOR_DATABASE_PORT:
                    default: "3306"
                CASDOOR_DATABASE_USERNAME:
                    default: root
                CASDOOR_ENDPOINT:
                    default: http://casdoor.zeabur.internal:8000
                CASDOOR_EXTERNAL_ENDPOINT:
                    default: https://${CASDOOR_DOMAIN}
                CASDOOR_ORGANIZATION_NAME:
                    default: example-org
                CASDOOR_REDIRECT_URL:
                    default: https://${PUBLIC_DOMAIN}/api/rpa-auth/login/oauth2/code/casdoor
                DATABASE_HOST:
                    default: mysql.zeabur.internal
                DATABASE_NAME:
                    default: rpa
                DATABASE_PASSWORD:
                    default: ${DATABASE_PASSWORD}
                DATABASE_PORT:
                    default: "3306"
                DATABASE_USERNAME:
                    default: root
                REDIS_DB:
                    default: "0"
                REDIS_HOST:
                    default: redis.zeabur.internal
                REDIS_PASSWORD:
                    default: ""
                REDIS_PORT:
                    default: "6379"
        - name: gateway
          icon: https://raw.githubusercontent.com/zeabur/service-icons/main/marketplace/nginx.svg
          template: PREBUILT_V2
          spec:
            id: gateway
            source:
                image: openresty/openresty:1.27.1.1-alpine
            ports:
                - id: web
                  port: 80
                  type: HTTP
            configs:
                - path: /entrypoint.sh
                  template: |
                    #!/bin/sh
                    set -e
                    mkdir -p /etc/nginx/conf.d /usr/local/openresty/nginx/lua
                    wget -qO /etc/nginx/conf.d/default.conf "https://raw.githubusercontent.com/iflytek/astron-rpa/main/docker/volumes/nginx/default.conf"
                    wget -qO /usr/local/openresty/nginx/lua/auth_handler.lua "https://raw.githubusercontent.com/iflytek/astron-rpa/main/docker/volumes/nginx/lua/auth_handler.lua"
                    exec openresty -g 'daemon off;'
                  permission: 493
                  envsubst: null
          domainKey: PUBLIC_DOMAIN
