Update entrypoint.sh
Browse files- entrypoint.sh +30 -17
entrypoint.sh
CHANGED
|
@@ -1,33 +1,46 @@
|
|
| 1 |
#!/bin/bash
|
| 2 |
set -e
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
export OPENCODE_BINARY="/root/.local/bin/opencode"
|
| 6 |
-
if [ ! -f "$OPENCODE_BINARY" ]; then
|
| 7 |
-
# Auto-detect if it ended up somewhere else
|
| 8 |
-
export OPENCODE_BINARY=$(find / -name "opencode" -executable -type f 2>/dev/null | head -n 1)
|
| 9 |
-
fi
|
| 10 |
-
|
| 11 |
-
# 1. Inject Git Credentials for seamless GitHub pushing
|
| 12 |
if [ -n "$GITHUB_TOKEN" ] && [ -n "$GITHUB_USER" ]; then
|
| 13 |
git config --global credential.helper store
|
| 14 |
git config --global user.name "$GITHUB_USER"
|
| 15 |
git config --global user.email "$GITHUB_USER@users.noreply.github.com"
|
| 16 |
echo "https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com" > ~/.git-credentials
|
| 17 |
-
echo "Git credentials configured."
|
| 18 |
fi
|
| 19 |
|
| 20 |
-
# 2.
|
| 21 |
export XDG_CONFIG_HOME="/workspace/config"
|
| 22 |
export OPENCODE_CONFIG_DIR="/workspace/config/opencode"
|
| 23 |
mkdir -p $OPENCODE_CONFIG_DIR /workspace/projects
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
# 3.
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
echo "Starting OpenChamber on port 7860..."
|
| 32 |
cd /workspace/projects
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
#!/bin/bash
|
| 2 |
set -e
|
| 3 |
|
| 4 |
+
# 1. Git Credentials
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
if [ -n "$GITHUB_TOKEN" ] && [ -n "$GITHUB_USER" ]; then
|
| 6 |
git config --global credential.helper store
|
| 7 |
git config --global user.name "$GITHUB_USER"
|
| 8 |
git config --global user.email "$GITHUB_USER@users.noreply.github.com"
|
| 9 |
echo "https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com" > ~/.git-credentials
|
|
|
|
| 10 |
fi
|
| 11 |
|
| 12 |
+
# 2. Environment & Directories
|
| 13 |
export XDG_CONFIG_HOME="/workspace/config"
|
| 14 |
export OPENCODE_CONFIG_DIR="/workspace/config/opencode"
|
| 15 |
mkdir -p $OPENCODE_CONFIG_DIR /workspace/projects
|
| 16 |
+
touch /workspace/config/startup.sh
|
| 17 |
+
chmod +x /workspace/config/startup.sh
|
| 18 |
|
| 19 |
+
# 3. Ephemeral Package Replay (Wrappers for terminal)
|
| 20 |
+
cat << 'EOF' >> ~/.bashrc
|
| 21 |
+
pip() { command pip "$@" && echo "pip $*" >> /workspace/config/startup.sh; }
|
| 22 |
+
npm() { command npm "$@" && echo "npm $*" >> /workspace/config/startup.sh; }
|
| 23 |
+
apt() { command apt "$@" && echo "apt $*" >> /workspace/config/startup.sh; }
|
| 24 |
+
EOF
|
| 25 |
+
|
| 26 |
+
# 4. Replay previously installed packages
|
| 27 |
+
echo "Replaying persistent packages..."
|
| 28 |
+
bash /workspace/config/startup.sh || true
|
| 29 |
+
|
| 30 |
+
# 5. Run Startup Variables
|
| 31 |
+
[ -n "$OPENCODE_APT_PACKAGES" ] && apt-get update && apt-get install -y $OPENCODE_APT_PACKAGES
|
| 32 |
+
[ -n "$OPENCODE_RUN" ] && bash -c "$OPENCODE_RUN"
|
| 33 |
+
|
| 34 |
+
# 6. Start Background Services
|
| 35 |
+
python /health_server.py &
|
| 36 |
+
python /sync_config.py &
|
| 37 |
+
python /keep_alive.py &
|
| 38 |
|
| 39 |
+
# 7. Self-Healing Gateway (Auto-restarts OpenChamber if it crashes)
|
|
|
|
| 40 |
cd /workspace/projects
|
| 41 |
+
echo "Starting OpenChamber..."
|
| 42 |
+
while true; do
|
| 43 |
+
PORT=7860 openchamber --host 0.0.0.0
|
| 44 |
+
echo "OpenChamber exited with code $?. Restarting in 5 seconds..."
|
| 45 |
+
sleep 5
|
| 46 |
+
done
|