feat: add crucible image and sow-tools binary channel promote
This commit is contained in:
Executable
+85
@@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env bash
|
||||
# vendored from sow-platform/deploy/scripts/promote-gitea.sh — keep in sync
|
||||
# Channel pointer for crucible registry images (service tier).
|
||||
# channels.json values are the 12-char git SHAs used as image tags.
|
||||
set -euo pipefail
|
||||
|
||||
: "${GITEA_SERVER:?set GITEA_SERVER}"
|
||||
: "${GITEA_TOKEN:?set GITEA_TOKEN}"
|
||||
: "${GITEA_OWNER:?set GITEA_OWNER}"
|
||||
: "${REGISTRY_HOST:?set REGISTRY_HOST}"
|
||||
: "${REGISTRY_USER:?set REGISTRY_USER}"
|
||||
: "${REGISTRY_PASSWORD:?set REGISTRY_PASSWORD}"
|
||||
|
||||
STREAM_NAME=crucible
|
||||
STREAM_TIER=service
|
||||
DRY_RUN="${DRY_RUN:-0}"
|
||||
|
||||
need() { command -v "$1" >/dev/null 2>&1 || { printf 'need: %s not found\n' "$1" >&2; exit 1; }; }
|
||||
need jq curl skopeo
|
||||
die() { printf '[channels] ERROR: %s\n' "$*" >&2; exit 1; }
|
||||
log() { printf '[channels] %s\n' "$*" >&2; }
|
||||
|
||||
require_release() {
|
||||
local tag="$1"
|
||||
skopeo inspect \
|
||||
--creds "${REGISTRY_USER}:${REGISTRY_PASSWORD}" \
|
||||
"docker://${REGISTRY_HOST}/deployment/crucible:${tag}" \
|
||||
>/dev/null 2>&1 \
|
||||
|| die "no published image crucible:${tag}"
|
||||
}
|
||||
|
||||
# ---- promote-gitea.sh body (paste verbatim from sow-platform/deploy/scripts/promote-gitea.sh) ----
|
||||
_auth="Authorization: token ${GITEA_TOKEN}"
|
||||
_pkg_url="${GITEA_SERVER}/api/packages/${GITEA_OWNER}/generic/deployment-channels/${STREAM_NAME}/channels.json"
|
||||
_pkg_del="${GITEA_SERVER}/api/v1/packages/${GITEA_OWNER}/generic/deployment-channels/${STREAM_NAME}"
|
||||
|
||||
valid_channel() { case "$1" in current|previous) return 0 ;; *) return 1 ;; esac; }
|
||||
|
||||
read_channels() {
|
||||
local tmp status
|
||||
tmp="$(mktemp)"
|
||||
status="$(curl -fsS -o "$tmp" -w "%{http_code}" -H "$_auth" "$_pkg_url" 2>/dev/null || echo "000")"
|
||||
case "$status" in
|
||||
200) jq -e . "$tmp" >/dev/null 2>&1 || die "existing channels.json is invalid"; cat "$tmp" ;;
|
||||
404|000) printf '{}\n' ;;
|
||||
*) die "read channels.json: HTTP $status" ;;
|
||||
esac
|
||||
rm -f "$tmp"
|
||||
}
|
||||
|
||||
write_channels() {
|
||||
local json="$1" tmp
|
||||
jq -e . <<<"$json" >/dev/null 2>&1 || die "refusing to write invalid channels.json"
|
||||
tmp="$(mktemp)"; jq -S . <<<"$json" >"$tmp"
|
||||
if [[ "$DRY_RUN" == "1" ]]; then
|
||||
log "DRY_RUN: would write:"; jq -S . "$tmp" >&2; rm -f "$tmp"; return 0
|
||||
fi
|
||||
curl -fsS -X DELETE -H "$_auth" "$_pkg_del" >/dev/null 2>&1 || true
|
||||
curl -fsS -X PUT -H "$_auth" \
|
||||
-H "Content-Type: application/octet-stream" \
|
||||
--data-binary "@$tmp" \
|
||||
"$_pkg_url" >/dev/null || die "write channels.json failed"
|
||||
rm -f "$tmp"
|
||||
log "deployment-channels/crucible updated"
|
||||
jq -S . <<<"$json" >&2
|
||||
}
|
||||
|
||||
cmd="${1:-show}"
|
||||
case "$cmd" in
|
||||
show) read_channels | jq -S . ;;
|
||||
set)
|
||||
channel="${2:?usage: promote set <channel> <tag>}"
|
||||
tag="${3:?usage: promote set <channel> <tag>}"
|
||||
valid_channel "$channel" || die "unknown channel: $channel"
|
||||
require_release "$tag"
|
||||
write_channels "$(read_channels | jq --arg c "$channel" --arg t "$tag" '.[$c]=$t')"
|
||||
;;
|
||||
release)
|
||||
tag="${2:?usage: promote release <tag>}"
|
||||
require_release "$tag"
|
||||
write_channels "$(read_channels | jq --arg t "$tag" '
|
||||
(if .current then .previous = .current else . end) | .current = $t')"
|
||||
;;
|
||||
*) die "usage: promote show | set <channel> <tag> | release <tag>" ;;
|
||||
esac
|
||||
Reference in New Issue
Block a user