gabriel / musehub public
publish_muse_release.sh bash
148 lines 5.7 KB
Raw
sha256:3ff9c9863a9891bdcde71b4a43228f66d0493e38b7cc1d09fe9eb7de774046b2 feat: add repair-commit wire endpoint (API parity with repa… Opus 4.8 minor ⚠ breaking 1 day ago
1 #!/usr/bin/env bash
2 # Publish a new muse CLI release to staging.
3 #
4 # Usage:
5 # bash deploy/publish_muse_release.sh # builds current version from ~/ecosystem/muse
6 # MUSE_VERSION=0.2.1 bash deploy/publish_muse_release.sh # override version label
7 #
8 # What it does:
9 # 1. Builds the muse sdist from ~/ecosystem/muse.
10 # 2. Uploads the tarball to s3://musehub-releases/muse-{version}.tar.gz.
11 # 3. SSMs to the staging instance to pull the tarball from S3 into /data/releases/.
12 # 4. Removes stale tarballs from S3 and /data/releases/ (keeps the 3 most recent).
13 # 5. Verifies the tarball is live via https://staging.musehub.ai/releases/muse-{version}.tar.gz.
14 #
15 # Prerequisites:
16 # - Python 3.14 + build package (pip install build)
17 # - AWS CLI configured (musehub-infra profile or default with the right creds)
18 # - ~/ecosystem/muse checked out at the version you want to ship
19
20 set -euo pipefail
21
22 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
23 MUSE_REPO="${MUSE_REPO:-$HOME/ecosystem/muse}"
24 S3_BUCKET="musehub-releases"
25 STAGING_INSTANCE="i-07547cd20bee2dea5"
26 REGION="us-east-1"
27 STAGING_URL="https://staging.musehub.ai"
28 KEEP_RELEASES=3 # number of tarballs to keep on S3 and server
29
30 log() { printf '\033[1;34m%s\033[0m\n' "$*" >&2; }
31 die() { printf '\033[1;31mERROR: %s\033[0m\n' "$*" >&2; exit 1; }
32
33 # ── 1. Resolve version ────────────────────────────────────────────────────────
34
35 if [ -z "${MUSE_VERSION:-}" ]; then
36 MUSE_VERSION=$(python3 -c "
37 import re, pathlib
38 t = pathlib.Path('$MUSE_REPO/pyproject.toml').read_text()
39 m = re.search(r'^version\s*=\s*\"([^\"]+)\"', t, re.MULTILINE)
40 print(m.group(1))
41 ")
42 fi
43
44 log "[1/5] Building muse $MUSE_VERSION from $MUSE_REPO"
45
46 # ── 2. Build sdist ────────────────────────────────────────────────────────────
47
48 cd "$MUSE_REPO"
49 python3 -m build --sdist --outdir dist/ 2>&1 | tail -3
50
51 TARBALL="dist/muse-${MUSE_VERSION}.tar.gz"
52 [ -f "$TARBALL" ] || die "Expected tarball not found: $MUSE_REPO/$TARBALL"
53 log " Built: $(du -sh "$TARBALL" | cut -f1) $TARBALL"
54
55 # ── 3. Upload to S3 ───────────────────────────────────────────────────────────
56
57 log "[2/5] Uploading to s3://$S3_BUCKET/"
58 aws s3 cp "$TARBALL" "s3://$S3_BUCKET/muse-${MUSE_VERSION}.tar.gz"
59
60 # ── 4. Pull from S3 into /data/releases/ on staging ─────────────────────────
61
62 log "[3/5] Pushing to staging ($STAGING_INSTANCE)"
63
64 CMD="aws s3 cp s3://$S3_BUCKET/muse-${MUSE_VERSION}.tar.gz /tmp/muse-${MUSE_VERSION}.tar.gz && \
65 docker run --rm -v musehub_data:/data -v /tmp:/src alpine sh -c \
66 'mkdir -p /data/releases && cp /src/muse-${MUSE_VERSION}.tar.gz /data/releases/muse-${MUSE_VERSION}.tar.gz'"
67
68 CMD_ID=$(aws ssm send-command \
69 --region "$REGION" \
70 --instance-ids "$STAGING_INSTANCE" \
71 --document-name "AWS-RunShellScript" \
72 --parameters "commands=[\"$CMD\"]" \
73 --comment "publish muse $MUSE_VERSION" \
74 --timeout-seconds 120 \
75 --query "Command.CommandId" \
76 --output text)
77
78 log " SSM command: $CMD_ID — polling..."
79
80 for i in $(seq 1 24); do
81 sleep 5
82 STATUS=$(aws ssm get-command-invocation \
83 --region "$REGION" \
84 --command-id "$CMD_ID" \
85 --instance-id "$STAGING_INSTANCE" \
86 --query "Status" \
87 --output text 2>/dev/null || echo "Pending")
88 case "$STATUS" in
89 Success) log " ✅ Staging copy succeeded."; break ;;
90 Failed|Cancelled|TimedOut) die "SSM command $STATUS" ;;
91 *) printf '.' >&2 ;;
92 esac
93 done
94 [ "$STATUS" = "Success" ] || die "SSM timed out (status: $STATUS)"
95
96 # ── 5. Clean up old releases (S3 + server, keep newest KEEP_RELEASES) ────────
97
98 log "[4/5] Cleaning up old releases (keeping $KEEP_RELEASES newest)"
99
100 # S3 cleanup — list, sort by version, delete oldest
101 # awk buffers all lines and prints only those before the last KEEP_RELEASES
102 # (portable — avoids GNU-only `head -n -N` which fails on macOS/BSD)
103 STALE_S3=$(aws s3 ls "s3://$S3_BUCKET/" \
104 | awk '{print $NF}' \
105 | grep '^muse-.*\.tar\.gz$' \
106 | sort -V \
107 | awk -v keep="$KEEP_RELEASES" '{lines[NR]=$0} END{for(i=1;i<=NR-keep;i++) print lines[i]}')
108
109 if [ -n "$STALE_S3" ]; then
110 while IFS= read -r key; do
111 log " Deleting s3://$S3_BUCKET/$key"
112 aws s3 rm "s3://$S3_BUCKET/$key"
113 done <<< "$STALE_S3"
114 else
115 log " S3: nothing to remove."
116 fi
117
118 # Server cleanup — same logic via SSM (awk for portability)
119 CLEAN_CMD="ls /data/releases/muse-*.tar.gz 2>/dev/null \
120 | sort -V \
121 | awk -v keep=$KEEP_RELEASES '{lines[NR]=\$0} END{for(i=1;i<=NR-keep;i++) print lines[i]}' \
122 | xargs -r rm -v"
123
124 aws ssm send-command \
125 --region "$REGION" \
126 --instance-ids "$STAGING_INSTANCE" \
127 --document-name "AWS-RunShellScript" \
128 --parameters "commands=[\"$CLEAN_CMD\"]" \
129 --comment "cleanup old muse releases" \
130 --output text \
131 --query "Command.CommandId" > /dev/null
132
133 # ── 6. Smoke-test: verify tarball is live ─────────────────────────────────────
134
135 log "[5/5] Verifying $STAGING_URL/releases/muse-${MUSE_VERSION}.tar.gz"
136
137 HTTP=$(curl -sI "$STAGING_URL/releases/muse-${MUSE_VERSION}.tar.gz" \
138 | grep -i "^HTTP" | awk '{print $2}')
139
140 if [ "$HTTP" = "200" ]; then
141 log " ✅ Live at $STAGING_URL/releases/muse-${MUSE_VERSION}.tar.gz"
142 else
143 die "Expected HTTP 200, got: $HTTP"
144 fi
145
146 log ""
147 log "muse $MUSE_VERSION is live. Install with:"
148 log " curl -fsSL $STAGING_URL/install.sh | sh"
File History 1 commit
sha256:3ff9c9863a9891bdcde71b4a43228f66d0493e38b7cc1d09fe9eb7de774046b2 feat: add repair-commit wire endpoint (API parity with repa… Opus 4.8 minor 1 day ago