#!/usr/bin/env bash # Deploy irongit to the rybbit server: build the image here, ship it over SSH, # and roll only the irongit service in /opt/hygo (behind Caddy, on the shared # Postgres). Publishes the bundled ig CLI to R2 when its version changed. # # ./deploy.sh # # Roll back to the previous image: # ssh rybbit 'cd /opt/hygo && docker tag irongit:$(cat .irongit.prev) irongit:latest && docker compose up -d --no-deps irongit' set -euo pipefail cd "$(dirname "$0")" REMOTE=${DEPLOY_HOST:-rybbit} TAG=$(git rev-parse --short HEAD) if ! git diff --quiet HEAD; then TAG="$TAG-dirty-$(date +%Y%m%d%H%M%S)" fi PUBLIC_URL=${DEPLOY_PUBLIC_URL:-https://git.hygo.ai} # ig's version is major.minor from cli/Cargo.toml plus the number of commits # that touched the CLI, so any CLI change publishes a newer release that # `ig upgrade` (and its daily notice) picks up. No manual bumps. IG_BASE=$(sed -n 's/^version = "\([0-9]*\.[0-9]*\)\..*"/\1/p' cli/Cargo.toml | head -1) IG_VERSION="$IG_BASE.$(git rev-list --count HEAD -- cli shared)" echo "==> building irongit:$TAG (ig $IG_VERSION, default host $PUBLIC_URL)" docker build --build-arg "IG_BUILD_VERSION=$IG_VERSION" --build-arg "IG_DEFAULT_HOST=$PUBLIC_URL" -t "irongit:$TAG" . echo "==> shipping to $REMOTE" docker save "irongit:$TAG" | gzip -1 | ssh "$REMOTE" 'gunzip | docker load' echo "==> rolling" ssh "$REMOTE" bash -s -- "$TAG" "$IG_VERSION" <<'REMOTE_SCRIPT' set -euo pipefail cd /opt/hygo tag=$1 ig_version=$2 [ -f .irongit.tag ] && cp .irongit.tag .irongit.prev docker tag "irongit:$tag" irongit:latest echo "$tag" > .irongit.tag docker compose up -d --no-deps irongit ok=0 for _ in $(seq 1 45); do status=$(docker inspect irongit --format '{{.State.Health.Status}}' 2>/dev/null || echo none) if [ "$status" = healthy ]; then ok=1; break; fi sleep 2 done if [ "$ok" != 1 ]; then echo "irongit did not become healthy; last logs:" >&2 docker logs --tail 60 irongit >&2 exit 1 fi echo "irongit:$tag healthy" published=$(docker exec irongit wget -qO- http://127.0.0.1:7878/api/v1/cli/latest 2>/dev/null | sed -n 's/.*"version":"\([^"]*\)".*/\1/p' || true) if [ "$published" != "$ig_version" ]; then echo "publishing ig $ig_version (was ${published:-none})" docker exec irongit irongit admin publish-cli /usr/local/share/irongit/ig --version "$ig_version" fi # Keep the three newest irongit images. docker images irongit --format '{{.Tag}} {{.CreatedAt}}' | grep -v '^latest ' | sort -k2 -r | tail -n +4 | cut -d' ' -f1 \ | while read -r old; do [ "$old" = "$tag" ] || docker rmi "irongit:$old" >/dev/null 2>&1 || true; done REMOTE_SCRIPT echo "==> done: $PUBLIC_URL"