#!/usr/bin/env bash # Build the image from the current tree, tag it with the commit, and switch to it. set -euo pipefail cd "$(dirname "$0")/.." tag="$(git rev-parse --short HEAD 2>/dev/null || echo init)" [[ -z "$(git status --porcelain)" ]] || tag="$tag-dirty" set -a . ./.env set +a mkdir -p "$DATA_DIR/paseo-home" "$DATA_DIR/browser-config" "$DATA_DIR/tailscale" docker compose build --pull --build-arg TOOLS_CACHE_BUST="$(date +%s)" paseo docker tag devbox:latest "devbox:$tag" # /workspace used to be a separate mount; it now lives inside the home mount (see # the Dockerfile) so pnpm can hardlink between projects and worktrees. Move the # old directory right before switching containers so running agents keep theirs. if [[ -d $DATA_DIR/workspace && ! -e $DATA_DIR/paseo-home/workspace ]]; then mv "$DATA_DIR/workspace" "$DATA_DIR/paseo-home/workspace" fi mkdir -p "$DATA_DIR/paseo-home/workspace" docker compose up -d echo "devbox is running devbox:$tag" # Every build reinstalls the toolchain into a fresh ~1 GB layer, so old images # pile up. Keep the newest few for scripts/rollback and drop the rest; tags # sharing an image count once, and the running image is always kept. keep=3 current="$(docker image inspect -f '{{.Id}}' devbox:latest)" docker image ls devbox --no-trunc --format '{{.ID}}' | awk '!seen[$0]++' | tail -n +"$((keep + 1))" | while read -r id; do [[ $id == "$current" ]] && continue docker image ls devbox --no-trunc --format '{{.ID}} {{.Repository}}:{{.Tag}}' | awk -v id="$id" '$1 == id { print $2 }' | xargs docker image rm || true done