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.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
chore: Update dev setup scripts and API README (#31415)
盐粒 Yanli67657c2f48e5
diff --git a/api/README.md b/api/README.mdindex 794b05d3af9..9d89b490b0d 100644--- a/api/README.md+++ b/api/README.md@@ -1,6 +1,6 @@# Dify Backend API-## Usage+## Setup and Run> [!IMPORTANT]>@@ -8,48 +8,77 @@> [`uv`](https://docs.astral.sh/uv/) as the package manager> for Dify API backend service.-1. Start the docker-compose stack+`uv` and `pnpm` are required to run the setup and development commands below.- The backend require some middleware, including PostgreSQL, Redis, and Weaviate, which can be started together using `docker-compose`.+### Using scripts (recommended)++The scripts resolve paths relative to their location, so you can run them from anywhere.++1. Run setup (copies env files and installs dependencies).```bash- cd ../docker- cp middleware.env.example middleware.env- # change the profile to mysql if you are not using postgres,change the profile to other vector database if you are not using weaviate- docker compose -f docker-compose.middleware.yaml --profile postgresql --profile weaviate -p dify up -d- cd ../api+ ./dev/setup```-1. Copy `.env.example` to `.env`+1. Review `api/.env`, `web/.env.local`, and `docker/middleware.env` values (see the `SECRET_KEY` note below).++1. Start middleware (PostgreSQL/Redis/Weaviate).- ```cli- cp .env.example .env+ ```bash+ ./dev/start-docker-compose```-> [!IMPORTANT]->-> When the frontend and backend run on different subdomains, set COOKIE_DOMAIN to the site’s top-level domain (e.g., `example.com`). The frontend and backend must be under the same top-level domain in order to share authentication cookies.+1. Start backend (runs migrations first).++ ```bash+ ./dev/start-api+ ```++1. Start Dify [web](../web) service.-1. Generate a `SECRET_KEY` in the `.env` file.+ ```bash+ ./dev/start-web+ ```++1. Set up your application by visiting `http://localhost:3000`.++1. Optional: start the worker service (async tasks, runs from `api`).++ ```bash+ ./dev/start-worker+ ```- bash for Linux+1. Optional: start Celery Beat (scheduled tasks).- ```bash for Linux- sed -i "/^SECRET_KEY=/c\SECRET_KEY=$(openssl rand -base64 42)" .env+ ```bash+ ./dev/start-beat```- bash for Mac+### Manual commands++<details>+<summary>Show manual setup and run steps</summary>++These commands assume you start from the repository root.++1. Start the docker-compose stack.++ The backend requires middleware, including PostgreSQL, Redis, and Weaviate, which can be started together using `docker-compose`.- ```bash for Mac- secret_key=$(openssl rand -base64 42)- sed -i '' "/^SECRET_KEY=/c\\- SECRET_KEY=${secret_key}" .env+ ```bash+ cp docker/middleware.env.example docker/middleware.env+ # Use mysql or another vector database profile if you are not using postgres/weaviate.+ docker compose -f docker/docker-compose.middleware.yaml --profile postgresql --profile weaviate -p dify up -d```-1. Create environment.+1. Copy env files.++ ```bash+ cp api/.env.example api/.env+ cp web/.env.example web/.env.local+ ```- Dify API service uses [UV](https://docs.astral.sh/uv/) to manage dependencies.- First, you need to add the uv package manager, if you don't have it already.+1. Install UV if needed.```bashpip install uv@@ -57,60 +86,96 @@brew install uv```-1. Install dependencies+1. Install API dependencies.```bash- uv sync --dev+ cd api+ uv sync --group dev```-1. Run migrate+1. Install web dependencies.++ ```bash+ cd web+ pnpm install+ cd ..+ ```- Before the first launch, migrate the database to the latest version.+1. Start backend (runs migrations first, in a new terminal).```bash+ cd apiuv run flask db upgrade+ uv run flask run --host 0.0.0.0 --port=5001 --debug```-1. Start backend+1. Start Dify [web](../web) service (in a new terminal).```bash- uv run flask run --host 0.0.0.0 --port=5001 --debug+ cd web+ pnpm dev:inspect```-1. Start Dify [web](../web) service.+1. Set up your application by visiting `http://localhost:3000`.++1. Optional: start the worker service (async tasks, in a new terminal).++ ```bash+ cd api+ uv run celery -A app.celery worker -P threads -c 2 --loglevel INFO -Q dataset,priority_dataset,priority_pipeline,pipeline,mail,ops_trace,app_deletion,plugin,workflow_storage,conversation,workflow,schedule_poller,schedule_executor,triggered_workflow_dispatcher,trigger_refresh_executor,retention+ ```++1. Optional: start Celery Beat (scheduled tasks, in a new terminal).++ ```bash+ cd api+ uv run celery -A app.celery beat+ ```++</details>++### Environment notes++> [!IMPORTANT]+>+> When the frontend and backend run on different subdomains, set COOKIE_DOMAIN to the site’s top-level domain (e.g., `example.com`). The frontend and backend must be under the same top-level domain in order to share authentication cookies.-1. Setup your application by visiting `http://localhost:3000`.+- Generate a `SECRET_KEY` in the `.env` file.-1. If you need to handle and debug the async tasks (e.g. dataset importing and documents indexing), please start the worker service.+ bash for Linux-```bash-uv run celery -A app.celery worker -P threads -c 2 --loglevel INFO -Q dataset,priority_dataset,priority_pipeline,pipeline,mail,ops_trace,app_deletion,plugin,workflow_storage,conversation,workflow,schedule_poller,schedule_executor,triggered_workflow_dispatcher,trigger_refresh_executor,retention-```+ ```bash+ sed -i "/^SECRET_KEY=/c\\SECRET_KEY=$(openssl rand -base64 42)" .env+ ```-Additionally, if you want to debug the celery scheduled tasks, you can run the following command in another terminal to start the beat service:+ bash for Mac-```bash-uv run celery -A app.celery beat-```+ ```bash+ secret_key=$(openssl rand -base64 42)+ sed -i '' "/^SECRET_KEY=/c\\+ SECRET_KEY=${secret_key}" .env+ ```## Testing1. Install dependencies for both the backend and the test environment```bash- uv sync --dev+ cd api+ uv sync --group dev```1. Run the tests locally with mocked system environment variables in `tool.pytest_env` section in `pyproject.toml`, more can check [Claude.md](../CLAUDE.md)```bash+ cd apiuv run pytest # Run all testsuv run pytest tests/unit_tests/ # Unit tests onlyuv run pytest tests/integration_tests/ # Integration tests# Code quality- ../dev/reformat # Run all formatters and linters- uv run ruff check --fix ./ # Fix linting issues- uv run ruff format ./ # Format code- uv run basedpyright . # Type checking+ ./dev/reformat # Run all formatters and linters+ uv run ruff check --fix ./ # Fix linting issues+ uv run ruff format ./ # Format code+ uv run basedpyright . # Type checking```diff --git a/dev/setup b/dev/setupnew file mode 100755index 00000000000..399c8f28a58--- /dev/null+++ b/dev/setup@@ -0,0 +1,28 @@+#!/usr/bin/env bash+set -euo pipefail++SCRIPT_DIR="$(dirname "$(realpath "$0")")"+ROOT="$(dirname "$SCRIPT_DIR")"++API_ENV_EXAMPLE="$ROOT/api/.env.example"+API_ENV="$ROOT/api/.env"+WEB_ENV_EXAMPLE="$ROOT/web/.env.example"+WEB_ENV="$ROOT/web/.env.local"+MIDDLEWARE_ENV_EXAMPLE="$ROOT/docker/middleware.env.example"+MIDDLEWARE_ENV="$ROOT/docker/middleware.env"++# 1) Copy api/.env.example -> api/.env+cp "$API_ENV_EXAMPLE" "$API_ENV"++# 2) Copy web/.env.example -> web/.env.local+cp "$WEB_ENV_EXAMPLE" "$WEB_ENV"++# 3) Copy docker/middleware.env.example -> docker/middleware.env+cp "$MIDDLEWARE_ENV_EXAMPLE" "$MIDDLEWARE_ENV"++# 4) Install deps+cd "$ROOT/api"+uv sync --group dev++cd "$ROOT/web"+pnpm installdiff --git a/dev/start-api b/dev/start-apiindex 0b50ad0d0a9..bdfa58eca66 100755--- a/dev/start-api+++ b/dev/start-api@@ -3,8 +3,9 @@set -xSCRIPT_DIR="$(dirname "$(realpath "$0")")"-cd "$SCRIPT_DIR/.."+cd "$SCRIPT_DIR/../api"+uv run flask db upgrade-uv --directory api run \+uv run \flask run --host 0.0.0.0 --port=5001 --debugdiff --git a/dev/start-docker-compose b/dev/start-docker-composenew file mode 100755index 00000000000..9652be169df--- /dev/null+++ b/dev/start-docker-compose@@ -0,0 +1,8 @@+#!/usr/bin/env bash+set -euo pipefail++SCRIPT_DIR="$(dirname "$(realpath "$0")")"+ROOT="$(dirname "$SCRIPT_DIR")"++cd "$ROOT/docker"+docker compose -f docker-compose.middleware.yaml --profile postgresql --profile weaviate -p dify up -ddiff --git a/dev/start-worker b/dev/start-workerindex 78766201885..3e48065631a 100755--- a/dev/start-worker+++ b/dev/start-worker@@ -83,7 +83,7 @@ while [[ $# -gt 0 ]]; dodoneSCRIPT_DIR="$(dirname "$(realpath "$0")")"-cd "$SCRIPT_DIR/.."+cd "$SCRIPT_DIR/../api"if [[ -n "${ENV_FILE}" ]]; thenif [[ ! -f "${ENV_FILE}" ]]; then@@ -123,6 +123,6 @@ echo " Concurrency: ${CONCURRENCY}"echo " Pool: ${POOL}"echo " Log Level: ${LOGLEVEL}"-uv --directory api run \+uv run \celery -A app.celery worker \-P ${POOL} -c ${CONCURRENCY} --loglevel ${LOGLEVEL} -Q ${QUEUES}diff --git a/dev/update-uv b/dev/update-uvindex 189bd1f6b1f..35d723fe207 100755--- a/dev/update-uv+++ b/dev/update-uv@@ -4,7 +4,7 @@set -eset -o pipefail-SCRIPT_DIR="$(dirname "$0")"+SCRIPT_DIR="$(dirname "$(realpath "$0")")"REPO_ROOT="$(dirname "${SCRIPT_DIR}")"# rely on `poetry` in path