gabriel / musehub public
publish_muse_release.sh bash
154 lines 6.1 KB
Raw
sha256:1ccb8409daa5aabe577bd26d11b56ed12f3376d64011d0e75a247e81211a66ee docs(mwp4/phase5): tick Phase 5 checkboxes, close musehub#109 Sonnet 4.6 21 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 2 commits
sha256:1ccb8409daa5aabe577bd26d11b56ed12f3376d64011d0e75a247e81211a66ee docs(mwp4/phase5): tick Phase 5 checkboxes, close musehub#109 Sonnet 4.6 21 days ago
sha256:2c523da45351334b5c4dbefed4dc3dd553b3faa8737a4e6caf301e5dc82141be test(mwp4): Phase 0 RED reproduction tests for RC-4 ordering race Sonnet 4.6 21 days ago