Spaces:
Sleeping
Sleeping
Claude Code Claude Opus 4.6 commited on
Commit ·
2edbaaf
1
Parent(s): 5943eba
Claude Code: add explicit startup logging and error_handlers integration
Browse files- Add startup_event handler with detailed logging sequence
- Integrate error_handlers.py exception handlers
- Create entrypoint.sh with startup sequence debugging
- Optimize Dockerfile COPY layers
- Add stdout logging for container visibility
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Dockerfile +10 -5
- app.py +60 -2
- entrypoint.sh +41 -0
Dockerfile
CHANGED
|
@@ -12,12 +12,17 @@ WORKDIR /app
|
|
| 12 |
COPY requirements.txt .
|
| 13 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 14 |
|
| 15 |
-
# Copy all application files
|
| 16 |
-
COPY app.py error_handlers.py
|
| 17 |
-
COPY
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
ENV PORT=7860
|
| 21 |
EXPOSE 7860
|
| 22 |
|
| 23 |
-
|
|
|
|
|
|
| 12 |
COPY requirements.txt .
|
| 13 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 14 |
|
| 15 |
+
# Copy all application files - combined layer for faster builds
|
| 16 |
+
COPY app.py error_handlers.py entrypoint.sh openclaw.json /app/
|
| 17 |
+
COPY openclaw/ /app/openclaw/
|
| 18 |
+
COPY static/ /app/static/ 2>/dev/null || true
|
| 19 |
+
|
| 20 |
+
# Create necessary directories
|
| 21 |
+
RUN mkdir -p /app/logs && \
|
| 22 |
+
chmod +x /app/entrypoint.sh
|
| 23 |
|
| 24 |
ENV PORT=7860
|
| 25 |
EXPOSE 7860
|
| 26 |
|
| 27 |
+
# Use entrypoint for better startup logging
|
| 28 |
+
ENTRYPOINT ["/app/entrypoint.sh"]
|
app.py
CHANGED
|
@@ -3,20 +3,77 @@
|
|
| 3 |
Minimal HuggingClaw - Cain
|
| 4 |
Testing basic FastAPI container functionality.
|
| 5 |
"""
|
| 6 |
-
from fastapi import FastAPI, status as http_status
|
| 7 |
-
from fastapi.responses import JSONResponse
|
| 8 |
import os
|
| 9 |
import sys
|
| 10 |
import time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# Add /app to sys.path for proper package imports
|
| 13 |
sys.path.insert(0, "/app")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
|
|
|
| 15 |
app = FastAPI(title="HuggingClaw - Cain (Minimal Test)", version="0.0.1")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
START_TIME = time.time()
|
| 18 |
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
@app.get("/")
|
| 21 |
async def root():
|
| 22 |
"""Root endpoint - welcome message."""
|
|
@@ -92,4 +149,5 @@ async def health():
|
|
| 92 |
|
| 93 |
if __name__ == "__main__":
|
| 94 |
import uvicorn
|
|
|
|
| 95 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 3 |
Minimal HuggingClaw - Cain
|
| 4 |
Testing basic FastAPI container functionality.
|
| 5 |
"""
|
|
|
|
|
|
|
| 6 |
import os
|
| 7 |
import sys
|
| 8 |
import time
|
| 9 |
+
import logging
|
| 10 |
+
from fastapi import FastAPI, status as http_status
|
| 11 |
+
from fastapi.responses import JSONResponse
|
| 12 |
+
|
| 13 |
+
# Configure logging to stdout for container visibility
|
| 14 |
+
logging.basicConfig(
|
| 15 |
+
level=logging.INFO,
|
| 16 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
| 17 |
+
handlers=[logging.StreamHandler(sys.stdout)]
|
| 18 |
+
)
|
| 19 |
+
logger = logging.getLogger(__name__)
|
| 20 |
|
| 21 |
# Add /app to sys.path for proper package imports
|
| 22 |
sys.path.insert(0, "/app")
|
| 23 |
+
logger.info(">>> STARTUP: sys.path configured")
|
| 24 |
+
|
| 25 |
+
# Import error handlers
|
| 26 |
+
try:
|
| 27 |
+
from error_handlers import (
|
| 28 |
+
http_exception_handler,
|
| 29 |
+
generic_exception_handler
|
| 30 |
+
)
|
| 31 |
+
logger.info(">>> STARTUP: error_handlers.py imported successfully")
|
| 32 |
+
except ImportError as e:
|
| 33 |
+
logger.warning(f">>> STARTUP: error_handlers.py import failed: {e}")
|
| 34 |
+
# Define fallback handlers
|
| 35 |
+
async def http_exception_handler(request, exc):
|
| 36 |
+
return JSONResponse(status_code=exc.status_code, content={"error": exc.detail})
|
| 37 |
+
async def generic_exception_handler(request, exc):
|
| 38 |
+
return JSONResponse(status_code=500, content={"error": str(exc)})
|
| 39 |
|
| 40 |
+
# Initialize FastAPI
|
| 41 |
app = FastAPI(title="HuggingClaw - Cain (Minimal Test)", version="0.0.1")
|
| 42 |
+
logger.info(">>> STARTUP: FastAPI app created")
|
| 43 |
+
|
| 44 |
+
# Register exception handlers
|
| 45 |
+
app.add_exception_handler(Exception, generic_exception_handler)
|
| 46 |
+
logger.info(">>> STARTUP: Exception handlers registered")
|
| 47 |
|
| 48 |
START_TIME = time.time()
|
| 49 |
|
| 50 |
|
| 51 |
+
@app.on_event("startup")
|
| 52 |
+
async def startup_event():
|
| 53 |
+
"""Log startup sequence for debugging."""
|
| 54 |
+
logger.info(">>> STARTUP: startup_event triggered")
|
| 55 |
+
logger.info(f">>> STARTUP: PORT={os.environ.get('PORT', '7860')}")
|
| 56 |
+
logger.info(f">>> STARTUP: Working directory={os.getcwd()}")
|
| 57 |
+
logger.info(f">>> STARTUP: Python version={sys.version}")
|
| 58 |
+
logger.info(">>> STARTUP: Checking openclaw package...")
|
| 59 |
+
|
| 60 |
+
# Check if openclaw package is accessible
|
| 61 |
+
try:
|
| 62 |
+
import openclaw
|
| 63 |
+
logger.info(f">>> STARTUP: openclaw package found at: {openclaw.__file__}")
|
| 64 |
+
except ImportError as e:
|
| 65 |
+
logger.error(f">>> STARTUP: openclaw package NOT found: {e}")
|
| 66 |
+
|
| 67 |
+
# Check brain_minimal
|
| 68 |
+
try:
|
| 69 |
+
from openclaw.agents.brain_minimal import BrainMinimal
|
| 70 |
+
logger.info(">>> STARTUP: brain_minimal module imported successfully")
|
| 71 |
+
except ImportError as e:
|
| 72 |
+
logger.warning(f">>> STARTUP: brain_minimal import failed: {e}")
|
| 73 |
+
|
| 74 |
+
logger.info(">>> STARTUP: Initialization complete, ready to serve requests")
|
| 75 |
+
|
| 76 |
+
|
| 77 |
@app.get("/")
|
| 78 |
async def root():
|
| 79 |
"""Root endpoint - welcome message."""
|
|
|
|
| 149 |
|
| 150 |
if __name__ == "__main__":
|
| 151 |
import uvicorn
|
| 152 |
+
logger.info(">>> STARTUP: Starting uvicorn directly (not via CMD)")
|
| 153 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
entrypoint.sh
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# Entrypoint for HuggingClaw - Cain
|
| 3 |
+
# Provides explicit logging for startup sequence debugging
|
| 4 |
+
|
| 5 |
+
set -e
|
| 6 |
+
|
| 7 |
+
echo "=========================================="
|
| 8 |
+
echo "Cain Starting..."
|
| 9 |
+
echo "=========================================="
|
| 10 |
+
echo "Timestamp: $(date -u +"%Y-%m-%dT%H:%M:%SZ")"
|
| 11 |
+
echo "PORT: ${PORT:-7860}"
|
| 12 |
+
echo "Working Directory: $(pwd)"
|
| 13 |
+
echo "Python Version: $(python --version)"
|
| 14 |
+
echo "=========================================="
|
| 15 |
+
|
| 16 |
+
# Verify app.py exists
|
| 17 |
+
if [ ! -f "/app/app.py" ]; then
|
| 18 |
+
echo "ERROR: app.py not found in /app"
|
| 19 |
+
exit 1
|
| 20 |
+
fi
|
| 21 |
+
echo "✓ app.py found"
|
| 22 |
+
|
| 23 |
+
# Verify openclaw package
|
| 24 |
+
if [ -d "/app/openclaw" ]; then
|
| 25 |
+
echo "✓ openclaw directory found"
|
| 26 |
+
else
|
| 27 |
+
echo "⚠ openclaw directory not found"
|
| 28 |
+
fi
|
| 29 |
+
|
| 30 |
+
# List key files for debugging
|
| 31 |
+
echo ""
|
| 32 |
+
echo "Files in /app:"
|
| 33 |
+
ls -la /app/*.py 2>/dev/null || echo " (no .py files in /app root)"
|
| 34 |
+
|
| 35 |
+
echo ""
|
| 36 |
+
echo "=========================================="
|
| 37 |
+
echo "Starting uvicorn..."
|
| 38 |
+
echo "=========================================="
|
| 39 |
+
|
| 40 |
+
# Start uvicorn with explicit host/port
|
| 41 |
+
exec uvicorn app:app --host 0.0.0.0 --port "${PORT:-7860}"
|