aws-provision.sh
bash
sha256:34035d72cef530c1ab9d6a6f53be18d803dde705fc3157617d70352a96d0747b
Merge branch 'fix/wire-push-external-parent-manifest' into dev
Human
9 days ago
| 1 | #!/usr/bin/env bash |
| 2 | # Run this locally (after installing AWS CLI and running `aws configure`). |
| 3 | # Creates an EC2 t3.small, security group, key pair, and Elastic IP for musehub.ai. |
| 4 | # |
| 5 | # Prerequisites: |
| 6 | # brew install awscli |
| 7 | # aws configure (enter your Access Key ID, Secret, region=us-east-1, output=json) |
| 8 | # |
| 9 | # Usage: |
| 10 | # chmod +x deploy/aws-provision.sh |
| 11 | # ./deploy/aws-provision.sh |
| 12 | |
| 13 | set -euo pipefail |
| 14 | |
| 15 | # Suppress AWS CLI pager entirely — prevents the script from blocking on `less` |
| 16 | export AWS_PAGER="" |
| 17 | |
| 18 | REGION="us-east-1" |
| 19 | AMI_ID="ami-0c7217cdde317cfec" # Ubuntu 22.04 LTS (us-east-1, 2024) |
| 20 | INSTANCE_TYPE="t3.small" |
| 21 | KEY_NAME="musehub-key" |
| 22 | SG_NAME="musehub-sg" |
| 23 | SG_ID="sg-05815872537fcfe76" # Already created — skip re-creation |
| 24 | INSTANCE_NAME="musehub-prod" |
| 25 | |
| 26 | # ── Key pair ────────────────────────────────────────────────────────────────── |
| 27 | if [ -f ~/.ssh/${KEY_NAME}.pem ]; then |
| 28 | echo "==> Key pair already exists at ~/.ssh/${KEY_NAME}.pem, skipping" |
| 29 | else |
| 30 | echo "==> Creating key pair: $KEY_NAME" |
| 31 | aws ec2 create-key-pair \ |
| 32 | --region "$REGION" \ |
| 33 | --key-name "$KEY_NAME" \ |
| 34 | --query 'KeyMaterial' \ |
| 35 | --output text > ~/.ssh/${KEY_NAME}.pem |
| 36 | chmod 400 ~/.ssh/${KEY_NAME}.pem |
| 37 | echo " Key saved to ~/.ssh/${KEY_NAME}.pem" |
| 38 | fi |
| 39 | |
| 40 | # ── Current IP ──────────────────────────────────────────────────────────────── |
| 41 | echo "==> Getting your current public IP..." |
| 42 | MY_IP=$(curl -s https://checkip.amazonaws.com) |
| 43 | echo " Your IP: $MY_IP" |
| 44 | |
| 45 | # ── Security group ──────────────────────────────────────────────────────────── |
| 46 | echo "==> Using existing security group: $SG_ID" |
| 47 | |
| 48 | # ── Inbound rules (idempotent — ignore duplicate-rule errors) ───────────────── |
| 49 | echo "==> Adding inbound rules (SSH / HTTP / HTTPS)..." |
| 50 | |
| 51 | add_rule() { |
| 52 | local port=$1 cidr=$2 |
| 53 | aws ec2 authorize-security-group-ingress \ |
| 54 | --region "$REGION" \ |
| 55 | --group-id "$SG_ID" \ |
| 56 | --protocol tcp --port "$port" --cidr "$cidr" \ |
| 57 | --output text > /dev/null 2>&1 \ |
| 58 | && echo " Port $port ($cidr) — added" \ |
| 59 | || echo " Port $port ($cidr) — already exists, skipping" |
| 60 | } |
| 61 | |
| 62 | add_rule 22 "${MY_IP}/32" |
| 63 | add_rule 80 "0.0.0.0/0" |
| 64 | add_rule 443 "0.0.0.0/0" |
| 65 | |
| 66 | # ── EC2 instance ────────────────────────────────────────────────────────────── |
| 67 | # Check if instance already exists |
| 68 | EXISTING=$(aws ec2 describe-instances \ |
| 69 | --region "$REGION" \ |
| 70 | --filters "Name=tag:Name,Values=$INSTANCE_NAME" "Name=instance-state-name,Values=pending,running,stopped" \ |
| 71 | --query 'Reservations[0].Instances[0].InstanceId' \ |
| 72 | --output text) |
| 73 | |
| 74 | if [ "$EXISTING" != "None" ] && [ -n "$EXISTING" ]; then |
| 75 | echo "==> Instance already exists: $EXISTING" |
| 76 | INSTANCE_ID="$EXISTING" |
| 77 | else |
| 78 | echo "==> Launching EC2 instance..." |
| 79 | INSTANCE_ID=$(aws ec2 run-instances \ |
| 80 | --region "$REGION" \ |
| 81 | --image-id "$AMI_ID" \ |
| 82 | --instance-type "$INSTANCE_TYPE" \ |
| 83 | --key-name "$KEY_NAME" \ |
| 84 | --security-group-ids "$SG_ID" \ |
| 85 | --block-device-mappings '[{"DeviceName":"/dev/sda1","Ebs":{"VolumeSize":20,"VolumeType":"gp3","DeleteOnTermination":true}}]' \ |
| 86 | --tag-specifications "ResourceType=instance,Tags=[{Key=Name,Value=$INSTANCE_NAME}]" \ |
| 87 | --query 'Instances[0].InstanceId' \ |
| 88 | --output text) |
| 89 | echo " Instance ID: $INSTANCE_ID" |
| 90 | fi |
| 91 | |
| 92 | echo "==> Waiting for instance to be running..." |
| 93 | aws ec2 wait instance-running --region "$REGION" --instance-ids "$INSTANCE_ID" |
| 94 | echo " Instance is running" |
| 95 | |
| 96 | # ── Elastic IP ──────────────────────────────────────────────────────────────── |
| 97 | # Check if already associated |
| 98 | EXISTING_EIP=$(aws ec2 describe-addresses \ |
| 99 | --region "$REGION" \ |
| 100 | --filters "Name=instance-id,Values=$INSTANCE_ID" \ |
| 101 | --query 'Addresses[0].PublicIp' \ |
| 102 | --output text) |
| 103 | |
| 104 | if [ "$EXISTING_EIP" != "None" ] && [ -n "$EXISTING_EIP" ]; then |
| 105 | echo "==> Elastic IP already associated: $EXISTING_EIP" |
| 106 | PUBLIC_IP="$EXISTING_EIP" |
| 107 | else |
| 108 | echo "==> Allocating Elastic IP..." |
| 109 | ALLOC_ID=$(aws ec2 allocate-address \ |
| 110 | --region "$REGION" \ |
| 111 | --domain vpc \ |
| 112 | --query 'AllocationId' \ |
| 113 | --output text) |
| 114 | echo " Allocation ID: $ALLOC_ID" |
| 115 | |
| 116 | echo "==> Associating Elastic IP with instance..." |
| 117 | aws ec2 associate-address \ |
| 118 | --region "$REGION" \ |
| 119 | --instance-id "$INSTANCE_ID" \ |
| 120 | --allocation-id "$ALLOC_ID" \ |
| 121 | --output text > /dev/null |
| 122 | |
| 123 | PUBLIC_IP=$(aws ec2 describe-addresses \ |
| 124 | --region "$REGION" \ |
| 125 | --allocation-ids "$ALLOC_ID" \ |
| 126 | --query 'Addresses[0].PublicIp' \ |
| 127 | --output text) |
| 128 | fi |
| 129 | |
| 130 | echo "" |
| 131 | echo "============================================================" |
| 132 | echo " DONE. Your EC2 instance is ready." |
| 133 | echo "============================================================" |
| 134 | echo " Instance ID : $INSTANCE_ID" |
| 135 | echo " Elastic IP : $PUBLIC_IP" |
| 136 | echo " Key file : ~/.ssh/${KEY_NAME}.pem" |
| 137 | echo "" |
| 138 | echo " DNS records to add at Namecheap (Advanced DNS tab):" |
| 139 | echo " ┌──────────┬──────────┬────────────────┬───────────┐" |
| 140 | echo " │ Type │ Host │ Value │ TTL │" |
| 141 | echo " ├──────────┼──────────┼────────────────┼───────────┤" |
| 142 | echo " │ A Record │ @ │ $PUBLIC_IP │ Automatic │" |
| 143 | echo " │ A Record │ www │ $PUBLIC_IP │ Automatic │" |
| 144 | echo " └──────────┴──────────┴────────────────┴───────────┘" |
| 145 | echo " Also DELETE the existing TXT record (the SPF one)." |
| 146 | echo "" |
| 147 | echo " Verify propagation: dig musehub.ai +short" |
| 148 | echo "" |
| 149 | echo " SSH into the server:" |
| 150 | echo " ssh -i ~/.ssh/${KEY_NAME}.pem ubuntu@$PUBLIC_IP" |
| 151 | echo "" |
| 152 | echo " Then run: bash /opt/musehub/deploy/setup-ec2.sh" |
| 153 | echo "============================================================" |
File History
14 commits
sha256:34035d72cef530c1ab9d6a6f53be18d803dde705fc3157617d70352a96d0747b
Merge branch 'fix/wire-push-external-parent-manifest' into dev
Human
9 days ago
sha256:fc04e4cae9e1774d6a21b65c45daeed0e6787eb581d13aa1b03bfe9384a34226
Merge branch 'fix/two-column-scroll-layout' into dev
Human
9 days ago
sha256:408916fc5973ba59c6e4eebaa80ebdcc801c0a63205651e25009d11548f79454
chore: bump version to 0.2.0.dev2 — nightly.2, matching muse
Sonnet 4.6
patch
11 days ago
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
⚠
29 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
34 days ago
sha256:24a7d47486ebc4ebd1832830580e177ec6f877b48dced8c000e198cdec4ce9d6
Merge 'task/bump-version-rc12' into 'dev' — proposal: Bump …
Human
35 days ago
sha256:b9ff931d147e0114a1f17060f415b89ed551c170a91ff226c70437aa5c85f9ee
Merge 'task/bump-version-rc12' into 'dev' — proposal: Bump …
Human
35 days ago
sha256:d1122d21e73471879b460037b22c0b50fded7c423444a176f248428f75dac39c
Merge 'task/fix-issue-pagination-cursor' into 'dev' — propo…
Human
35 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