feat: Add start-container.sh for container initialization, config patching, and orchestrating backend service startup.

This commit is contained in:
Bruno Charest 2026-03-13 15:28:39 -04:00
parent dd163fec87
commit 973705e8f1
2 changed files with 57 additions and 33 deletions

View File

@ -36,6 +36,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
net-tools \
iproute2 \
nano \
tini \
&& mkdir -p /etc/apt/keyrings \
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_22.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
@ -80,4 +81,6 @@ EXPOSE 7000
USER foxy
ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["./start-container.sh"]

View File

@ -1,39 +1,41 @@
#!/bin/bash
set -e
echo "🦊 Starting Foxy Dev Team API Container..."
echo "🦊 Starting Foxy Dev Team API Container (Enhanced Mode)..."
# Defaults
# Force HOME for consistent paths
export HOME="/home/foxy"
export FOXY_HOME="/home/foxy/.openclaw"
export OPENCLAW_TYPE="${OPENCLAW_TYPE:-standalone}"
# Ensure logs directory exists
# Ensure directories exist
mkdir -p "$FOXY_HOME/logs"
mkdir -p "$FOXY_HOME/workspace"
mkdir -p "$FOXY_HOME/agents"
# --- 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
# We look for both possible filenames
FILES=("$FOXY_HOME/config.json" "$FOXY_HOME/openclaw.json" "$FOXY_HOME/config.yaml" "$FOXY_HOME/openclaw.yaml")
if [ -n "$CONFIG_FILE" ]; then
echo "🔧 Patching OpenClaw config paths for container environment..."
# Replace any /home/openclaw with /home/foxy in the config file
for CONFIG_FILE in "${FILES[@]}"; do
if [ -f "$CONFIG_FILE" ]; then
echo "🔧 Patching $CONFIG_FILE..."
sed -i 's/\/home\/openclaw/\/home\/foxy/g' "$CONFIG_FILE"
echo "✅ Paths updated to /home/foxy in $CONFIG_FILE"
sed -i 's/"gatewayHost": "127.0.0.1"/"gatewayHost": "0.0.0.0"/g' "$CONFIG_FILE"
sed -i 's/gatewayHost: 127.0.0.1/gatewayHost: 0.0.0.0/g' "$CONFIG_FILE"
echo "$CONFIG_FILE patched."
fi
done
# --- GATEWAY STARTUP ---
if [ "$OPENCLAW_TYPE" = "standalone" ]; then
echo "🔧 OPENCLAW_TYPE is standalone. Starting internal Gateway..."
# Deep patch: search for any stray host paths in agents or other files
echo "🔍 Searching for stray host paths in $FOXY_HOME..."
find "$FOXY_HOME" -type f -not -path "*/logs/*" -exec sed -i 's/\/home\/openclaw/\/home\/foxy/g' {} +
echo "✅ Recursive path patching complete."
# Initialize default config if none found
if [ -z "$CONFIG_FILE" ]; then
echo "📦 Initializing default config..."
mkdir -p "$FOXY_HOME/workspace" "$FOXY_HOME/agents"
cat <<EOF > "$FOXY_HOME/config.json"
# If no config exists at all, create a default one
if [ ! -f "$FOXY_HOME/config.json" ] && [ ! -f "$FOXY_HOME/openclaw.json" ] && [ ! -f "$FOXY_HOME/config.yaml" ] && [ ! -f "$FOXY_HOME/openclaw.yaml" ]; then
echo "📦 No config found. Initializing default OpenClaw config..."
cat <<EOF > "$FOXY_HOME/openclaw.json"
{
"theme": "dark",
"logLevel": "info",
@ -45,21 +47,40 @@ if [ "$OPENCLAW_TYPE" = "standalone" ]; then
EOF
fi
echo "🚀 Starting OpenClaw Gateway..."
# 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 > "$FOXY_HOME/logs/gateway.log" 2>&1 &
# --- GATEWAY STARTUP ---
if [ "$OPENCLAW_TYPE" = "standalone" ]; then
echo "🔧 OPENCLAW_TYPE is standalone. Starting internal Gateway..."
# Try to kill any existing (though unlikely in fresh container)
pkill -f "openclaw" || true
echo "🚀 Launching OpenClaw Gateway in background..."
# We use 'nohup' and target 0.0.0.0 explicitly.
# Redirecting to a persistent log file.
nohup openclaw gateway start --host 0.0.0.0 --port 18789 > "$FOXY_HOME/logs/gateway.log" 2>&1 &
# Wait and check
echo "⏱ Waiting for Gateway to initialize..."
sleep 5
sleep 3
if pgrep -f "openclaw" > /dev/null; then
echo "✅ OpenClaw Gateway is UP."
else
echo "❌ Gateway failed to start. Checking logs..."
cat "$FOXY_HOME/logs/gateway.log"
echo "✅ OpenClaw Gateway process found (PID: $(pgrep -f "openclaw"))."
# Optional: check if port is listening
if command -v netstat >/dev/null 2>&1; then
netstat -tulpn | grep 18789 || echo "⚠️ Gateway started but port 18789 not yet listening."
fi
else
echo "🔗 OPENCLAW_TYPE is shared. Host gateway expected."
echo "❌ OpenClaw Gateway crashed or failed to start!"
echo "--- LAST LOGS ---"
tail -n 20 "$FOXY_HOME/logs/gateway.log"
echo "-----------------"
fi
else
echo "🔗 OPENCLAW_TYPE is shared. Assuming host gateway."
fi
echo "🚀 Starting Uvicorn API Server..."
# We don't use 'exec' here so that this script stays as a parent
# OR we do use exec if tini is the entrypoint (it will handle orphans).
# Using exec is better for signal propagation.
exec python -m uvicorn app.main:app --host 0.0.0.0 --port 7000