3794ec60d7
- Fix chown/sudo to use numeric UID/GID instead of hardcoded 'claude' username (baseimage-gui creates users dynamically, name not available at script runtime) - Fix image name: ghcr.io/cpfarhood/devcontainer (matches github.repository) - Fix ConfigMap name: antigravity-config -> antigravity (matches statefulset refs) - Set github-repo in ConfigMap to headlamp-polaris-plugin - Set HTTPRoute to external gateway at antigravity.dev.farh.net - Add CLAUDE.md for Claude Code guidance Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
81 lines
2.6 KiB
Bash
81 lines
2.6 KiB
Bash
#!/bin/bash
|
|
# Initialize repository and start Happy Coder
|
|
set -e
|
|
|
|
echo "=== Repository Initialization ==="
|
|
|
|
# Check if GITHUB_REPO is set
|
|
if [ -z "$GITHUB_REPO" ]; then
|
|
echo "GITHUB_REPO not set, skipping repository clone"
|
|
WORKSPACE_DIR="/workspace/default"
|
|
mkdir -p "$WORKSPACE_DIR"
|
|
else
|
|
# Parse repo name from URL
|
|
REPO_NAME=$(basename "$GITHUB_REPO" .git)
|
|
WORKSPACE_DIR="/workspace/$REPO_NAME"
|
|
|
|
echo "Repository: $GITHUB_REPO"
|
|
echo "Target directory: $WORKSPACE_DIR"
|
|
|
|
# Check if repo already exists
|
|
if [ -d "$WORKSPACE_DIR/.git" ]; then
|
|
echo "Repository already exists, pulling latest changes..."
|
|
cd "$WORKSPACE_DIR"
|
|
|
|
# Configure git to use token if provided
|
|
if [ -n "$GITHUB_TOKEN" ]; then
|
|
git config credential.helper store
|
|
echo "https://oauth2:${GITHUB_TOKEN}@github.com" > /home/.git-credentials
|
|
chmod 600 /home/.git-credentials
|
|
fi
|
|
|
|
git pull || echo "Pull failed, continuing anyway..."
|
|
else
|
|
echo "Cloning repository..."
|
|
mkdir -p "$(dirname "$WORKSPACE_DIR")"
|
|
|
|
# Clone with token if provided
|
|
if [ -n "$GITHUB_TOKEN" ]; then
|
|
# Replace https://github.com/ with https://oauth2:token@github.com/
|
|
CLONE_URL=$(echo "$GITHUB_REPO" | sed "s|https://github.com/|https://oauth2:${GITHUB_TOKEN}@github.com/|")
|
|
git clone "$CLONE_URL" "$WORKSPACE_DIR"
|
|
|
|
# Configure credentials for future use
|
|
git config --global credential.helper store
|
|
echo "https://oauth2:${GITHUB_TOKEN}@github.com" > /home/.git-credentials
|
|
chmod 600 /home/.git-credentials
|
|
else
|
|
git clone "$GITHUB_REPO" "$WORKSPACE_DIR"
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
# Set ownership using numeric IDs (username may not exist yet in baseimage-gui)
|
|
RUN_UID="${USER_ID:-1000}"
|
|
RUN_GID="${GROUP_ID:-1000}"
|
|
chown -R "$RUN_UID:$RUN_GID" "$WORKSPACE_DIR"
|
|
chown -R "$RUN_UID:$RUN_GID" /home
|
|
|
|
# Start Happy Coder in background as the app user
|
|
echo "Starting Happy Coder..."
|
|
cd "$WORKSPACE_DIR"
|
|
|
|
# Create Happy Coder log file
|
|
HAPPY_LOG="/tmp/happy-coder.log"
|
|
touch "$HAPPY_LOG"
|
|
chown "$RUN_UID:$RUN_GID" "$HAPPY_LOG"
|
|
|
|
# Start Happy Coder as the app user (use numeric UID for compatibility with baseimage-gui)
|
|
sudo -u "#$RUN_UID" bash -c "cd '$WORKSPACE_DIR' && happy-coder > '$HAPPY_LOG' 2>&1 &"
|
|
|
|
# Save PID for monitoring
|
|
echo $! > /tmp/happy-coder.pid
|
|
|
|
echo "Happy Coder started (PID: $(cat /tmp/happy-coder.pid))"
|
|
echo "Logs available at: $HAPPY_LOG"
|
|
|
|
# Export workspace directory for startapp.sh
|
|
echo "$WORKSPACE_DIR" > /tmp/workspace-dir
|
|
|
|
echo "=== Initialization Complete ==="
|