Update entrypoint.sh
Browse files- entrypoint.sh +14 -17
entrypoint.sh
CHANGED
|
@@ -3,7 +3,10 @@ set -e
|
|
| 3 |
|
| 4 |
echo "===== Application Startup at $(date) ====="
|
| 5 |
|
| 6 |
-
#
|
|
|
|
|
|
|
|
|
|
| 7 |
if [ -n "$GITHUB_TOKEN" ] && [ -n "$GITHUB_USER" ]; then
|
| 8 |
git config --global credential.helper store
|
| 9 |
git config --global user.name "$GITHUB_USER"
|
|
@@ -12,13 +15,13 @@ if [ -n "$GITHUB_TOKEN" ] && [ -n "$GITHUB_USER" ]; then
|
|
| 12 |
echo "β
Git credentials configured."
|
| 13 |
fi
|
| 14 |
|
| 15 |
-
# 2. Environment &
|
| 16 |
export XDG_CONFIG_HOME="/workspace/config"
|
| 17 |
export OPENCODE_CONFIG_DIR="/workspace/config/opencode"
|
| 18 |
export OPENCHAMBER_UI_PASSWORD="${GATEWAY_TOKEN:-changeme}"
|
| 19 |
mkdir -p $OPENCODE_CONFIG_DIR /workspace/projects
|
| 20 |
|
| 21 |
-
# 3.
|
| 22 |
if [ -n "$CLOUDFLARE_API_TOKEN" ]; then
|
| 23 |
mkdir -p ~/.wrangler/config
|
| 24 |
cat << EOF > ~/.wrangler/config/default.toml
|
|
@@ -27,7 +30,7 @@ EOF
|
|
| 27 |
echo "β
Wrangler configured."
|
| 28 |
fi
|
| 29 |
|
| 30 |
-
# 4.
|
| 31 |
if [ -n "$LLM_API_KEY" ]; then
|
| 32 |
export OPENROUTER_API_KEY="$LLM_API_KEY"
|
| 33 |
export ANTHROPIC_API_KEY="$LLM_API_KEY"
|
|
@@ -35,18 +38,15 @@ if [ -n "$LLM_API_KEY" ]; then
|
|
| 35 |
export GOOGLE_API_KEY="$LLM_API_KEY"
|
| 36 |
export GEMINI_API_KEY="$LLM_API_KEY"
|
| 37 |
export DEEPSEEK_API_KEY="$LLM_API_KEY"
|
| 38 |
-
export HF_TOKEN="$LLM_API_KEY"
|
| 39 |
fi
|
| 40 |
export OPENCODE_DEFAULT_MODEL="${LLM_MODEL:-openrouter/anthropic/claude-sonnet-4}"
|
| 41 |
|
| 42 |
-
# 5. Restore Workspace from HF
|
| 43 |
python /restore_workspace.py
|
| 44 |
|
| 45 |
-
# 6.
|
| 46 |
touch /workspace/config/startup.sh
|
| 47 |
chmod +x /workspace/config/startup.sh
|
| 48 |
-
|
| 49 |
-
# Add wrappers to bashrc to record package installs
|
| 50 |
if ! grep -q "workspace/config/startup.sh" ~/.bashrc 2>/dev/null; then
|
| 51 |
cat << 'EOF' >> ~/.bashrc
|
| 52 |
pip() { command pip "$@" && echo "pip $*" >> /workspace/config/startup.sh; }
|
|
@@ -54,21 +54,18 @@ npm() { command npm "$@" && echo "npm $*" >> /workspace/config/startup.sh; }
|
|
| 54 |
apt() { command apt "$@" && echo "apt $*" >> /workspace/config/startup.sh; }
|
| 55 |
EOF
|
| 56 |
fi
|
| 57 |
-
|
| 58 |
-
# Replay previously installed packages
|
| 59 |
echo "π¦ Replaying persistent packages..."
|
| 60 |
bash /workspace/config/startup.sh 2>/dev/null || true
|
| 61 |
|
| 62 |
-
# 7.
|
| 63 |
[ -n "$OPENCODE_APT_PACKAGES" ] && apt-get update && apt-get install -y $OPENCODE_APT_PACKAGES
|
| 64 |
[ -n "$OPENCODE_RUN" ] && bash -c "$OPENCODE_RUN"
|
| 65 |
|
| 66 |
-
# 8.
|
| 67 |
-
python /
|
| 68 |
-
[ -n "$
|
| 69 |
-
[ -n "$CLOUDFLARE_WORKERS_TOKEN" ] && [ -n "$CF_ACCOUNT_ID" ] && python /keep_alive.py &
|
| 70 |
|
| 71 |
-
# 9. Launch OpenChamber
|
| 72 |
cd /workspace/projects
|
| 73 |
echo "π Starting OpenChamber on port 7860..."
|
| 74 |
exec openchamber --port 7860 --host 0.0.0.0
|
|
|
|
| 3 |
|
| 4 |
echo "===== Application Startup at $(date) ====="
|
| 5 |
|
| 6 |
+
# β‘ START HEALTH SERVER FIRST (prevents HF timeout during restore)
|
| 7 |
+
python /health_server.py &
|
| 8 |
+
|
| 9 |
+
# 1. Git Credentials
|
| 10 |
if [ -n "$GITHUB_TOKEN" ] && [ -n "$GITHUB_USER" ]; then
|
| 11 |
git config --global credential.helper store
|
| 12 |
git config --global user.name "$GITHUB_USER"
|
|
|
|
| 15 |
echo "β
Git credentials configured."
|
| 16 |
fi
|
| 17 |
|
| 18 |
+
# 2. Environment & Dirs
|
| 19 |
export XDG_CONFIG_HOME="/workspace/config"
|
| 20 |
export OPENCODE_CONFIG_DIR="/workspace/config/opencode"
|
| 21 |
export OPENCHAMBER_UI_PASSWORD="${GATEWAY_TOKEN:-changeme}"
|
| 22 |
mkdir -p $OPENCODE_CONFIG_DIR /workspace/projects
|
| 23 |
|
| 24 |
+
# 3. Wrangler Config
|
| 25 |
if [ -n "$CLOUDFLARE_API_TOKEN" ]; then
|
| 26 |
mkdir -p ~/.wrangler/config
|
| 27 |
cat << EOF > ~/.wrangler/config/default.toml
|
|
|
|
| 30 |
echo "β
Wrangler configured."
|
| 31 |
fi
|
| 32 |
|
| 33 |
+
# 4. LLM Keys
|
| 34 |
if [ -n "$LLM_API_KEY" ]; then
|
| 35 |
export OPENROUTER_API_KEY="$LLM_API_KEY"
|
| 36 |
export ANTHROPIC_API_KEY="$LLM_API_KEY"
|
|
|
|
| 38 |
export GOOGLE_API_KEY="$LLM_API_KEY"
|
| 39 |
export GEMINI_API_KEY="$LLM_API_KEY"
|
| 40 |
export DEEPSEEK_API_KEY="$LLM_API_KEY"
|
|
|
|
| 41 |
fi
|
| 42 |
export OPENCODE_DEFAULT_MODEL="${LLM_MODEL:-openrouter/anthropic/claude-sonnet-4}"
|
| 43 |
|
| 44 |
+
# 5. Restore Workspace (now safe from HF timeout)
|
| 45 |
python /restore_workspace.py
|
| 46 |
|
| 47 |
+
# 6. Package Replay
|
| 48 |
touch /workspace/config/startup.sh
|
| 49 |
chmod +x /workspace/config/startup.sh
|
|
|
|
|
|
|
| 50 |
if ! grep -q "workspace/config/startup.sh" ~/.bashrc 2>/dev/null; then
|
| 51 |
cat << 'EOF' >> ~/.bashrc
|
| 52 |
pip() { command pip "$@" && echo "pip $*" >> /workspace/config/startup.sh; }
|
|
|
|
| 54 |
apt() { command apt "$@" && echo "apt $*" >> /workspace/config/startup.sh; }
|
| 55 |
EOF
|
| 56 |
fi
|
|
|
|
|
|
|
| 57 |
echo "π¦ Replaying persistent packages..."
|
| 58 |
bash /workspace/config/startup.sh 2>/dev/null || true
|
| 59 |
|
| 60 |
+
# 7. Startup Vars
|
| 61 |
[ -n "$OPENCODE_APT_PACKAGES" ] && apt-get update && apt-get install -y $OPENCODE_APT_PACKAGES
|
| 62 |
[ -n "$OPENCODE_RUN" ] && bash -c "$OPENCODE_RUN"
|
| 63 |
|
| 64 |
+
# 8. Background Services
|
| 65 |
+
[ -n "$MY_HF_TOKEN" ] && [ -n "$HF_DATASET_REPO" ] && python /sync_workspace.py &
|
| 66 |
+
[ -n "$CLOUDFLARE_API_TOKEN" ] && [ -n "$CF_ACCOUNT_ID" ] && python /keep_alive.py &
|
|
|
|
| 67 |
|
| 68 |
+
# 9. Launch OpenChamber
|
| 69 |
cd /workspace/projects
|
| 70 |
echo "π Starting OpenChamber on port 7860..."
|
| 71 |
exec openchamber --port 7860 --host 0.0.0.0
|