mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-03 06:12:14 +08:00
chore(docker): Refactor sandbox state management and improve Docker integration (#1068)
* Refactor sandbox state management and improve Docker integration - Removed FileSandboxStateStore and SandboxStateStore classes for a cleaner architecture. - Enhanced LocalContainerBackend to handle port allocation retries and introduced environment variable support for sandbox host configuration. - Updated Paths class to include host_base_dir for Docker volume mounts and ensured proper permissions for sandbox directories. - Modified ExtensionsConfig to improve error handling when loading configuration files and adjusted environment variable resolution. - Updated sandbox configuration to include a replicas option for managing concurrent sandbox containers. - Improved logging and context management in SandboxMiddleware for better sandbox lifecycle handling. - Enhanced network port allocation logic to bind to 0.0.0.0 for compatibility with Docker. - Updated Docker Compose files to ensure proper volume management and environment variable configuration. - Created scripts to ensure necessary configuration files are present before starting services. - Cleaned up unused MCP server configurations in extensions_config.example.json. * Address Copilot review suggestions from PR #1068 (#9) --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -125,6 +125,39 @@ start() {
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Ensure config.yaml exists before starting.
|
||||
if [ ! -f "$PROJECT_ROOT/config.yaml" ]; then
|
||||
if [ -f "$PROJECT_ROOT/config.example.yaml" ]; then
|
||||
cp "$PROJECT_ROOT/config.example.yaml" "$PROJECT_ROOT/config.yaml"
|
||||
echo ""
|
||||
echo -e "${YELLOW}============================================================${NC}"
|
||||
echo -e "${YELLOW} config.yaml has been created from config.example.yaml.${NC}"
|
||||
echo -e "${YELLOW} Please edit config.yaml to set your API keys and model ${NC}"
|
||||
echo -e "${YELLOW} configuration before starting DeerFlow. ${NC}"
|
||||
echo -e "${YELLOW}============================================================${NC}"
|
||||
echo ""
|
||||
echo -e "${YELLOW} Edit the file: $PROJECT_ROOT/config.yaml${NC}"
|
||||
echo -e "${YELLOW} Then run: make docker-start${NC}"
|
||||
echo ""
|
||||
exit 0
|
||||
else
|
||||
echo -e "${YELLOW}✗ config.yaml not found and no config.example.yaml to copy from.${NC}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Ensure extensions_config.json exists as a file before mounting.
|
||||
# Docker creates a directory when bind-mounting a non-existent host path.
|
||||
if [ ! -f "$PROJECT_ROOT/extensions_config.json" ]; then
|
||||
if [ -f "$PROJECT_ROOT/extensions_config.example.json" ]; then
|
||||
cp "$PROJECT_ROOT/extensions_config.example.json" "$PROJECT_ROOT/extensions_config.json"
|
||||
echo -e "${BLUE}Created extensions_config.json from example${NC}"
|
||||
else
|
||||
echo "{}" > "$PROJECT_ROOT/extensions_config.json"
|
||||
echo -e "${BLUE}Created empty extensions_config.json${NC}"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Building and starting containers..."
|
||||
cd "$DOCKER_DIR" && $COMPOSE_CMD up --build -d --remove-orphans $services
|
||||
echo ""
|
||||
@@ -177,8 +210,15 @@ 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
|
||||
echo "Stopping Docker development services..."
|
||||
cd "$DOCKER_DIR" && $COMPOSE_CMD down
|
||||
echo "Cleaning up sandbox containers..."
|
||||
"$SCRIPT_DIR/cleanup-containers.sh" deer-flow-sandbox 2>/dev/null || true
|
||||
echo -e "${GREEN}✓ Docker services stopped${NC}"
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ pkill -f "next dev" 2>/dev/null || true
|
||||
nginx -c "$REPO_ROOT/docker/nginx/nginx.local.conf" -p "$REPO_ROOT" -s quit 2>/dev/null || true
|
||||
sleep 1
|
||||
pkill -9 nginx 2>/dev/null || true
|
||||
killall -9 nginx 2>/dev/null || true
|
||||
./scripts/cleanup-containers.sh deer-flow-sandbox 2>/dev/null || true
|
||||
sleep 1
|
||||
|
||||
@@ -60,9 +61,15 @@ cleanup() {
|
||||
pkill -f "langgraph dev" 2>/dev/null || true
|
||||
pkill -f "uvicorn src.gateway.app:app" 2>/dev/null || true
|
||||
pkill -f "next dev" 2>/dev/null || true
|
||||
nginx -c "$REPO_ROOT/docker/nginx/nginx.local.conf" -p "$REPO_ROOT" -s quit 2>/dev/null || true
|
||||
sleep 1
|
||||
# Kill nginx using the captured PID first (most reliable),
|
||||
# then fall back to pkill/killall for any stray nginx workers.
|
||||
if [ -n "${NGINX_PID:-}" ] && kill -0 "$NGINX_PID" 2>/dev/null; then
|
||||
kill -TERM "$NGINX_PID" 2>/dev/null || true
|
||||
sleep 1
|
||||
kill -9 "$NGINX_PID" 2>/dev/null || true
|
||||
fi
|
||||
pkill -9 nginx 2>/dev/null || true
|
||||
killall -9 nginx 2>/dev/null || true
|
||||
echo "Cleaning up sandbox containers..."
|
||||
./scripts/cleanup-containers.sh deer-flow-sandbox 2>/dev/null || true
|
||||
echo "✓ All services stopped"
|
||||
@@ -106,6 +113,7 @@ echo "✓ Frontend started on localhost:3000"
|
||||
|
||||
echo "Starting Nginx reverse proxy..."
|
||||
nginx -g 'daemon off;' -c "$REPO_ROOT/docker/nginx/nginx.local.conf" -p "$REPO_ROOT" > logs/nginx.log 2>&1 &
|
||||
NGINX_PID=$!
|
||||
./scripts/wait-for-port.sh 2026 10 "Nginx" || {
|
||||
echo " See logs/nginx.log for details"
|
||||
tail -10 logs/nginx.log
|
||||
|
||||
Reference in New Issue
Block a user