gabriel / musehub public
publish_muse_release.sh bash
154 lines 6.1 KB
Raw
sha256:d035733f21ccff27735fddebfbbe0ed24565a32a22db8de5885402262671ecd2 chore: bump version to 0.2.0rc15 for musehub#113 fix release Sonnet 4.6 patch 15 days 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 # 6. Runs deploy/smoke_muse.sh — installs into a throwaway venv and runs 18 CLI checks.
15 #
16 # Prerequisites:
17 # - Python 3.14 + build package (pip install build)
18 # - AWS CLI configured (musehub-infra profile or default with the right creds)
19 # - ~/ecosystem/muse checked out at the version you want to ship
20
21 set -euo pipefail
22
23 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
24 MUSE_REPO="${MUSE_REPO:-$HOME/ecosystem/muse}"
25 S3_BUCKET="musehub-releases"
26 STAGING_INSTANCE="i-07547cd20bee2dea5"
27 REGION="us-east-1"
28 STAGING_URL="https://staging.musehub.ai"
29 KEEP_RELEASES=3 # number of tarballs to keep on S3 and server
30
31 log() { printf '\033[1;34m%s\033[0m\n' "$*" >&2; }
32 die() { printf '\033[1;31mERROR: %s\033[0m\n' "$*" >&2; exit 1; }
33
34 # ── 1. Resolve version ────────────────────────────────────────────────────────
35
36 if [ -z "${MUSE_VERSION:-}" ]; then
37 MUSE_VERSION=$(python3 -c "
38 import re, pathlib
39 t = pathlib.Path('$MUSE_REPO/pyproject.toml').read_text()
40 m = re.search(r'^version\s*=\s*\"([^\"]+)\"', t, re.MULTILINE)
41 print(m.group(1))
42 ")
43 fi
44
45 log "[1/5] Building muse $MUSE_VERSION from $MUSE_REPO"
46
47 # ── 2. Build sdist ────────────────────────────────────────────────────────────
48
49 cd "$MUSE_REPO"
50 python3 -m build --sdist --outdir dist/ 2>&1 | tail -3
51
52 TARBALL="dist/muse-${MUSE_VERSION}.tar.gz"
53 [ -f "$TARBALL" ] || die "Expected tarball not found: $MUSE_REPO/$TARBALL"
54 log " Built: $(du -sh "$TARBALL" | cut -f1) $TARBALL"
55
56 # ── 3. Upload to S3 ───────────────────────────────────────────────────────────
57
58 log "[2/5] Uploading to s3://$S3_BUCKET/"
59 aws s3 cp "$TARBALL" "s3://$S3_BUCKET/muse-${MUSE_VERSION}.tar.gz"
60
61 # ── 4. Pull from S3 into /data/releases/ on staging ─────────────────────────
62
63 log "[3/5] Pushing to staging ($STAGING_INSTANCE)"
64
65 CMD="aws s3 cp s3://$S3_BUCKET/muse-${MUSE_VERSION}.tar.gz /tmp/muse-${MUSE_VERSION}.tar.gz && \
66 docker run --rm -v musehub_data:/data -v /tmp:/src alpine sh -c \
67 'mkdir -p /data/releases && cp /src/muse-${MUSE_VERSION}.tar.gz /data/releases/muse-${MUSE_VERSION}.tar.gz'"
68
69 CMD_ID=$(aws ssm send-command \
70 --region "$REGION" \
71 --instance-ids "$STAGING_INSTANCE" \
72 --document-name "AWS-RunShellScript" \
73 --parameters "commands=[\"$CMD\"]" \
74 --comment "publish muse $MUSE_VERSION" \
75 --timeout-seconds 120 \
76 --query "Command.CommandId" \
77 --output text)
78
79 log " SSM command: $CMD_ID — polling..."
80
81 for i in $(seq 1 24); do
82 sleep 5
83 STATUS=$(aws ssm get-command-invocation \
84 --region "$REGION" \
85 --command-id "$CMD_ID" \
86 --instance-id "$STAGING_INSTANCE" \
87 --query "Status" \
88 --output text 2>/dev/null || echo "Pending")
89 case "$STATUS" in
90 Success) log " ✅ Staging copy succeeded."; break ;;
91 Failed|Cancelled|TimedOut) die "SSM command $STATUS" ;;
92 *) printf '.' >&2 ;;
93 esac
94 done
95 [ "$STATUS" = "Success" ] || die "SSM timed out (status: $STATUS)"
96
97 # ── 5. Clean up old releases (S3 + server, keep newest KEEP_RELEASES) ────────
98
99 log "[4/5] Cleaning up old releases (keeping $KEEP_RELEASES newest)"
100
101 # S3 cleanup — list, sort by version, delete oldest
102 # awk buffers all lines and prints only those before the last KEEP_RELEASES
103 # (portable — avoids GNU-only `head -n -N` which fails on macOS/BSD)
104 STALE_S3=$(aws s3 ls "s3://$S3_BUCKET/" \
105 | awk '{print $NF}' \
106 | grep '^muse-.*\.tar\.gz$' \
107 | sort -V \
108 | awk -v keep="$KEEP_RELEASES" '{lines[NR]=$0} END{for(i=1;i<=NR-keep;i++) print lines[i]}')
109
110 if [ -n "$STALE_S3" ]; then
111 while IFS= read -r key; do
112 log " Deleting s3://$S3_BUCKET/$key"
113 aws s3 rm "s3://$S3_BUCKET/$key"
114 done <<< "$STALE_S3"
115 else
116 log " S3: nothing to remove."
117 fi
118
119 # Server cleanup — same logic via SSM (awk for portability)
120 CLEAN_CMD="ls /data/releases/muse-*.tar.gz 2>/dev/null \
121 | sort -V \
122 | awk -v keep=$KEEP_RELEASES '{lines[NR]=\$0} END{for(i=1;i<=NR-keep;i++) print lines[i]}' \
123 | xargs -r rm -v"
124
125 aws ssm send-command \
126 --region "$REGION" \
127 --instance-ids "$STAGING_INSTANCE" \
128 --document-name "AWS-RunShellScript" \
129 --parameters "commands=[\"$CLEAN_CMD\"]" \
130 --comment "cleanup old muse releases" \
131 --output text \
132 --query "Command.CommandId" > /dev/null
133
134 # ── 6. Smoke-test: verify tarball is live ─────────────────────────────────────
135
136 log "[5/5] Verifying $STAGING_URL/releases/muse-${MUSE_VERSION}.tar.gz"
137
138 HTTP=$(curl -sI "$STAGING_URL/releases/muse-${MUSE_VERSION}.tar.gz" \
139 | grep -i "^HTTP" | awk '{print $2}')
140
141 if [ "$HTTP" = "200" ]; then
142 log " ✅ Live at $STAGING_URL/releases/muse-${MUSE_VERSION}.tar.gz"
143 else
144 die "Expected HTTP 200, got: $HTTP"
145 fi
146
147 # ── 7. Full smoke test ────────────────────────────────────────────────────────
148
149 log "[6/6] Running smoke test against $STAGING_URL"
150 bash "$SCRIPT_DIR/smoke_muse.sh" --url "$STAGING_URL" --version "$MUSE_VERSION"
151
152 log ""
153 log "muse $MUSE_VERSION is live. Install with:"
154 log " curl -fsSL $STAGING_URL/install.sh | sh"
File History 11 commits
sha256:d035733f21ccff27735fddebfbbe0ed24565a32a22db8de5885402262671ecd2 chore: bump version to 0.2.0rc15 for musehub#113 fix release Sonnet 4.6 patch 15 days ago
sha256:0032d6cfa33bc3c8367436ad768e7dd0e339b4332153160247da8266cb5fa352 Merge branch 'task/version-tags-phase3-server' into dev Human 17 days ago
sha256:4669620efda9ff41c55bdefd1f7bfe1c239d468428744c84ead9957e5a003a53 merge: rescue snapshot-recovery hardening (c00aa21d) into d… Opus 4.8 minor 30 days ago
sha256:a59da49c4611b970fc4b6ae48678ce4943261c213a07ddbd73ce9201df869b4a fix: remove false-positive proposal_comments index drop fro… Sonnet 4.6 patch 34 days ago
sha256:0a240d6dbff234f07d98a28a4a9a68db702f3f9ff9260196f24219bdb1c0b6f3 feat: render markdown mists as HTML with heading anchor links Sonnet 4.6 patch 35 days ago
sha256:24a7d47486ebc4ebd1832830580e177ec6f877b48dced8c000e198cdec4ce9d6 Merge 'task/bump-version-rc12' into 'dev' — proposal: Bump … Human 36 days ago
sha256:b9ff931d147e0114a1f17060f415b89ed551c170a91ff226c70437aa5c85f9ee Merge 'task/bump-version-rc12' into 'dev' — proposal: Bump … Human 36 days ago
sha256:d1122d21e73471879b460037b22c0b50fded7c423444a176f248428f75dac39c Merge 'task/fix-issue-pagination-cursor' into 'dev' — propo… Human 36 days ago
sha256:01e18975e73d2b3cd5b6db7929c895bef9aa6e0d4391dc5b2adfc548b41318dd Merge 'feat/adding-debug-logs-to-staging' into 'dev' — prop… Human 36 days ago
sha256:6b1949fc2797ca4c1936a637a4cbfec828ef56cf52398a2e74ca3c4f494e728f fix: use wire_bytes not mpack_bytes_raw in compute_object_b… Sonnet 4.6 patch 48 days ago
sha256:b99f2455dc346966d040133f5203297e6e3ef5803a93728a2c30568d0a0f7583 rename: delta_add → delta_upsert across wire format, models… Sonnet 4.6 patch 50 days ago