Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

chore: separate websocket service (#35981)

非法操作1e6dc6247002
diff --git a/api/.env.example b/api/.env.example
index 56ba8a6c5db..ba153e4c9cb 100644
--- a/api/.env.example
+++ b/api/.env.example
@@ -34,7 +34,7 @@ TRIGGER_URL=http://localhost:5001
FILES_ACCESS_TIMEOUT=300
# Collaboration mode toggle
-ENABLE_COLLABORATION_MODE=false
+ENABLE_COLLABORATION_MODE=true
# Access token expiration time in minutes
ACCESS_TOKEN_EXPIRE_MINUTES=60
diff --git a/api/configs/feature/__init__.py b/api/configs/feature/__init__.py
index 52e33c1789e..e9bb34fa759 100644
--- a/api/configs/feature/__init__.py
+++ b/api/configs/feature/__init__.py
@@ -1298,7 +1298,7 @@ class PositionConfig(BaseSettings):
class CollaborationConfig(BaseSettings):
ENABLE_COLLABORATION_MODE: bool = Field(
description="Whether to enable collaboration mode features across the workspace",
- default=False,
+ default=True,
)
diff --git a/api/services/feature_service.py b/api/services/feature_service.py
index 9477c28bf3c..257c4bea9ad 100644
--- a/api/services/feature_service.py
+++ b/api/services/feature_service.py
@@ -166,7 +166,7 @@ class SystemFeatureModel(BaseModel):
enable_email_code_login: bool = False
enable_email_password_login: bool = True
enable_social_oauth_login: bool = False
- enable_collaboration_mode: bool = False
+ enable_collaboration_mode: bool = True
is_allow_register: bool = False
is_allow_create_workspace: bool = False
is_email_setup: bool = False
diff --git a/docker/.env.example b/docker/.env.example
index 82bd837ffb1..d9891d842a6 100644
--- a/docker/.env.example
+++ b/docker/.env.example
@@ -34,7 +34,8 @@ CHECK_UPDATE_URL=https://updates.dify.ai
OPENAI_API_BASE=https://api.openai.com/v1
MIGRATION_ENABLED=true
FILES_ACCESS_TIMEOUT=300
-ENABLE_COLLABORATION_MODE=false
+# Remove `collaboration` from COMPOSE_PROFILES to stop the dedicated websocket service.
+ENABLE_COLLABORATION_MODE=true
# Logging and server workers
LOG_LEVEL=INFO
@@ -52,6 +53,9 @@ DIFY_PORT=5001
SERVER_WORKER_AMOUNT=1
SERVER_WORKER_CLASS=gevent
SERVER_WORKER_CONNECTIONS=10
+API_WEBSOCKET_WORKER_CLASS=geventwebsocket.gunicorn.workers.GeventWebSocketWorker
+API_WEBSOCKET_WORKER_CONNECTIONS=1000
+API_WEBSOCKET_GUNICORN_TIMEOUT=360
GUNICORN_TIMEOUT=360
CELERY_WORKER_CLASS=
CELERY_WORKER_AMOUNT=4
@@ -246,6 +250,7 @@ NGINX_KEEPALIVE_TIMEOUT=65
NGINX_PROXY_READ_TIMEOUT=3600s
NGINX_PROXY_SEND_TIMEOUT=3600s
NGINX_ENABLE_CERTBOT_CHALLENGE=false
+NGINX_SOCKET_IO_UPSTREAM=api_websocket:5001
EXPOSE_NGINX_PORT=80
EXPOSE_NGINX_SSL_PORT=443
-COMPOSE_PROFILES=${VECTOR_STORE:-weaviate},${DB_TYPE:-postgresql}
+COMPOSE_PROFILES=${VECTOR_STORE:-weaviate},${DB_TYPE:-postgresql},collaboration
diff --git a/docker/docker-compose-template.yaml b/docker/docker-compose-template.yaml
index 0f65c38098c..72c9d4fd906 100644
--- a/docker/docker-compose-template.yaml
+++ b/docker/docker-compose-template.yaml
@@ -261,6 +261,31 @@ services:
- ssrf_proxy_network
- default
+ # WebSocket service for workflow collaboration.
+ api_websocket:
+ <<: *shared-api-worker-config
+ image: langgenius/dify-api:1.14.0
+ profiles:
+ - collaboration
+ environment:
+ MODE: api
+ SERVER_WORKER_AMOUNT: 1
+ SERVER_WORKER_CLASS: ${API_WEBSOCKET_WORKER_CLASS:-geventwebsocket.gunicorn.workers.GeventWebSocketWorker}
+ SERVER_WORKER_CONNECTIONS: ${API_WEBSOCKET_WORKER_CONNECTIONS:-1000}
+ GUNICORN_TIMEOUT: ${API_WEBSOCKET_GUNICORN_TIMEOUT:-360}
+ depends_on:
+ db_postgres:
+ condition: service_healthy
+ required: false
+ db_mysql:
+ condition: service_healthy
+ required: false
+ redis:
+ condition: service_started
+ networks:
+ - ssrf_proxy_network
+ - default
+
# worker service
# The Celery worker for processing all queues (dataset, workflow, mail, etc.)
worker:
@@ -661,6 +686,7 @@ services:
NGINX_PROXY_READ_TIMEOUT: ${NGINX_PROXY_READ_TIMEOUT:-3600s}
NGINX_PROXY_SEND_TIMEOUT: ${NGINX_PROXY_SEND_TIMEOUT:-3600s}
NGINX_ENABLE_CERTBOT_CHALLENGE: ${NGINX_ENABLE_CERTBOT_CHALLENGE:-false}
+ NGINX_SOCKET_IO_UPSTREAM: ${NGINX_SOCKET_IO_UPSTREAM:-api_websocket:5001}
CERTBOT_DOMAIN: ${CERTBOT_DOMAIN:-}
depends_on:
- api
diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml
index 0f8458a58f1..c1d75e01f4a 100644
--- a/docker/docker-compose.yaml
+++ b/docker/docker-compose.yaml
@@ -267,6 +267,31 @@ services:
- ssrf_proxy_network
- default
+ # WebSocket service for workflow collaboration.
+ api_websocket:
+ <<: *shared-api-worker-config
+ image: langgenius/dify-api:1.14.0
+ profiles:
+ - collaboration
+ environment:
+ MODE: api
+ SERVER_WORKER_AMOUNT: 1
+ SERVER_WORKER_CLASS: ${API_WEBSOCKET_WORKER_CLASS:-geventwebsocket.gunicorn.workers.GeventWebSocketWorker}
+ SERVER_WORKER_CONNECTIONS: ${API_WEBSOCKET_WORKER_CONNECTIONS:-1000}
+ GUNICORN_TIMEOUT: ${API_WEBSOCKET_GUNICORN_TIMEOUT:-360}
+ depends_on:
+ db_postgres:
+ condition: service_healthy
+ required: false
+ db_mysql:
+ condition: service_healthy
+ required: false
+ redis:
+ condition: service_started
+ networks:
+ - ssrf_proxy_network
+ - default
+
# worker service
# The Celery worker for processing all queues (dataset, workflow, mail, etc.)
worker:
@@ -667,6 +692,7 @@ services:
NGINX_PROXY_READ_TIMEOUT: ${NGINX_PROXY_READ_TIMEOUT:-3600s}
NGINX_PROXY_SEND_TIMEOUT: ${NGINX_PROXY_SEND_TIMEOUT:-3600s}
NGINX_ENABLE_CERTBOT_CHALLENGE: ${NGINX_ENABLE_CERTBOT_CHALLENGE:-false}
+ NGINX_SOCKET_IO_UPSTREAM: ${NGINX_SOCKET_IO_UPSTREAM:-api_websocket:5001}
CERTBOT_DOMAIN: ${CERTBOT_DOMAIN:-}
depends_on:
- api
diff --git a/docker/envs/core-services/shared.env.example b/docker/envs/core-services/shared.env.example
index 2a57f6954a2..af1c3ce74e2 100644
--- a/docker/envs/core-services/shared.env.example
+++ b/docker/envs/core-services/shared.env.example
@@ -16,7 +16,8 @@ CHECK_UPDATE_URL=https://updates.dify.ai
OPENAI_API_BASE=https://api.openai.com/v1
MIGRATION_ENABLED=true
FILES_ACCESS_TIMEOUT=300
-ENABLE_COLLABORATION_MODE=false
+# Remove `collaboration` from COMPOSE_PROFILES to stop the dedicated websocket service.
+ENABLE_COLLABORATION_MODE=true
CELERY_BROKER_URL=redis://:difyai123456@redis:6379/1
CELERY_TASK_ANNOTATIONS=null
AZURE_BLOB_ACCOUNT_URL=https://<your_account_name>.blob.core.windows.net
@@ -87,6 +88,9 @@ DIFY_PORT=5001
SERVER_WORKER_AMOUNT=1
SERVER_WORKER_CLASS=gevent
SERVER_WORKER_CONNECTIONS=10
+API_WEBSOCKET_WORKER_CLASS=geventwebsocket.gunicorn.workers.GeventWebSocketWorker
+API_WEBSOCKET_WORKER_CONNECTIONS=1000
+API_WEBSOCKET_GUNICORN_TIMEOUT=360
CELERY_SENTINEL_PASSWORD=
S3_ACCESS_KEY=
S3_SECRET_KEY=
@@ -399,7 +403,7 @@ TABLESTORE_ENDPOINT=https://instance-name.cn-hangzhou.ots.aliyuncs.com
TABLESTORE_INSTANCE_NAME=instance-name
CLICKZETTA_USERNAME=
CLICKZETTA_VECTOR_DISTANCE_FUNCTION=cosine_distance
-COMPOSE_PROFILES=${VECTOR_STORE:-weaviate},${DB_TYPE:-postgresql}
+COMPOSE_PROFILES=${VECTOR_STORE:-weaviate},${DB_TYPE:-postgresql},collaboration
EXPOSE_NGINX_PORT=80
EXPOSE_NGINX_SSL_PORT=443
POSITION_TOOL_PINS=
diff --git a/docker/envs/infrastructure/nginx.env.example b/docker/envs/infrastructure/nginx.env.example
index fbe86680ba0..fcb369a47dd 100644
--- a/docker/envs/infrastructure/nginx.env.example
+++ b/docker/envs/infrastructure/nginx.env.example
@@ -15,3 +15,4 @@ NGINX_KEEPALIVE_TIMEOUT=65
NGINX_PROXY_READ_TIMEOUT=3600s
NGINX_PROXY_SEND_TIMEOUT=3600s
NGINX_ENABLE_CERTBOT_CHALLENGE=false
+NGINX_SOCKET_IO_UPSTREAM=api_websocket:5001
diff --git a/docker/nginx/conf.d/default.conf.template b/docker/nginx/conf.d/default.conf.template
index 94a748290f8..64c720ca2b5 100644
--- a/docker/nginx/conf.d/default.conf.template
+++ b/docker/nginx/conf.d/default.conf.template
@@ -15,7 +15,9 @@ server {
}
location /socket.io/ {
- proxy_pass http://api:5001;
+ resolver 127.0.0.11 valid=30s ipv6=off;
+ set $socket_io_upstream ${NGINX_SOCKET_IO_UPSTREAM};
+ proxy_pass http://$socket_io_upstream;
include proxy.conf;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";