# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: RSS3 Node
spec:
    description: A lightweight service that joins the RSS3 Network as a node.
    coverImage: https://a-us.storyblok.com/f/1018186/2600x1420/59d1051f18/chips.png
    icon: https://avatars.githubusercontent.com/u/152575164?s=48&v=4
    variables:
        - key: EVM_ADDRESS
          type: STRING
          name: What is your operator evm address?
          description: Used for the operator evm address for your node.
        - key: SIGNATURE
          type: STRING
          name: What is your operator signature?
          description: Used for the operator signature for your node.
        - key: WEB_URL
          type: DOMAIN
          name: What is your domain for the node?
          description: Used for expose the node to the public web.
        - key: GI_ENDPOINT
          type: STRING
          name: What is your global indexer endpoint?
          description: Used for the global indexer endpoint for your node.
    tags:
        - web3
    readme: |
        ## Prerequisites

        Before deploying, you need to create a node on the explorer: [RSS3 Explorer](https://explorer.rss3.io/nodes).

        Additionally, ensure that your Zeabur account is upgraded to at least the Developer Plan ($5/month).

        ## Deployment

        You only need to fill in two fields in the RSS3-Node service:
        - **Operator EVM Address**: Your wallet address (which is also your node address).
        - **Operator Signature**: The challenge signature obtained here: https://explorer.rss3.io/nodes/YOUR_WALLET_ADDRESS. (Click the "Signature" button to complete the challenge and copy your signature to paste here.)
        - **Custom Domain**: The domain name you want to use for your node.
        - **Global Indexer Endpoint**: The global indexer endpoint for your node. (You can use the default value.)

        After the service starts, it will join the RSS3 Network as a lightweight RSS3 Node.

        ## Contact

        If you have any questions, feel free to contact me: [pseudoyu@rss3.io](mailto:pseudoyu@rss3.io).
    services:
        - name: Redis
          icon: https://raw.githubusercontent.com/zeabur/service-icons/main/marketplace/redis.svg
          template: PREBUILT
          spec:
            source:
                image: redis/redis-stack-server:latest
            ports:
                - id: database
                  port: 6379
                  type: TCP
            volumes:
                - id: data
                  dir: /data
            instructions:
                - title: Command to connect to your Redis
                  content: redis-cli -h ${PORT_FORWARDED_HOSTNAME} -p ${DATABASE_PORT_FORWARDED_PORT} -a ${REDIS_PASSWORD}
                - title: Redis Connection String
                  content: redis://:${REDIS_PASSWORD}@${PORT_FORWARDED_HOSTNAME}:${DATABASE_PORT_FORWARDED_PORT}
                - title: Redis password
                  content: ${REDIS_PASSWORD}
                - title: Redis host
                  content: ${PORT_FORWARDED_HOSTNAME}
                - title: Redis port
                  content: ${DATABASE_PORT_FORWARDED_PORT}
            env:
                REDIS_ARGS:
                    default: --requirepass ${REDIS_PASSWORD}
                REDIS_CONNECTION_STRING:
                    default: redis://:${REDIS_PASSWORD}@${REDIS_HOST}:${REDIS_PORT}
                    expose: true
                REDIS_HOST:
                    default: ${CONTAINER_HOSTNAME}
                    expose: true
                REDIS_PASSWORD:
                    default: ${PASSWORD}
                    expose: true
                REDIS_PORT:
                    default: ${DATABASE_PORT}
                    expose: true
                REDIS_URI:
                    default: ${REDIS_CONNECTION_STRING}
                    expose: true
        - name: PostgreSQL
          icon: https://raw.githubusercontent.com/zeabur/service-icons/main/marketplace/postgresql.svg
          template: PREBUILT
          spec:
            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: 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: RSSHub
          icon: https://cdn.zeabur.com/rss-logo.png
          dependencies:
            - Redis
          template: PREBUILT
          spec:
            source:
                image: diygod/rsshub
            ports:
                - id: web
                  port: 1200
                  type: HTTP
            env:
                CACHE_TYPE:
                    default: redis
                REDIS_URL:
                    default: ${REDIS_URI}
        - name: AgentData
          icon: https://avatars.githubusercontent.com/u/184013737?s=200&v=4
          dependencies:
            - PostgreSQL
          template: PREBUILT
          spec:
            source:
                image: ghcr.io/rss3-network/agentdata:0.1.0
            ports:
                - id: web
                  port: 8887
                  type: HTTP
            env:
                DB_CONNECTION:
                    default: ${POSTGRES_CONNECTION_STRING}
        - name: RSS3-Node-Core
          icon: https://explorer.rss3.io/rss3.svg
          dependencies:
            - Redis
            - AgentData
          template: PREBUILT
          spec:
            source:
                image: ghcr.io/rss3-network/node:v2.0.0
                command:
                    - ./node
                    - --module=core
            ports:
                - id: web
                  port: 80
                  type: HTTP
            env:
                CORE_PASSWORD:
                    default: ${PASSWORD}
                    expose: true
                NODE_COMPONENT_AI_ENDPOINT:
                    default: http://agentdata.zeabur.internal:8887
                NODE_COMPONENT_RSS_ENDPOINT:
                    default: http://rsshub.zeabur.internal:1200
                NODE_DISCOVERY_OPERATOR_EVM_ADDRESS:
                    default: ${EVM_ADDRESS}
                NODE_DISCOVERY_OPERATOR_SIGNATURE:
                    default: ${SIGNATURE}
                NODE_DISCOVERY_SERVER_ACCESS_TOKEN:
                    default: ${PASSWORD}
                NODE_DISCOVERY_SERVER_GLOBAL_INDEXER_ENDPOINT:
                    default: ${GI_ENDPOINT}
                NODE_OBSERVABILITY_OPENTELEMETRY_METRICS_ENABLE:
                    default: "false"
                NODE_OBSERVABILITY_OPENTELEMETRY_TRACES_ENABLE:
                    default: "false"
                NODE_REDIS_ENDPOINT:
                    default: ${REDIS_HOST}:${REDIS_PORT}
                NODE_REDIS_PASSWORD:
                    default: ${REDIS_PASSWORD}
                PUBLIC_DOMAIN:
                    default: ${ZEABUR_WEB_URL}
                    expose: true
          domainKey: WEB_URL
        - name: RSS3-Node-Broadcaster
          icon: https://explorer.rss3.io/rss3.svg
          dependencies:
            - RSS3-Node-Core
            - AgentData
          template: PREBUILT
          spec:
            source:
                image: ghcr.io/rss3-network/node:v2.0.0
                command:
                    - ./node
                    - --module=broadcaster
            env:
                NODE_COMPONENT_AI_ENDPOINT:
                    default: http://agentdata.zeabur.internal:8887
                NODE_COMPONENT_RSS_ENDPOINT:
                    default: http://rsshub.zeabur.internal:1200
                NODE_DISCOVERY_OPERATOR_EVM_ADDRESS:
                    default: ${EVM_ADDRESS}
                NODE_DISCOVERY_OPERATOR_SIGNATURE:
                    default: ${SIGNATURE}
                NODE_DISCOVERY_SERVER_ACCESS_TOKEN:
                    default: ${CORE_PASSWORD}
                NODE_DISCOVERY_SERVER_ENDPOINT:
                    default: ${PUBLIC_DOMAIN}
                NODE_DISCOVERY_SERVER_GLOBAL_INDEXER_ENDPOINT:
                    default: ${GI_ENDPOINT}
                NODE_OBSERVABILITY_OPENTELEMETRY_METRICS_ENABLE:
                    default: "false"
                NODE_OBSERVABILITY_OPENTELEMETRY_TRACES_ENABLE:
                    default: "false"
        - name: RSS3-Node-Monitor
          icon: https://explorer.rss3.io/rss3.svg
          dependencies:
            - Redis
            - AgentData
          template: PREBUILT
          spec:
            source:
                image: ghcr.io/rss3-network/node:v2.0.0
                command:
                    - ./node
                    - --module=monitor
            env:
                NODE_COMPONENT_AI_ENDPOINT:
                    default: http://agentdata.zeabur.internal:8887
                NODE_COMPONENT_RSS_ENDPOINT:
                    default: http://rsshub.zeabur.internal:1200
                NODE_REDIS_ENDPOINT:
                    default: ${REDIS_HOST}:${REDIS_PORT}
                NODE_REDIS_PASSWORD:
                    default: ${REDIS_PASSWORD}
