feat: Containerize backend startup logic using a new start-container.sh script integrated into the Dockerfile.
This commit is contained in:
parent
8056219f39
commit
3176b81181
@ -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
|
||||
|
||||
|
||||
@ -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 <<EOF > "$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
|
||||
# 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 &
|
||||
|
||||
# Give it a second to start
|
||||
sleep 2
|
||||
|
||||
sleep 3
|
||||
if pgrep -f "openclaw" > /dev/null; then
|
||||
echo "✅ OpenClaw Gateway started successfully."
|
||||
echo "✅ OpenClaw Gateway is UP."
|
||||
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
|
||||
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..."
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user