-
Notifications
You must be signed in to change notification settings - Fork 11.2k
fix(docker): don't abort Docker startup when .env is missing #4956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
516a58b
5b4cbc7
0bedc01
abf0c6b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,17 @@ | ||
| # DeerFlow Development Environment | ||
| # Usage: docker-compose -f docker-compose-dev.yaml up --build | ||
| # | ||
| # Supported entry: from the repository root, run `make docker-start`. | ||
| # That wrapper creates missing .env files and invokes Compose from this | ||
| # directory with a relative filename. | ||
| # | ||
| # Direct Compose must also be run from the repository root: | ||
| # docker compose -f docker/docker-compose-dev.yaml up --build | ||
| # Do not reuse that -f path from inside docker/ — it resolves to | ||
| # docker/docker/docker-compose-dev.yaml and fails with file-not-found. | ||
| # | ||
| # env_file targets are optional so a missing ../.env or ../frontend/.env | ||
| # does not abort Compose on Windows ("file not found" / | ||
| # "Le fichier spécifique est introuvable"). | ||
| # | ||
| # Services: | ||
| # - nginx: Reverse proxy (port 2026) | ||
|
|
@@ -74,7 +86,8 @@ services: | |
| # The same value must be set on the gateway side via config.yaml sandbox.provisioner_api_key. | ||
| - PROVISIONER_API_KEY=${PROVISIONER_API_KEY:-} | ||
| env_file: | ||
| - ../.env | ||
| - path: ../.env | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P1] Please declare or avoid the new Compose 2.24 minimum. The long-form env_file required field is not understood by older Compose v2 clients, so configurations that previously ran make docker-start now fail while parsing this file, before the wrapper-created env files can help. The prerequisites currently list Docker Desktop or Engine without a Compose version floor, and the wrapper has no version check. Either preserve the previous syntax/support or document Compose >= 2.24 and fail early with an actionable version check, including for direct callers. |
||
| required: false | ||
| extra_hosts: | ||
| - "host.docker.internal:host-gateway" | ||
| networks: | ||
|
|
@@ -139,7 +152,8 @@ services: | |
| - CI=true | ||
| - DEER_FLOW_INTERNAL_GATEWAY_BASE_URL=http://gateway:8001 | ||
| env_file: | ||
| - ../frontend/.env | ||
| - path: ../frontend/.env | ||
| required: false | ||
| networks: | ||
| - deer-flow-dev | ||
| restart: unless-stopped | ||
|
|
@@ -212,7 +226,8 @@ services: | |
| - NO_PROXY=${NO_PROXY:-}${NO_PROXY:+,}localhost,127.0.0.1,::1,gateway,frontend,nginx,provisioner,openviking,host.docker.internal | ||
| - no_proxy=${no_proxy:-}${no_proxy:+,}localhost,127.0.0.1,::1,gateway,frontend,nginx,provisioner,openviking,host.docker.internal | ||
| env_file: | ||
| - ../.env | ||
| - path: ../.env | ||
| required: false | ||
| extra_hosts: | ||
| # For Linux: map host.docker.internal to host gateway | ||
| - "host.docker.internal:host-gateway" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,8 +12,46 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
| PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" | ||
| DOCKER_DIR="$PROJECT_ROOT/docker" | ||
|
|
||
| # Docker Compose command with project name | ||
| COMPOSE_CMD="docker compose -p deer-flow-dev -f docker-compose-dev.yaml" | ||
| # Docker Compose command with project name. | ||
| # Use a filename relative to DOCKER_DIR (we always `cd` there) so Windows | ||
| # Docker Desktop does not receive a Git Bash `/c/...` path it cannot open. | ||
| # See https://github.com/bytedance/deer-flow/issues/2416 | ||
| COMPOSE_FILE="docker-compose-dev.yaml" | ||
| COMPOSE_CMD="docker compose -p deer-flow-dev -f $COMPOSE_FILE" | ||
|
|
||
| ensure_from_example() { | ||
| local dest="$1" | ||
| local src="$2" | ||
| local label="$3" | ||
|
|
||
| if [ -f "$dest" ]; then | ||
| return 0 | ||
| fi | ||
| if [ -f "$src" ]; then | ||
| cp "$src" "$dest" | ||
| echo -e "${BLUE}Created ${label} from $(basename "$src")${NC}" | ||
| return 0 | ||
| fi | ||
| echo -e "${YELLOW}✗ ${label} not found and no $(basename "$src") to copy from.${NC}" | ||
| echo "Create ${dest} before starting Docker." | ||
| exit 1 | ||
| } | ||
|
|
||
| # Compose env_file entries fail closed on Windows when .env is missing | ||
| # ("The specified file cannot be found" / "Le fichier spécifique est introuvable"). | ||
| prepare_compose_env() { | ||
| if [ ! -f "$DOCKER_DIR/$COMPOSE_FILE" ]; then | ||
| echo -e "${YELLOW}✗ ${COMPOSE_FILE} not found at ${DOCKER_DIR}/${COMPOSE_FILE}${NC}" | ||
| echo "Run this from the DeerFlow repository root, e.g. 'make docker-start'." | ||
| echo "Do not run 'docker compose -f docker/${COMPOSE_FILE}' from inside docker/ — that resolves to docker/docker/${COMPOSE_FILE}." | ||
| exit 1 | ||
| fi | ||
| if [ -z "$DEER_FLOW_ROOT" ]; then | ||
| export DEER_FLOW_ROOT="$PROJECT_ROOT" | ||
| fi | ||
| ensure_from_example "$PROJECT_ROOT/.env" "$PROJECT_ROOT/.env.example" ".env" | ||
| ensure_from_example "$PROJECT_ROOT/frontend/.env" "$PROJECT_ROOT/frontend/.env.example" "frontend/.env" | ||
| } | ||
|
|
||
| load_proxy_env_from_dotenv() { | ||
| local env_file="$PROJECT_ROOT/.env" | ||
|
|
@@ -207,7 +245,7 @@ start() { | |
| exit 1 | ||
| fi | ||
| echo -e "${YELLOW}Mounting host Docker socket into gateway (DooD = host root-equivalent). See SECURITY.md.${NC}" | ||
| COMPOSE_CMD="$COMPOSE_CMD -f $DOCKER_DIR/docker-compose.dood.yaml" | ||
| COMPOSE_CMD="$COMPOSE_CMD -f docker-compose.dood.yaml" | ||
| fi | ||
|
|
||
| echo -e "${BLUE}Runtime: Gateway embedded agent runtime${NC}" | ||
|
|
@@ -260,6 +298,7 @@ start() { | |
| fi | ||
| fi | ||
|
|
||
| prepare_compose_env | ||
| load_proxy_env_from_dotenv | ||
|
|
||
| echo "Building and starting containers..." | ||
|
|
@@ -283,12 +322,8 @@ start() { | |
| logs() { | ||
| local service="" | ||
|
|
||
| # DEER_FLOW_ROOT is referenced in docker-compose-dev.yaml; set it before | ||
| # reading logs so Compose does not resolve mounted paths from an empty root. | ||
| if [ -z "$DEER_FLOW_ROOT" ]; then | ||
| export DEER_FLOW_ROOT="$PROJECT_ROOT" | ||
| fi | ||
|
|
||
| prepare_compose_env | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2] Please keep logs, stop, and restart read-only with respect to configuration. prepare_compose_env calls ensure_from_example for both env files, so these commands now mutate a fresh checkout and can even refuse to stop running containers if an example file is unavailable. Since the Compose entries are optional after this change, split the shared preflight into compose-file validation plus DEER_FLOW_ROOT setup, and run env-file creation only from start. |
||
|
|
||
| case "$1" in | ||
| --frontend) | ||
| service="frontend" | ||
|
|
@@ -325,11 +360,7 @@ logs() { | |
|
|
||
| # Stop Docker development environment | ||
| stop() { | ||
| # DEER_FLOW_ROOT is referenced in docker-compose-dev.yaml; set it before | ||
| # running compose down to suppress "variable is not set" warnings. | ||
| if [ -z "$DEER_FLOW_ROOT" ]; then | ||
| export DEER_FLOW_ROOT="$PROJECT_ROOT" | ||
| fi | ||
| prepare_compose_env | ||
| echo "Stopping Docker development services..." | ||
| cd "$DOCKER_DIR" && $COMPOSE_CMD down | ||
| echo "Cleaning up sandbox containers..." | ||
|
|
@@ -339,11 +370,7 @@ stop() { | |
|
|
||
| # Restart Docker development environment | ||
| restart() { | ||
| # DEER_FLOW_ROOT is referenced in docker-compose-dev.yaml; set it before | ||
| # restarting services so Compose resolves mounted paths from this checkout. | ||
| if [ -z "$DEER_FLOW_ROOT" ]; then | ||
| export DEER_FLOW_ROOT="$PROJECT_ROOT" | ||
| fi | ||
| prepare_compose_env | ||
| echo "========================================" | ||
| echo " Restarting DeerFlow Docker Services" | ||
| echo "========================================" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] This direct command also needs to set DEER_FLOW_ROOT to the absolute checkout path. Running the documented command with it unset emits warnings and renders DEER_FLOW_HOST_BASE_DIR as /backend/.deer-flow and THREADS_HOST_PATH as /backend/.deer-flow/threads. Those are host-side paths in AIO/provisioner mode, so the command gets past the missing env file but remains misconfigured. Please document the platform-appropriate setting or make Compose derive it reliably.