From 3176b8118137f5a65d1e04f1bf13d874e1970b0e Mon Sep 17 00:00:00 2001 From: Bruno Charest Date: Fri, 13 Mar 2026 14:21:10 -0400 Subject: [PATCH] feat: Containerize backend startup logic using a new `start-container.sh` script integrated into the Dockerfile. --- Dockerfile | 3 +- backend/start-container.sh | 67 +++++++++++++++++++------------------- 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3908cbc..c41c14c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -69,7 +69,8 @@ RUN chmod +x ./start-container.sh # Runtime config ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ - LOG_LEVEL=info + LOG_LEVEL=info \ + HOME=/home/foxy EXPOSE 7000 diff --git a/backend/start-container.sh b/backend/start-container.sh index 0795849..5cb0ac6 100644 --- a/backend/start-container.sh +++ b/backend/start-container.sh @@ -3,23 +3,36 @@ set -e echo "🦊 Starting Foxy Dev Team API Container..." -# Defaults if not provided -export FOXY_HOME="${FOXY_HOME:-/home/foxy/.openclaw}" -export OPENCLAW_TYPE="${OPENCLAW_TYPE:-shared}" +# Defaults +export HOME="/home/foxy" +export FOXY_HOME="/home/foxy/.openclaw" +export OPENCLAW_TYPE="${OPENCLAW_TYPE:-standalone}" # Ensure logs directory exists mkdir -p "$FOXY_HOME/logs" +# --- CONFIG PATCHING --- +# If we have a config file, we must ensure it doesn't point to host-specific paths +# that don't exist in the container (like /home/openclaw) +CONFIG_FILE="" +if [ -f "$FOXY_HOME/config.json" ]; then CONFIG_FILE="$FOXY_HOME/config.json"; fi +if [ -f "$FOXY_HOME/config.yaml" ]; then CONFIG_FILE="$FOXY_HOME/config.yaml"; fi + +if [ -n "$CONFIG_FILE" ]; then + echo "🔧 Patching OpenClaw config paths for container environment..." + # Replace any /home/openclaw with /home/foxy in the config file + sed -i 's/\/home\/openclaw/\/home\/foxy/g' "$CONFIG_FILE" + echo "✅ Paths updated to /home/foxy in $CONFIG_FILE" +fi + +# --- GATEWAY STARTUP --- if [ "$OPENCLAW_TYPE" = "standalone" ]; then - echo "🔧 OPENCLAW_TYPE is standalone. Setting up internal OpenClaw Gateway..." + echo "🔧 OPENCLAW_TYPE is standalone. Starting internal Gateway..." - # Initialize OpenClaw default configuration if it doesn't exist - if [ ! -f "$FOXY_HOME/config.json" ] && [ ! -f "$FOXY_HOME/config.yaml" ]; then - echo "📦 Initializing default OpenClaw config at $FOXY_HOME..." - mkdir -p "$FOXY_HOME/workspace" - mkdir -p "$FOXY_HOME/agents" - - # Write a simple default config for Docker environment + # Initialize default config if none found + if [ -z "$CONFIG_FILE" ]; then + echo "📦 Initializing default config..." + mkdir -p "$FOXY_HOME/workspace" "$FOXY_HOME/agents" cat < "$FOXY_HOME/config.json" { "theme": "dark", @@ -30,34 +43,22 @@ if [ "$OPENCLAW_TYPE" = "standalone" ]; then "agentsDir": "$FOXY_HOME/agents" } EOF - echo "✅ Default configuration created (binding to 0.0.0.0)." - else - echo "👍 OpenClaw configuration already exists at $FOXY_HOME." - # Optional: ensure gatewayHost is 0.0.0.0 even in existing config if it's internal fi echo "🚀 Starting OpenClaw Gateway..." - # Launching the gateway. If 'start' backgrounds itself we might need 'run' or similar. - # We use 'nohup' but we'll check it's alive. - if command -v openclaw >/dev/null 2>&1; then - # Some versions of openclaw use 'gateway run' or just 'gateway' for foreground - nohup openclaw gateway start --host 0.0.0.0 > "$FOXY_HOME/logs/gateway.log" 2>&1 & - - # Give it a second to start - sleep 2 - - if pgrep -f "openclaw" > /dev/null; then - echo "✅ OpenClaw Gateway started successfully." - else - echo "⚠️ Gateway didn't start with 'start' command, trying direct execution..." - # Fallback for some installations - nohup openclaw gateway > "$FOXY_HOME/logs/gateway.log" 2>&1 & - fi + # We use 'gateway start' but ensure it binds to all interfaces + # We also use --daemon=false if possible, or standard nohup + nohup openclaw gateway start --host 0.0.0.0 > "$FOXY_HOME/logs/gateway.log" 2>&1 & + + sleep 3 + if pgrep -f "openclaw" > /dev/null; then + echo "✅ OpenClaw Gateway is UP." else - echo "❌ 'openclaw' command not found!" + echo "❌ Gateway failed to start. Checking logs..." + cat "$FOXY_HOME/logs/gateway.log" fi else - echo "🔗 OPENCLAW_TYPE is shared. Assuming OpenClaw Gateway is managed by the host." + echo "🔗 OPENCLAW_TYPE is shared. Host gateway expected." fi echo "🚀 Starting Uvicorn API Server..."