irongit

Git hosting and a container registry in one Rust binary (axum + Astro)

irongit/deploy.sh
62 lines2.2 KBBourne Again Shell (bash)
1#!/usr/bin/env bash
2# Deploy irongit to the rybbit server: build the image here, ship it over SSH,
3# and roll only the irongit service in /opt/hygo (behind Caddy, on the shared
4# Postgres). Publishes the bundled ig CLI to R2 when its version changed.
5#
6# ./deploy.sh
7#
8# Roll back to the previous image:
9# ssh rybbit 'cd /opt/hygo && docker tag irongit:$(cat .irongit.prev) irongit:latest && docker compose up -d --no-deps irongit'
10set -euo pipefail
11
12cd "$(dirname "$0")"
13REMOTE=${DEPLOY_HOST:-rybbit}
14TAG=$(git rev-parse --short HEAD)
15if ! git diff --quiet HEAD; then
16 TAG="$TAG-dirty-$(date +%Y%m%d%H%M%S)"
17fi
18IG_VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' cli/Cargo.toml | head -1)
19
20echo "==> building irongit:$TAG (ig $IG_VERSION)"
21docker build -t "irongit:$TAG" .
22
23echo "==> shipping to $REMOTE"
24docker save "irongit:$TAG" | gzip -1 | ssh "$REMOTE" 'gunzip | docker load'
25
26echo "==> rolling"
27ssh "$REMOTE" bash -s -- "$TAG" "$IG_VERSION" <<'REMOTE_SCRIPT'
28set -euo pipefail
29cd /opt/hygo
30tag=$1
31ig_version=$2
32
33[ -f .irongit.tag ] && cp .irongit.tag .irongit.prev
34docker tag "irongit:$tag" irongit:latest
35echo "$tag" > .irongit.tag
36docker compose up -d --no-deps irongit
37
38ok=0
39for _ in $(seq 1 45); do
40 status=$(docker inspect irongit --format '{{.State.Health.Status}}' 2>/dev/null || echo none)
41 if [ "$status" = healthy ]; then ok=1; break; fi
42 sleep 2
43done
44if [ "$ok" != 1 ]; then
45 echo "irongit did not become healthy; last logs:" >&2
46 docker logs --tail 60 irongit >&2
47 exit 1
48fi
49echo "irongit:$tag healthy"
50
51published=$(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)
52if [ "$published" != "$ig_version" ]; then
53 echo "publishing ig $ig_version (was ${published:-none})"
54 docker exec irongit irongit admin publish-cli /usr/local/share/irongit/ig --version "$ig_version"
55fi
56
57# Keep the three newest irongit images.
58docker images irongit --format '{{.Tag}} {{.CreatedAt}}' | grep -v '^latest ' | sort -k2 -r | tail -n +4 | cut -d' ' -f1 \
59 | while read -r old; do [ "$old" = "$tag" ] || docker rmi "irongit:$old" >/dev/null 2>&1 || true; done
60REMOTE_SCRIPT
61
62echo "==> done: https://git.hygo.ai"