Add update.sh to generated project scripts
Updates three things: 1. Context Studio Core — git pull on ~/.context-studio/core 2. Claude Code — npm install -g @anthropic-ai/claude-code in container 3. OS packages — apt-get update + upgrade in container If container is not running, in-container steps are skipped with a warning. Offers optional full image rebuild (--pull --no-cache) for a clean slate. Warns that in-container updates are ephemeral without a rebuild. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
6aa4c22d9e
commit
8a82d27dae
2 changed files with 85 additions and 1 deletions
|
|
@ -123,5 +123,84 @@ echo "→ Stopping \$CONTAINER_NAME..."
|
|||
STOP
|
||||
chmod +x "$project_dir/stop.sh"
|
||||
|
||||
success "Generated: start.sh stop.sh bin/claude"
|
||||
# ── update.sh — update core, claude-code, and optionally OS packages ──
|
||||
cat > "$project_dir/update.sh" <<UPDATE
|
||||
#!/usr/bin/env bash
|
||||
set -uo pipefail
|
||||
SCRIPT_DIR="\$(cd "\$(dirname "\${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_DIR="\$SCRIPT_DIR"
|
||||
CONTAINER_NAME="${container_name}"
|
||||
IMAGE_NAME="${slug}"
|
||||
RUNTIME="\$(command -v podman || command -v docker || true)"
|
||||
CS_CORE="\${CS_CORE_DIR:-\$HOME/.context-studio/core}"
|
||||
|
||||
GREEN='\033[0;32m'; CYAN='\033[0;36m'; YELLOW='\033[1;33m'; BOLD='\033[1m'; RESET='\033[0m'
|
||||
info() { echo -e "\${CYAN}\${BOLD}[update]\${RESET} \$*"; }
|
||||
success() { echo -e "\${GREEN}\${BOLD}[ok]\${RESET} \$*"; }
|
||||
warn() { echo -e "\${YELLOW}\${BOLD}[warn]\${RESET} \$*"; }
|
||||
|
||||
CONTAINER_RUNNING=false
|
||||
if "\$RUNTIME" container inspect "\$CONTAINER_NAME" --format '{{.State.Running}}' 2>/dev/null | grep -q true; then
|
||||
CONTAINER_RUNNING=true
|
||||
fi
|
||||
|
||||
# ── 1. Update Context Studio Core ───────────────────────────────────────
|
||||
info "Updating Context Studio Core..."
|
||||
if [[ -d "\$CS_CORE/.git" ]]; then
|
||||
git -C "\$CS_CORE" pull --ff-only && success "Core updated." || warn "Core pull failed — continuing with current version."
|
||||
else
|
||||
warn "Core not found at \$CS_CORE — skipping."
|
||||
fi
|
||||
|
||||
# ── 2. Update Claude Code in container ──────────────────────────────────
|
||||
info "Updating Claude Code (claude-code)..."
|
||||
if \$CONTAINER_RUNNING; then
|
||||
"\$RUNTIME" exec "\$CONTAINER_NAME" npm install -g @anthropic-ai/claude-code \
|
||||
&& success "Claude Code updated in running container." \
|
||||
|| warn "Claude Code update failed."
|
||||
else
|
||||
warn "Container not running — Claude Code will be updated on next image build."
|
||||
fi
|
||||
|
||||
# ── 3. Update OS packages in container ──────────────────────────────────
|
||||
info "Updating OS packages in container..."
|
||||
if \$CONTAINER_RUNNING; then
|
||||
"\$RUNTIME" exec "\$CONTAINER_NAME" bash -c "apt-get update -qq && apt-get upgrade -y" \
|
||||
&& success "OS packages updated in running container." \
|
||||
|| warn "OS package update failed."
|
||||
else
|
||||
warn "Container not running — OS packages will be updated on next image build."
|
||||
fi
|
||||
|
||||
# ── 4. Rebuild image to persist updates ─────────────────────────────────
|
||||
echo ""
|
||||
echo -e "\${BOLD}Rebuild container image?\${RESET}"
|
||||
echo -e " Rebuilds from scratch with latest base image + all packages."
|
||||
echo -e " ${YELLOW}⚠ Takes 5–15 minutes. Stops the running container.\${RESET}"
|
||||
echo -ne "Rebuild now? \${CYAN}[y/N]\${RESET}: "
|
||||
read -r _rebuild || true
|
||||
_rebuild="\${_rebuild:-n}"
|
||||
|
||||
if [[ "\$_rebuild" =~ ^[Yy]\$ ]]; then
|
||||
info "Stopping container..."
|
||||
"\$RUNTIME" rm -f "\$CONTAINER_NAME" 2>/dev/null || true
|
||||
|
||||
info "Rebuilding image '\$IMAGE_NAME' (--pull --no-cache)..."
|
||||
"\$RUNTIME" build --pull --no-cache -t "\$IMAGE_NAME" "\$PROJECT_DIR/.devcontainer/" \
|
||||
&& success "Image rebuilt. Run ./start.sh to start with the fresh image." \
|
||||
|| { echo "Image build failed." >&2; exit 1; }
|
||||
else
|
||||
info "Skipped image rebuild."
|
||||
if \$CONTAINER_RUNNING; then
|
||||
warn "In-container updates are temporary — they will be lost when the container is recreated."
|
||||
warn "Run ./update.sh again and choose 'y' to rebuild, or run ./start.sh (which recreates the container from the old image)."
|
||||
fi
|
||||
fi
|
||||
|
||||
echo ""
|
||||
success "Update complete."
|
||||
UPDATE
|
||||
chmod +x "$project_dir/update.sh"
|
||||
|
||||
success "Generated: start.sh stop.sh update.sh bin/claude"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -137,6 +137,11 @@ print_next_steps() {
|
|||
echo -e "${BOLD}Stop the container:${RESET}"
|
||||
echo -e " ${CYAN}./stop.sh${RESET}"
|
||||
echo ""
|
||||
echo -e "${BOLD}Update everything:${RESET}"
|
||||
echo -e " ${CYAN}./update.sh${RESET}"
|
||||
echo -e " Updates Context Studio Core, Claude Code, and OS packages."
|
||||
echo -e " Optionally rebuilds the image from scratch."
|
||||
echo ""
|
||||
echo -e "${BOLD}How it works:${RESET}"
|
||||
echo -e " • Context Studio Core runs on your host (Electron UI, no display issues)"
|
||||
echo -e " • Claude Code agents run inside container ${CYAN}cs-${slug}${RESET}"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue