# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: Refly AI
spec:
    description: The AI Native Creation Engine
    coverImage: https://cdn.zeabur.com/refly-banner.png
    icon: https://avatars.githubusercontent.com/u/132635806?s=500&v=4
    variables:
        - key: GENERATED_DOMAIN_PREFIX
          type: DOMAIN
          name: Public Domain
          description: The domain you want to use for your Refly AI website
    readme: |-
        Refly is an open-source AI-native creation engine. It's intuitive free-form canvas interface combines multi-threaded conversations, knowledge base RAG integration, contextual memory, intelligent search, WYSIWYG AI editor and more, empowering you to effortlessly transform ideas into production-ready content.

        For details, see [their homepage](https://refly.ai).
    services:
        - name: postgresql
          icon: https://cdn.zeabur.com/marketplace/postgresql.svg
          template: PREBUILT_V2
          spec:
            id: postgresql
            source:
                image: postgres:17
                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
                    expose: false
                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
                    expose: false
                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
                    expose: false
                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: redis
          icon: https://raw.githubusercontent.com/zeabur/service-icons/main/marketplace/redis.svg
          template: PREBUILT_V2
          spec:
            id: redis
            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:
                CONFFILE:
                    default: /etc/redis-stack.conf
                    expose: false
                REDIS_ARGS:
                    default: --requirepass ${REDIS_PASSWORD}
                    expose: false
                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
            configs:
                - path: /etc/redis-stack.conf
                  template: |
                    port 6379
                    daemonize no
                  permission: null
                  envsubst: null
        - name: minio
          icon: https://cdn.zeabur.com/marketplace/minio.svg
          template: PREBUILT_V2
          spec:
            id: minio
            source:
                image: quay.io/minio/minio:latest
                command:
                    - /bin/sh
                args:
                    - -c
                    - |
                      minio server /data --console-address :9090 &
                      MINIO_PID=$!
                      while ! curl -s http://localhost:9000/minio/health/live; do
                        echo 'Waiting for MinIO to start...'
                        sleep 1
                      done
                      sleep 5
                      mc alias set myminio http://localhost:9000 $MINIO_USERNAME $MINIO_PASSWORD
                      echo "Creating bucket '$MINIO_DEFAULT_BUCKET'"
                      mc mb myminio/$MINIO_DEFAULT_BUCKET
                      wait $MINIO_PID
            ports:
                - id: web
                  port: 9000
                  type: HTTP
                - id: console
                  port: 9090
                  type: HTTP
            volumes:
                - id: data
                  dir: /data
            instructions:
                - title: Go to MinIO Console
                  content: ${MINIO_CONSOLE_URL}
                - title: Default Username (S3 Access Key ID)
                  content: ${MINIO_USERNAME}
                - title: Default Password (S3 Secret Access Key)
                  content: ${MINIO_PASSWORD}
                - title: Default Bucket
                  content: ${MINIO_DEFAULT_BUCKET}
            env:
                MINIO_BROWSER_REDIRECT:
                    default: "false"
                    expose: false
                MINIO_CONSOLE_URL:
                    default: ${ZEABUR_CONSOLE_URL}
                    expose: true
                MINIO_DEFAULT_BUCKET:
                    default: zeabur
                    expose: false
                MINIO_PASSWORD:
                    default: ${MINIO_ROOT_PASSWORD}
                    expose: true
                MINIO_ROOT_PASSWORD:
                    default: ${PASSWORD}
                    expose: false
                MINIO_ROOT_USER:
                    default: minio
                    expose: false
                MINIO_USERNAME:
                    default: ${MINIO_ROOT_USER}
                    expose: true
            configs: []
        - name: qdrant
          icon: https://avatars.githubusercontent.com/u/73504361?s=500&v=4
          template: PREBUILT_V2
          spec:
            id: qdrant
            source:
                image: reflyai/qdrant:v1.13.1
            ports:
                - id: http
                  port: 6333
                  type: HTTP
            volumes:
                - id: data
                  dir: /qdrant/storage
            env: {}
            configs: []
        - name: elasticsearch
          icon: https://avatars.githubusercontent.com/u/6764390?s=500&v=4
          template: PREBUILT_V2
          spec:
            id: elasticsearch
            source:
                image: reflyai/elasticsearch:7.10.2
            ports:
                - id: http
                  port: 9200
                  type: HTTP
            volumes:
                - id: data
                  dir: /usr/share/elasticsearch/data
            env: {}
            configs:
                - path: /usr/share/elasticsearch/config/elasticsearch.yml
                  template: |-
                    discovery.type: single-node
                    xpack.security.enabled: false
                    network.host: "0.0.0.0"
                  permission: null
                  envsubst: null
        - name: api
          icon: https://avatars.githubusercontent.com/u/132635806?s=500&v=4
          dependencies:
            - postgresql
            - redis
            - minio
            - qdrant
            - elasticsearch
          template: PREBUILT_V2
          spec:
            id: api
            source:
                image: reflyai/refly-api:nightly
                command:
                    - /bin/sh
                args:
                    - -c
                    - cd /app/apps/api/dist && node scripts/sync-db-schema.js && node main.js
            ports:
                - id: http
                  port: 5800
                  type: HTTP
                - id: collab
                  port: 5801
                  type: HTTP
            env:
                AUTH_SKIP_VERIFICATION:
                    default: "true"
                    expose: false
                DATABASE_URL:
                    default: ${POSTGRES_CONNECTION_STRING}?schema=refly
                    expose: false
                ELASTICSEARCH_PASSWORD:
                    default: "1"
                    expose: false
                ELASTICSEARCH_URL:
                    default: http://${ELASTICSEARCH_HOST}:9200
                    expose: false
                ELASTICSEARCH_USERNAME:
                    default: "1"
                    expose: false
                HOST:
                    default: 0.0.0.0
                    expose: false
                JINA_API_KEY:
                    default: "123"
                    expose: false
                MINIO_EXTERNAL_ACCESS_KEY:
                    default: ${MINIO_USERNAME}
                    expose: false
                MINIO_EXTERNAL_BUCKET:
                    default: refly
                    expose: false
                MINIO_EXTERNAL_ENDPOINT:
                    default: minio
                    expose: false
                MINIO_EXTERNAL_PORT:
                    default: "true"
                    expose: false
                MINIO_EXTERNAL_SECRET_KEY:
                    default: ${MINIO_PASSWORD}
                    expose: false
                MINIO_EXTERNAL_USE_SSL:
                    default: "443"
                    expose: false
                MINIO_INTERNAL_ACCESS_KEY:
                    default: ${MINIO_USERNAME}
                    expose: false
                MINIO_INTERNAL_BUCKET:
                    default: refly
                    expose: false
                MINIO_INTERNAL_ENDPOINT:
                    default: ${MINIO_HOST}
                    expose: false
                MINIO_INTERNAL_PORT:
                    default: "9000"
                    expose: false
                MINIO_INTERNAL_SECRET_KEY:
                    default: ${MINIO_PASSWORD}
                    expose: false
                MINIO_INTERNAL_USE_SSL:
                    default: "false"
                    expose: false
                OPENAI_API_KEY:
                    default: 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
                    expose: false
                PUBLIC_DOMAIN:
                    default: ${GENERATED_DOMAIN_PREFIX}.zeabur.app
                    expose: true
                QDRANT_PORT:
                    default: "6333"
                    expose: false
                REFLY_VEC_DIM:
                    default: "768"
                    expose: false
                RESEND_API_KEY:
                    default: re_123
                    expose: false
                STATIC_PRIVATE_ENDPOINT:
                    default: https://${PUBLIC_DOMAIN}/api/v1/misc
                    expose: true
                STATIC_PUBLIC_ENDPOINT:
                    default: https://${PUBLIC_DOMAIN}/api/v1/misc/public
                    expose: true
            configs: []
        - name: web
          icon: https://avatars.githubusercontent.com/u/132635806?s=500&v=4
          dependencies:
            - api
          template: PREBUILT_V2
          spec:
            id: web
            source:
                image: reflyai/refly-web:nightly
            ports:
                - id: http
                  port: 80
                  type: HTTP
            env:
                API_URL:
                    default: /api
                    expose: false
                COLLAB_URL:
                    default: /collab
                    expose: false
                STATIC_PRIVATE_ENDPOINT:
                    default: /api/v1/misc
                    expose: false
                STATIC_PUBLIC_ENDPOINT:
                    default: /api/v1/misc/public
                    expose: false
            configs: []
          domainKey: GENERATED_DOMAIN_PREFIX
