publish_muse_release.sh
bash
sha256:1dd27e6d5c24550177b01b0a171e8375c07cf046b549e7683364706b6522d3bc
docs(#139): mark all 11 checklist items resolved, document …
Sonnet 5
12 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, prune via PEP 440 precedence (packaging.version.Version, |
| 102 | # not sort -V's lexical comparison -- see issue #128), delete the stale set. |
| 103 | STALE_S3=$(aws s3 ls "s3://$S3_BUCKET/" \ |
| 104 | | awk '{print $NF}' \ |
| 105 | | grep '^muse-.*\.tar\.gz$' \ |
| 106 | | xargs -r python3 "$SCRIPT_DIR/prune_releases.py" --keep "$KEEP_RELEASES") |
| 107 | |
| 108 | if [ -n "$STALE_S3" ]; then |
| 109 | while IFS= read -r key; do |
| 110 | log " Deleting s3://$S3_BUCKET/$key" |
| 111 | aws s3 rm "s3://$S3_BUCKET/$key" |
| 112 | done <<< "$STALE_S3" |
| 113 | else |
| 114 | log " S3: nothing to remove." |
| 115 | fi |
| 116 | |
| 117 | # Server cleanup — list remotely, compute the stale set LOCALLY with the same |
| 118 | # prune_releases.py call (Python/packaging availability on the bare EC2 host |
| 119 | # is not guaranteed), then send an explicit rm of the exact stale filenames. |
| 120 | # The remote shell never sorts or re-implements precedence logic itself. |
| 121 | LIST_CMD_ID=$(aws ssm send-command \ |
| 122 | --region "$REGION" \ |
| 123 | --instance-ids "$STAGING_INSTANCE" \ |
| 124 | --document-name "AWS-RunShellScript" \ |
| 125 | --parameters 'commands=["ls /data/releases/muse-*.tar.gz 2>/dev/null | xargs -n1 basename"]' \ |
| 126 | --comment "list muse releases for pruning" \ |
| 127 | --output text \ |
| 128 | --query "Command.CommandId") |
| 129 | |
| 130 | for i in $(seq 1 24); do |
| 131 | sleep 2 |
| 132 | LIST_STATUS=$(aws ssm get-command-invocation \ |
| 133 | --region "$REGION" \ |
| 134 | --command-id "$LIST_CMD_ID" \ |
| 135 | --instance-id "$STAGING_INSTANCE" \ |
| 136 | --query "Status" \ |
| 137 | --output text 2>/dev/null || echo "Pending") |
| 138 | case "$LIST_STATUS" in |
| 139 | Success) break ;; |
| 140 | Failed|Cancelled|TimedOut) die "SSM list command $LIST_STATUS" ;; |
| 141 | *) printf '.' >&2 ;; |
| 142 | esac |
| 143 | done |
| 144 | [ "$LIST_STATUS" = "Success" ] || die "SSM list command timed out (status: $LIST_STATUS)" |
| 145 | |
| 146 | REMOTE_FILES=$(aws ssm get-command-invocation \ |
| 147 | --region "$REGION" \ |
| 148 | --command-id "$LIST_CMD_ID" \ |
| 149 | --instance-id "$STAGING_INSTANCE" \ |
| 150 | --query "StandardOutputContent" \ |
| 151 | --output text) |
| 152 | |
| 153 | STALE_SERVER=$(printf '%s' "$REMOTE_FILES" | xargs -r python3 "$SCRIPT_DIR/prune_releases.py" --keep "$KEEP_RELEASES") |
| 154 | |
| 155 | if [ -n "$STALE_SERVER" ]; then |
| 156 | RM_ARGS=$(printf '%s\n' "$STALE_SERVER" | sed 's#^#/data/releases/#' | tr '\n' ' ') |
| 157 | aws ssm send-command \ |
| 158 | --region "$REGION" \ |
| 159 | --instance-ids "$STAGING_INSTANCE" \ |
| 160 | --document-name "AWS-RunShellScript" \ |
| 161 | --parameters "commands=[\"rm -v $RM_ARGS\"]" \ |
| 162 | --comment "prune stale muse releases" \ |
| 163 | --output text \ |
| 164 | --query "Command.CommandId" > /dev/null |
| 165 | else |
| 166 | log " Server: nothing to remove." |
| 167 | fi |
| 168 | |
| 169 | # ── 6. Smoke-test: verify tarball is live ───────────────────────────────────── |
| 170 | |
| 171 | log "[5/5] Verifying $STAGING_URL/releases/muse-${MUSE_VERSION}.tar.gz" |
| 172 | |
| 173 | HTTP=$(curl -sI "$STAGING_URL/releases/muse-${MUSE_VERSION}.tar.gz" \ |
| 174 | | grep -i "^HTTP" | awk '{print $2}') |
| 175 | |
| 176 | if [ "$HTTP" = "200" ]; then |
| 177 | log " ✅ Live at $STAGING_URL/releases/muse-${MUSE_VERSION}.tar.gz" |
| 178 | else |
| 179 | die "Expected HTTP 200, got: $HTTP" |
| 180 | fi |
| 181 | |
| 182 | # ── 7. Full smoke test ──────────────────────────────────────────────────────── |
| 183 | |
| 184 | log "[6/6] Running smoke test against $STAGING_URL" |
| 185 | bash "$SCRIPT_DIR/smoke_muse.sh" --url "$STAGING_URL" --version "$MUSE_VERSION" |
| 186 | |
| 187 | log "" |
| 188 | log "muse $MUSE_VERSION is live. Install with:" |
| 189 | log " curl -fsSL $STAGING_URL/install.sh | sh" |
File History
2 commits
sha256:1dd27e6d5c24550177b01b0a171e8375c07cf046b549e7683364706b6522d3bc
docs(#139): mark all 11 checklist items resolved, document …
Sonnet 5
12 days ago
sha256:649011bedd713e22f7dca4c4be94bdefbf3b10950d9fc80235928d0b0b823be8
docs: track issue #139 (two-column app-shell refactor) plan…
Sonnet 5
12 days ago