feat: Containerize backend startup logic using a new start-container.sh script integrated into the Dockerfile.

This commit is contained in:
Bruno Charest 2026-03-13 14:21:10 -04:00
parent 8056219f39
commit 3176b81181
2 changed files with 36 additions and 34 deletions

View File

@ -69,7 +69,8 @@ RUN chmod +x ./start-container.sh
# Runtime config # Runtime config
ENV PYTHONUNBUFFERED=1 \ ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \ PYTHONDONTWRITEBYTECODE=1 \
LOG_LEVEL=info LOG_LEVEL=info \
HOME=/home/foxy
EXPOSE 7000 EXPOSE 7000

View File

@ -3,23 +3,36 @@ set -e
echo "🦊 Starting Foxy Dev Team API Container..." echo "🦊 Starting Foxy Dev Team API Container..."
# Defaults if not provided # Defaults
export FOXY_HOME="${FOXY_HOME:-/home/foxy/.openclaw}" export HOME="/home/foxy"
export OPENCLAW_TYPE="${OPENCLAW_TYPE:-shared}" export FOXY_HOME="/home/foxy/.openclaw"
export OPENCLAW_TYPE="${OPENCLAW_TYPE:-standalone}"
# Ensure logs directory exists # Ensure logs directory exists
mkdir -p "$FOXY_HOME/logs" 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 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 # Initialize default config if none found
if [ ! -f "$FOXY_HOME/config.json" ] && [ ! -f "$FOXY_HOME/config.yaml" ]; then if [ -z "$CONFIG_FILE" ]; then
echo "📦 Initializing default OpenClaw config at $FOXY_HOME..." echo "📦 Initializing default config..."
mkdir -p "$FOXY_HOME/workspace" mkdir -p "$FOXY_HOME/workspace" "$FOXY_HOME/agents"
mkdir -p "$FOXY_HOME/agents"
# Write a simple default config for Docker environment
cat <<EOF > "$FOXY_HOME/config.json" cat <<EOF > "$FOXY_HOME/config.json"
{ {
"theme": "dark", "theme": "dark",
@ -30,34 +43,22 @@ if [ "$OPENCLAW_TYPE" = "standalone" ]; then
"agentsDir": "$FOXY_HOME/agents" "agentsDir": "$FOXY_HOME/agents"
} }
EOF 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 fi
echo "🚀 Starting OpenClaw Gateway..." echo "🚀 Starting OpenClaw Gateway..."
# Launching the gateway. If 'start' backgrounds itself we might need 'run' or similar. # We use 'gateway start' but ensure it binds to all interfaces
# We use 'nohup' but we'll check it's alive. # We also use --daemon=false if possible, or standard nohup
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 & nohup openclaw gateway start --host 0.0.0.0 > "$FOXY_HOME/logs/gateway.log" 2>&1 &
# Give it a second to start sleep 3
sleep 2
if pgrep -f "openclaw" > /dev/null; then if pgrep -f "openclaw" > /dev/null; then
echo "✅ OpenClaw Gateway started successfully." echo "✅ OpenClaw Gateway is UP."
else else
echo "⚠️ Gateway didn't start with 'start' command, trying direct execution..." echo "❌ Gateway failed to start. Checking logs..."
# Fallback for some installations cat "$FOXY_HOME/logs/gateway.log"
nohup openclaw gateway > "$FOXY_HOME/logs/gateway.log" 2>&1 &
fi fi
else else
echo "❌ 'openclaw' command not found!" echo "🔗 OPENCLAW_TYPE is shared. Host gateway expected."
fi
else
echo "🔗 OPENCLAW_TYPE is shared. Assuming OpenClaw Gateway is managed by the host."
fi fi
echo "🚀 Starting Uvicorn API Server..." echo "🚀 Starting Uvicorn API Server..."