Adds a `publish` job to ci.yml that fires only on green pushes to main. It builds broker, server, and frontend from images/*.Dockerfile, tags each with :main-<sha> + :latest, and pushes to the fleet registry at redclaw-web-01:5000 (via its Tailscale IP 100.94.185.103, which the daemons already trust in insecure-registries). Adds a small systemd oneshot + 1-minute timer for gw-04 that polls :latest of each service, pulls on drift, retags to the un-prefixed name the current compose file uses, and rolls only the changed services. The retag keeps /root/clawmates/docker-compose.yml unchanged for now — a follow-up can migrate the compose file to registry-prefixed names once we're confident. End-to-end: push to main -> tests -> images pushed -> gw-04 timer pulls within ~1 min -> prod updated. Rollback = docker tag <old-sha> :latest and `docker compose up -d`.
63 lines
2.0 KiB
Bash
Executable File
63 lines
2.0 KiB
Bash
Executable File
#!/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/<svc>:latest → clawmates/<svc>: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:-<none>} -> $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[*]}"
|