# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: Dify
spec:
    description: Dify is an open-source LLM app development platform.
    coverImage: https://cdn.zeabur.com/dify-banner.png
    icon: https://cdn.zeabur.com/dify-icon.png
    variables:
        - key: PUBLIC_DOMAIN
          type: DOMAIN
          name: Domain
          description: Domain of your Dify app.
    tags:
        - LLM
        - Workflow
        - AI
    readme: |
        Dify is an open-source LLM app development platform. Its intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.

        ## Features

        1. **Workflows**: Build and test powerful AI workflows on a visual canvas, leveraging all the following features and beyond.
        2. **Comprehensive model support**: Seamless integration with hundreds of proprietary / open-source LLMs from dozens of inference providers and self-hosted solutions, covering GPT, Mistral, Llama3, and any OpenAI API-compatible models. A full list of supported model providers can be found [in the Model Providers section](https://docs.dify.ai/getting-started/readme/model-providers).
        3. **Prompt IDE**: Intuitive interface for crafting prompts, comparing model performance, and adding additional features such as text-to-speech to a chat-based app.
        4. **RAG Pipeline**: Extensive RAG capabilities that cover everything from document ingestion to retrieval, with out-of-box support for text extraction from PDFs, PPTs, and other common document formats.
        5. **Agent capabilities**: You can define agents based on LLM Function Calling or ReAct, and add pre-built or custom tools for the agent. Dify provides 50+ built-in tools for AI agents, such as Google Search, DELL·E, Stable Diffusion and WolframAlpha.
        6. **LLMOps**: Monitor and analyze application logs and performance over time. You could continuously improve prompts, datasets, and models based on production data and annotations.
        7. **Backend-as-a-Service**: All of Dify's offerings come with corresponding APIs, so you could effortlessly integrate Dify into your own business logic.
        8. **Plugins**: Extend Dify's capabilities with plugins that can be installed from the marketplace or created by yourself.

        ## Deployment

        To deploy Dify, click the "Deploy" button in the top-right corner, and fill in the required domain name. Once deployed, you can access your Dify app at `https://<your-domain>.zeabur.app`.

        ## App structure

        - Redis, PostgreSQL, MINIO, and Webaviate for data storage and caching.
        - `api`, `worker`, `web`, `sandbox`, and `plugin_daemon` are the microservices of Dify.
        - `nginx` is the gateway of Dify. It integrates the microservices to a single host. In another words, **it is the entry point of your Dify app.**

        ## Configuration

        Refer to <https://docs.dify.ai/getting-started/install-self-hosted/environments> for the configurable variables, which are primarily set in the `api` service.

        ### Upload File Size Limit

        The default upload file size limit is 15 MB. You can change this limit by modifying the `client_max_body_size` directive in the configuration file located at `/etc/nginx/nginx.conf` for the `nginx` service. The value should be a string with a unit (e.g., `15M` for 15 MB).

        Additionally, you may need to set the `UPLOAD_FILE_SIZE_LIMIT` variable in the environment of the `api` service to match this value. Ensure that this value is the same as the `client_max_body_size` directive in the `/etc/nginx/nginx.conf` configuration (e.g., `15M` for 15 MB).
    services:
        - name: nginx
          icon: https://www.svgrepo.com/show/373924/nginx.svg
          template: PREBUILT
          spec:
            source:
                image: nginx:1.27
            ports:
                - id: web
                  port: 80
                  type: HTTP
            env:
                DIFY_GATEWAY_URL:
                    default: https://${ZEABUR_WEB_DOMAIN}
                    expose: true
            configs:
                - path: /etc/nginx/proxy.conf
                  template: |
                    proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_http_version 1.1; proxy_set_header Connection ""; proxy_buffering off; proxy_read_timeout 3600s; proxy_send_timeout 3600s;
                  permission: null
                  envsubst: null
                - path: /etc/nginx/nginx.conf
                  template: |
                    user  nginx; worker_processes  auto;
                    error_log  /var/log/nginx/error.log notice; pid        /var/run/nginx.pid;
                    events {
                      worker_connections  1024;
                    }
                    http {
                      include       /etc/nginx/mime.types;
                      default_type  application/octet-stream;

                      log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

                      access_log  /var/log/nginx/access.log  main;

                      sendfile        on;
                      keepalive_timeout  65;
                      client_max_body_size 15M;
                      include /etc/nginx/conf.d/*.conf;
                    }
                  permission: null
                  envsubst: null
                - path: /etc/nginx/conf.d/default.conf
                  template: "server {\n  listen 80;\n  server_name _;\n\n  location /console/api {\n    proxy_pass http://api:5001;\n    include proxy.conf;\n  }\n  \n  location /api {\n    proxy_pass http://api:5001;\n    include proxy.conf;\n  }\n  \n  location /v1 {\n    proxy_pass http://api:5001;\n    include proxy.conf;\n  }\n\n  location /files {\n    proxy_pass http://api:5001;\n    include proxy.conf;\n  }\n\n  location /e {\n    proxy_pass http://plugin-daemon:5002;\n    include proxy.conf;\n  }\n\n  location / {\n    proxy_pass http://web:3000;\n    include proxy.conf;\n  }\n\n}\n"
                  permission: null
                  envsubst: null
          domainKey: PUBLIC_DOMAIN
        - 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: db
          icon: https://raw.githubusercontent.com/zeabur/service-icons/main/marketplace/postgresql.svg
          template: PREBUILT
          spec:
            source:
                image: postgres:16
            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
        - name: minio
          icon: https://raw.githubusercontent.com/zeabur/service-icons/main/marketplace/minio.svg
          template: PREBUILT
          spec:
            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: MinIO Username
                  content: ${MINIO_USERNAME}
                - title: MinIO Password
                  content: ${MINIO_PASSWORD}
            env:
                MINIO_BROWSER_REDIRECT:
                    default: "false"
                MINIO_CONSOLE_URL:
                    default: ${ZEABUR_CONSOLE_URL}
                    expose: true
                MINIO_DEFAULT_BUCKET:
                    default: dify
                MINIO_PASSWORD:
                    default: ${MINIO_ROOT_PASSWORD}
                    expose: true
                MINIO_ROOT_PASSWORD:
                    default: ${PASSWORD}
                MINIO_ROOT_USER:
                    default: minio
                MINIO_USERNAME:
                    default: ${MINIO_ROOT_USER}
                    expose: true
        - name: api
          icon: https://cdn.zeabur.com/dify-icon.png
          template: PREBUILT
          spec:
            source:
                image: langgenius/dify-api:1.0.1
            ports:
                - id: api
                  port: 5001
                  type: HTTP
            volumes:
                - id: data
                  dir: /app/api/storage
            env:
                API_SECRET_KEY:
                    default: ${PASSWORD}
                    expose: true
                APP_WEB_URL:
                    default: ${DIFY_GATEWAY_URL}
                CELERY_BROKER_URL:
                    default: redis://:${REDIS_PASSWORD}@redis:6379/1
                CODE_EXECUTION_API_KEY:
                    default: dify-sandbox
                CODE_EXECUTION_ENDPOINT:
                    default: http://sandbox:8194
                CODE_MAX_NUMBER:
                    default: "9223372036854775807"
                CODE_MAX_NUMBER_ARRAY_LENGTH:
                    default: "1000"
                CODE_MAX_OBJECT_ARRAY_LENGTH:
                    default: "30"
                CODE_MAX_STRING_ARRAY_LENGTH:
                    default: "30"
                CODE_MAX_STRING_LENGTH:
                    default: "80000"
                CODE_MIN_NUMBER:
                    default: "-9223372036854775808"
                CONSOLE_API_URL:
                    default: ${DIFY_GATEWAY_URL}
                CONSOLE_WEB_URL:
                    default: ${DIFY_GATEWAY_URL}
                DB_DATABASE:
                    default: ${POSTGRES_DATABASE}
                DB_HOST:
                    default: ${POSTGRES_HOST}
                DB_PASSWORD:
                    default: ${POSTGRES_PASSWORD}
                DB_PORT:
                    default: ${POSTGRES_PORT}
                DB_USERNAME:
                    default: ${POSTGRES_USERNAME}
                INNER_API_KEY_FOR_PLUGIN:
                    default: QaHbTe77CtuXmsfyhR7+vRjI/+XbV1AaFy691iy+kGDv2Jvy0/eAh8Y1
                MIGRATION_ENABLED:
                    default: "true"
                MODE:
                    default: api
                PLUGIN_DAEMON_KEY:
                    default: lYkiYYT6owG+71oLerGzA7GXCgOT++6ovaezWAjpCjf+Sjc3ZtU+qUEi
                PLUGIN_DAEMON_URL:
                    default: http://plugin-daemon:5002
                PLUGIN_MAX_PACKAGE_SIZE:
                    default: "52428800"
                PLUGIN_REMOTE_INSTALL_HOST:
                    default: plugin-daemon
                PLUGIN_REMOTE_INSTALL_PORT:
                    default: "5003"
                REDIS_DB:
                    default: "0"
                REDIS_USE_SSL:
                    default: "false"
                REDIS_USERNAME:
                    default: ""
                S3_ACCESS_KEY:
                    default: ${MINIO_USERNAME}
                S3_BUCKET_NAME:
                    default: dify
                S3_ENDPOINT:
                    default: http://minio.zeabur.internal:9000
                S3_REGION:
                    default: us-east-1
                S3_SECRET_KEY:
                    default: ${MINIO_PASSWORD}
                SECRET_KEY:
                    default: ${API_SECRET_KEY}
                SERVICE_API_URL:
                    default: ${DIFY_GATEWAY_URL}
                STORAGE_TYPE:
                    default: s3
                TEMPLATE_TRANSFORM_MAX_LENGTH:
                    default: "80000"
                VECTOR_STORE:
                    default: weaviate
                WEAVIATE_API_KEY:
                    default: WVF5YThaHlkYwhGUSmCRgsX3tD5ngdN8pkih
                WEAVIATE_ENDPOINT:
                    default: http://weaviate:8080
        - name: worker
          icon: https://cdn.zeabur.com/dify-icon.png
          template: PREBUILT
          spec:
            source:
                image: langgenius/dify-api:1.0.1
            env:
                APP_WEB_URL:
                    default: ${DIFY_GATEWAY_URL}
                CELERY_BROKER_URL:
                    default: redis://:${REDIS_PASSWORD}@redis:6379/1
                CODE_EXECUTION_API_KEY:
                    default: dify-sandbox
                CODE_EXECUTION_ENDPOINT:
                    default: http://sandbox:8194
                CODE_MAX_NUMBER:
                    default: "9223372036854775807"
                CODE_MAX_NUMBER_ARRAY_LENGTH:
                    default: "1000"
                CODE_MAX_OBJECT_ARRAY_LENGTH:
                    default: "30"
                CODE_MAX_STRING_ARRAY_LENGTH:
                    default: "30"
                CODE_MAX_STRING_LENGTH:
                    default: "80000"
                CODE_MIN_NUMBER:
                    default: "-9223372036854775808"
                CONSOLE_API_URL:
                    default: ${DIFY_GATEWAY_URL}
                CONSOLE_WEB_URL:
                    default: ${DIFY_GATEWAY_URL}
                DB_DATABASE:
                    default: ${POSTGRES_DATABASE}
                DB_HOST:
                    default: ${POSTGRES_HOST}
                DB_PASSWORD:
                    default: ${POSTGRES_PASSWORD}
                DB_PORT:
                    default: ${POSTGRES_PORT}
                DB_USERNAME:
                    default: ${POSTGRES_USERNAME}
                INNER_API_KEY_FOR_PLUGIN:
                    default: QaHbTe77CtuXmsfyhR7+vRjI/+XbV1AaFy691iy+kGDv2Jvy0/eAh8Y1
                LOG_LEVEL:
                    default: INFO
                MIGRATION_ENABLED:
                    default: "true"
                MODE:
                    default: worker
                PLUGIN_DAEMON_KEY:
                    default: lYkiYYT6owG+71oLerGzA7GXCgOT++6ovaezWAjpCjf+Sjc3ZtU+qUEi
                PLUGIN_DAEMON_URL:
                    default: http://plugin-daemon:5002
                PLUGIN_MAX_PACKAGE_SIZE:
                    default: "52428800"
                PLUGIN_REMOTE_INSTALL_HOST:
                    default: plugin-daemon
                PLUGIN_REMOTE_INSTALL_PORT:
                    default: "5003"
                REDIS_DB:
                    default: "0"
                REDIS_USE_SSL:
                    default: "false"
                REDIS_USERNAME:
                    default: ""
                S3_ACCESS_KEY:
                    default: ${MINIO_USERNAME}
                S3_BUCKET_NAME:
                    default: dify
                S3_ENDPOINT:
                    default: http://minio.zeabur.internal:9000
                S3_REGION:
                    default: us-east-1
                S3_SECRET_KEY:
                    default: ${MINIO_PASSWORD}
                SECRET_KEY:
                    default: ${API_SECRET_KEY}
                STORAGE_TYPE:
                    default: s3
                TEMPLATE_TRANSFORM_MAX_LENGTH:
                    default: "80000"
                VECTOR_STORE:
                    default: weaviate
                WEAVIATE_API_KEY:
                    default: WVF5YThaHlkYwhGUSmCRgsX3tD5ngdN8pkih
                WEAVIATE_ENDPOINT:
                    default: http://weaviate:8080
        - name: web
          icon: https://cdn.zeabur.com/dify-icon.png
          template: PREBUILT
          spec:
            source:
                image: langgenius/dify-web:1.0.1
            ports:
                - id: web
                  port: 3000
                  type: HTTP
            env:
                APP_API_URL:
                    default: ${DIFY_GATEWAY_URL}
                CONSOLE_API_URL:
                    default: ${DIFY_GATEWAY_URL}
                MARKETPLACE_API_URL:
                    default: https://marketplace.dify.ai
                MARKETPLACE_URL:
                    default: https://marketplace.dify.ai
                NEXT_PUBLIC_MARKETPLACE_API_PREFIX:
                    default: https://marketplace.dify.ai/api/v1
                NEXT_PUBLIC_MARKETPLACE_URL_PREFIX:
                    default: https://marketplace.dify.ai
        - name: weaviate
          icon: https://avatars.githubusercontent.com/u/37794290
          template: PREBUILT
          spec:
            source:
                image: semitechnologies/weaviate:1.26.3
            ports:
                - id: web
                  port: 8080
                  type: HTTP
            volumes:
                - id: data
                  dir: /var/lib/weaviate
            env:
                AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED:
                    default: "false"
                AUTHENTICATION_APIKEY_ALLOWED_KEYS:
                    default: WVF5YThaHlkYwhGUSmCRgsX3tD5ngdN8pkih
                AUTHENTICATION_APIKEY_ENABLED:
                    default: "true"
                AUTHENTICATION_APIKEY_USERS:
                    default: hello@dify.ai
                AUTHORIZATION_ADMINLIST_ENABLED:
                    default: "true"
                AUTHORIZATION_ADMINLIST_USERS:
                    default: hello@dify.ai
                CLUSTER_HOSTNAME:
                    default: node1
                DEFAULT_VECTORIZER_MODULE:
                    default: none
                ENABLE_MODULES:
                    default: text2vec-cohere,text2vec-huggingface,text2vec-palm,text2vec-openai,generative-openai,generative-cohere,generative-palm,ref2vec-centroid,reranker-cohere,qna-openai
                PERSISTENCE_DATA_PATH:
                    default: /var/lib/weaviate
                QUERY_DEFAULTS_LIMIT:
                    default: "25"
        - name: sandbox
          icon: https://cdn.zeabur.com/dify-icon.png
          template: PREBUILT
          spec:
            source:
                image: langgenius/dify-sandbox:latest
            ports:
                - id: web
                  port: 8194
                  type: HTTP
            env:
                API_KEY:
                    default: dify-sandbox
                ENABLE_NETWORK:
                    default: "true"
                GIN_MODE:
                    default: release
                SANDBOX_PORT:
                    default: "8194"
                WORKER_TIMEOUT:
                    default: "15"
        - name: plugin-daemon
          icon: https://cdn.zeabur.com/dify-icon.png
          template: PREBUILT
          spec:
            source:
                image: langgenius/dify-plugin-daemon:release-1.0.1
            ports:
                - id: web
                  port: 5002
                  type: HTTP
                - id: debug
                  port: 5003
                  type: HTTP
            volumes:
                - id: data
                  dir: /app/storage/cwd
            env:
                DB_DATABASE:
                    default: dify_plugin
                DB_HOST:
                    default: ${POSTGRES_HOST}
                DB_PASSWORD:
                    default: ${POSTGRES_PASSWORD}
                DB_PORT:
                    default: ${POSTGRES_PORT}
                DB_USERNAME:
                    default: ${POSTGRES_USERNAME}
                DEBUGGING_HOST:
                    default: 0.0.0.0
                DEBUGGING_PORT:
                    default: "5003"
                DIFY_INNER_API_KEY:
                    default: QaHbTe77CtuXmsfyhR7+vRjI/+XbV1AaFy691iy+kGDv2Jvy0/eAh8Y1
                DIFY_INNER_API_URL:
                    default: http://api:5001
                ENDPOINT_URL_TEMPLATE:
                    default: ${DIFY_GATEWAY_URL}/e/{hook_id}
                FORCE_VERIFYING_SIGNATURE:
                    default: "true"
                MARKETPLACE_API_URL:
                    default: https://marketplace.dify.ai
                MARKETPLACE_ENABLED:
                    default: "true"
                MAX_EXECUTION_TIMEOUT:
                    default: "600"
                MAX_PACKAGE_SIZE:
                    default: "52428800"
                PLUGIN_REMOTE_INSTALLING_HOST:
                    default: 0.0.0.0
                PLUGIN_REMOTE_INSTALLING_PORT:
                    default: "5003"
                PLUGIN_WORKING_PATH:
                    default: /app/storage/cwd
                PORT:
                    default: "5002"
                PPROF_ENABLED:
                    default: "false"
                PYTHON_ENV_INIT_TIMEOUT:
                    default: "120"
                SERVER_KEY:
                    default: lYkiYYT6owG+71oLerGzA7GXCgOT++6ovaezWAjpCjf+Sjc3ZtU+qUEi
