From 423ea59491db1749316e9f6297efde8d2495de10 Mon Sep 17 00:00:00 2001 From: BillionToken Date: Wed, 18 Mar 2026 22:06:35 +0800 Subject: [PATCH] fix(scripts): handle docker-init failures gracefully for private registry (#1191) * fix(scripts): handle docker-init failures gracefully for private registry The make docker-init command was failing on Linux environments when users could not access the private Volces container registry. This commonly occurs in corporate intranet environments with proxies or for users without registry credentials. Changes: - Detect sandbox mode from config.yaml before attempting image pull - Skip image pull entirely for local sandbox mode (default) - Gracefully handle pull failures with informative messages - Update setup-sandbox Makefile target with same error handling Fixes #1168 * Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: BillionClaw Co-authored-by: Willem Jiang Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- Makefile | 10 ++++++--- scripts/docker.sh | 57 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index c9624dc..2beffd2 100644 --- a/Makefile +++ b/Makefile @@ -75,9 +75,13 @@ setup-sandbox: fi; \ if command -v docker >/dev/null 2>&1; then \ echo "Pulling image using Docker..."; \ - docker pull "$$IMAGE"; \ - echo ""; \ - echo "✓ Sandbox image pulled successfully"; \ + if docker pull "$$IMAGE"; then \ + echo ""; \ + echo "✓ Sandbox image pulled successfully"; \ + else \ + echo ""; \ + echo "⚠ Failed to pull sandbox image (this is OK for local sandbox mode)"; \ + fi; \ else \ echo "✗ Neither Docker nor Apple Container is available"; \ echo " Please install Docker: https://docs.docker.com/get-docker/"; \ diff --git a/scripts/docker.sh b/scripts/docker.sh index 79fe5f3..bc20d41 100755 --- a/scripts/docker.sh +++ b/scripts/docker.sh @@ -70,6 +70,20 @@ cleanup() { # Set up trap for Ctrl+C trap cleanup INT TERM +docker_available() { + # Check that the docker CLI exists + if ! command -v docker >/dev/null 2>&1; then + return 1 + fi + + # Check that the Docker daemon is reachable + if ! docker info >/dev/null 2>&1; then + return 1 + fi + + return 0 +} + # Initialize: pre-pull the sandbox image so first Pod startup is fast init() { echo "==========================================" @@ -79,9 +93,50 @@ init() { SANDBOX_IMAGE="enterprise-public-cn-beijing.cr.volces.com/vefaas-public/all-in-one-sandbox:latest" + # Detect sandbox mode from config.yaml + local sandbox_mode + sandbox_mode="$(detect_sandbox_mode)" + + # Skip image pull for local sandbox mode (no container image needed) + if [ "$sandbox_mode" = "local" ]; then + echo -e "${GREEN}Detected local sandbox mode — no Docker image required.${NC}" + echo "" + + if docker_available; then + echo -e "${GREEN}✓ Docker environment is ready.${NC}" + echo "" + echo -e "${YELLOW}Next step: make docker-start${NC}" + else + echo -e "${YELLOW}Docker does not appear to be installed, or the Docker daemon is not reachable.${NC}" + echo "Local sandbox mode itself does not require Docker, but Docker-based workflows (e.g., docker-start) will fail until Docker is available." + echo "" + echo -e "${YELLOW}Install and start Docker, then run: make docker-init && make docker-start${NC}" + fi + + return 0 + fi + if ! docker images --format '{{.Repository}}:{{.Tag}}' | grep -q "^${SANDBOX_IMAGE}$"; then echo -e "${BLUE}Pulling sandbox image: $SANDBOX_IMAGE ...${NC}" - docker pull "$SANDBOX_IMAGE" + echo "" + + if ! docker pull "$SANDBOX_IMAGE" 2>&1; then + echo "" + echo -e "${YELLOW}⚠ Failed to pull sandbox image.${NC}" + echo "" + echo "This is expected if:" + echo " 1. You are using local sandbox mode (default — no image needed)" + echo " 2. You are behind a corporate proxy or firewall" + echo " 3. The registry requires authentication" + echo "" + echo -e "${GREEN}The Docker development environment can still be started.${NC}" + echo "If you need AIO sandbox (container-based execution):" + echo " - Ensure you have network access to the registry" + echo " - Or configure a custom sandbox image in config.yaml" + echo "" + echo -e "${YELLOW}Next step: make docker-start${NC}" + return 0 + fi else echo -e "${GREEN}Sandbox image already exists locally: $SANDBOX_IMAGE${NC}" fi