#!/usr/bin/env bash # # clawmates rolling deploy — polls the fleet registry for :latest of the three # prod images (broker, server, frontend). On drift, pulls the new image, retags # it under the un-prefixed name the running compose file uses, and rolls the # affected services with `docker compose up -d`. # # Install: # sudo install -m 0755 clawmates-deploy.sh /usr/local/bin/clawmates-deploy.sh # sudo install -m 0644 clawmates-deploy.service /etc/systemd/system/ # sudo install -m 0644 clawmates-deploy.timer /etc/systemd/system/ # sudo systemctl daemon-reload # sudo systemctl enable --now clawmates-deploy.timer # # Verify: # systemctl list-timers clawmates-deploy.timer # tail -f /var/log/clawmates-deploy.log # # The retag step (registry/clawmates/:latest → clawmates/:latest) # keeps the current /root/clawmates/docker-compose.yml working unchanged until # we're ready to migrate the compose file to registry-prefixed image names. set -euo pipefail REGISTRY="${REGISTRY:-100.94.185.103:5000}" NAMESPACE="${NAMESPACE:-clawmates}" COMPOSE_DIR="${COMPOSE_DIR:-/root/clawmates}" LOG="${LOG:-/var/log/clawmates-deploy.log}" SERVICES=(broker server frontend) log() { printf '%s %s\n' "$(date -Iseconds)" "$*" | tee -a "$LOG" >/dev/null; } changed=() for svc in "${SERVICES[@]}"; do ref="${REGISTRY}/${NAMESPACE}/${svc}:latest" local_ref="${NAMESPACE}/${svc}:latest" before=$(docker inspect --format '{{.Id}}' "$ref" 2>/dev/null || echo "") if ! docker pull -q "$ref" >/dev/null 2>&1; then log "pull failed: $ref" continue fi after=$(docker inspect --format '{{.Id}}' "$ref") if [[ "$before" != "$after" ]]; then log "new image for $svc: ${before:-} -> $after" changed+=("$svc") fi # Always keep the un-prefixed tag pointing at the fresh image, so a stale # local retag can't wedge us. docker tag "$ref" "$local_ref" done if [[ ${#changed[@]} -eq 0 ]]; then exit 0 fi log "rolling: ${changed[*]}" cd "$COMPOSE_DIR" docker compose up -d "${changed[@]}" log "roll complete: ${changed[*]}"