File size: 3,511 Bytes
0d57ef7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
# Clawdbot Development Assistant Entrypoint
#
# CHANGELOG [2025-01-29 - Josh]
# Created for HuggingFace Spaces deployment
# Handles runtime setup before starting the Gradio application
#
# CHANGELOG [2025-01-31 - Claude]
# Added cache directory fallback for ChromaDB embedding model downloads.
# PROBLEM: ChromaDB tries to download ONNX MiniLM to /.cache on first use.
# Running as USER 1000 means /.cache (owned by root) is not writable.
# Dockerfile sets ENV vars to redirect to /data/.cache, but if /data
# isn't available (persistent storage not enabled), we need a fallback.
# FIX: Test /data writability at runtime. If not writable, redirect
# cache env vars to /tmp/.cache (ephemeral but at least writable).
# Also added startup timestamp and diagnostic logging.

echo ""
echo "===== Application Startup at $(date -u '+%Y-%m-%d %H:%M:%S') ====="
echo ""
echo "🦞 Clawdbot Entrypoint Starting..."

# =========================================================================
# CACHE DIRECTORY SETUP
# =========================================================================
# CHANGELOG [2025-01-31 - Claude]
# Ensure cache directories exist and are writable BEFORE Python starts.
# ChromaDB will crash immediately if it can't write its embedding model.
# =========================================================================

# Test if /data is writable (persistent storage enabled)
if touch /data/.write_test 2>/dev/null; then
    rm -f /data/.write_test
    echo "βœ… /data is writable (persistent storage enabled)"
    # Ensure cache subdirectories exist
    mkdir -p /data/.cache/huggingface /data/.cache/chroma
else
    echo "⚠️  /data is NOT writable - redirecting cache to /tmp"
    echo "   (Enable persistent storage in Space Settings for durability)"
    # Redirect cache env vars to /tmp (writable but ephemeral)
    export HF_HOME=/tmp/.cache/huggingface
    export TRANSFORMERS_CACHE=/tmp/.cache/huggingface
    export XDG_CACHE_HOME=/tmp/.cache
    export CHROMA_CACHE_DIR=/tmp/.cache/chroma
    mkdir -p /tmp/.cache/huggingface /tmp/.cache/chroma
fi

echo "πŸ“ Cache directory: ${XDG_CACHE_HOME}"

# =========================================================================
# GRADIO VERSION CHECK
# =========================================================================

echo ""
echo "πŸ” DEBUG: Checking Gradio installation..."
python3 -c "
import gradio as gr
print(f'βœ“ Gradio version: {gr.__version__}')
print(f'βœ“ Gradio path: {gr.__file__}')
" 2>&1 || echo "❌ Gradio import failed!"

# =========================================================================
# REPOSITORY SETUP
# =========================================================================

# Check if a repository URL was provided
if [ -n "$REPO_URL" ]; then
    echo "πŸ“¦ Cloning repository: $REPO_URL"
    if [ -d "/workspace/e-t-systems/.git" ]; then
        echo "  Repository already cloned, pulling latest..."
        cd /workspace/e-t-systems && git pull
    else
        git clone "$REPO_URL" /workspace/e-t-systems
    fi
else
    echo "ℹ️ No REPO_URL provided, using demo repository"
fi

# Show what's in the repository
echo "πŸ“‚ Repository contents:"
ls -la /workspace/e-t-systems/ 2>/dev/null || echo "  (empty or not found)"

# =========================================================================
# LAUNCH APPLICATION
# =========================================================================

echo "πŸš€ Starting Gradio application..."
exec python3 /app/app.py