Skip to content

Commit 31316b3

Browse files
mekarpelesMek
authored andcommitted
Streamline deploy.sh
1 parent 6ade322 commit 31316b3

File tree

1 file changed

+67
-13
lines changed

1 file changed

+67
-13
lines changed

scripts/deployment/deploy.sh

Lines changed: 67 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ copy_to_servers() {
168168
}
169169

170170
deploy_olsystem() {
171-
echo "Starting $REPO deployment at $(date)"
171+
echo "[Now] Starting $REPO deployment at $(date)"
172172
echo "Deploying to: $SERVERS"
173173

174174
check_server_access
@@ -231,6 +231,9 @@ deploy_olsystem() {
231231
if [ $CLEANUP -eq 1 ]; then
232232
cleanup "$TMP_DIR"
233233
fi
234+
235+
echo "[Next] Run openlibrary deploy (~12m00 as of 2024-12-09):"
236+
echo "time SERVER_SUFFIX='.us.archive.org' ./scripts/deployment/deploy.sh openlibrary"
234237
}
235238

236239
date_to_timestamp() {
@@ -250,6 +253,7 @@ date_to_timestamp() {
250253
}
251254

252255
deploy_openlibrary() {
256+
echo "[Now] Deploying openlibrary"
253257
COMPOSE_FILE="/opt/openlibrary/compose.yaml:/opt/openlibrary/compose.production.yaml"
254258
TMP_DIR=$(mktemp -d)
255259

@@ -358,30 +362,80 @@ deploy_openlibrary() {
358362
echo "To reboot the servers, please run scripts/deployments/restart_all_servers.sh"
359363

360364
cleanup $TMP_DIR
365+
366+
echo "[Next] Run review aka are_servers_in_sync.sh (~50s as of 2024-12-09):"
367+
echo "time SERVER_SUFFIX='.us.archive.org' ./scripts/deployment/deploy.sh review"
361368
}
362369

363-
# Clone booklending utils
364-
# parallel --quote ssh {1} "echo -e '\n\n{}'; if [ -d /opt/booklending_utils ]; then cd {2} && sudo git pull [email protected]:jake/booklending_utils.git master; fi" ::: $SERVERS ::: /opt/booklending_utils
370+
check_servers_in_sync() {
371+
echo "[Now] Ensuring git repo & docker images in sync across servers (~50s as of 2024-12-09):"
372+
time SERVER_SUFFIX='.us.archive.org' ./scripts/deployment/are_servers_in_sync.sh
373+
echo "[Next] Run restart on all servers (~3m as of 2024-12-09):"
374+
echo "time SERVER_SUFFIX='.us.archive.org' ./scripts/deployment/deploy.sh finalize"
375+
}
365376

377+
clone_booklending_utils() {
378+
echo "[Info] In case you need to clone booklending utils manually..."
379+
echo "parallel --quote ssh {1} \"echo -e '\\\\n\\\\n{}'; if [ -d /opt/booklending_utils ]; then cd {2} && sudo git pull [email protected]:jake/booklending_utils.git master; fi\" ::: \$SERVERS ::: /opt/booklending_utils"
380+
read -p "[Now] Clone booklending utils? (usually not necessary) [N/y]" answer
381+
answer=${answer:-N}
382+
if [[ "$answer" =~ ^[Yy]$ ]]; then
383+
parallel --quote ssh {1} "echo -e '\n\n{}'; if [ -d /opt/booklending_utils ]; then cd {2} && sudo git pull [email protected]:jake/booklending_utils.git master; fi" ::: $SERVERS ::: /opt/booklending_utils
384+
fi
385+
}
366386

367-
# Supports:
368-
# - deploy.sh olsystem
369-
# - deploy.sh openlibrary
387+
# See deployment documentation at https://github.com/internetarchive/olsystem/wiki/Deployments
370388

371-
if [ "$1" == "announce" ]; then
372-
echo "@here, Open Library is in the process of deploying its weekly release. See what's changed: $RELEASE_DIFF_URL"
373-
elif [ "$1" == "olsystem" ]; then
389+
if [ "$1" == "olsystem" ]; then
374390
deploy_olsystem
375391
elif [ "$1" == "openlibrary" ]; then
376392
deploy_openlibrary
393+
clone_booklending_utils
394+
395+
if [ "$2" == "review" ]; then
396+
check_servers_in_sync
397+
else
398+
read -p "[Now] Run review audit of servers now? [Y/n]" answer
399+
answer=${answer:-Y}
400+
if [[ "$answer" =~ ^[Yy]$ ]]; then
401+
time SERVER_SUFFIX='.us.archive.org' ./scripts/deployment/deploy.sh review
402+
fi
403+
fi
377404
elif [ "$1" == "review" ]; then
378-
# Ensure all the git repos, docker images are in sync across all servers (~50s as of 2024-12-09)
379-
time SERVER_SUFFIX='.us.archive.org' ./scripts/deployment/are_servers_in_sync.sh
405+
check_servers_in_sync
380406
elif [ "$1" == "finalize" ]; then
381-
# Restart things -- keep an eye on sentry/grafana (~3m as of 2024-12-09)
407+
echo "[Now] Rebuilding & restarting services, keep an eye on sentry/grafana (~3m as of 2024-12-09)"
408+
echo "- Sentry: https://sentry.archive.org/organizations/ia-ux/issues/?project=7&statsPeriod=1d"
409+
echo "- Grafana: https://grafana.us.archive.org/d/000000176/open-library-dev?orgId=1&refresh=1m&from=now-6h&to=now"
382410
time SERVER_SUFFIX='.us.archive.org' ./scripts/deployment/restart_servers.sh
411+
echo "[Now] Deploy complete, announce in #openlibrary-g, #openlibrary, and #open-librarians-g:"
383412
echo "The Open Library weekly deploy is now complete. Please let us know @here if anything seems broken or delightful!"
384413
else
385-
echo "Usage: $0 [olsystem|openlibrary]"
414+
echo "Usage: $0 [announce|olsystem|openlibrary|review|finalize]"
415+
416+
# Pull openlibrary before continuing so we have latest deploy.sh
417+
read -p "[Now] Switching to main branch and pulling latest changes? [Y/n]..." answer
418+
answer=${answer:-Y}
419+
if [[ "$answer" =~ ^[Yy]$ ]]; then
420+
git checkout master
421+
git pull https://github.com/internetarchive/openlibrary.git master
422+
fi
423+
424+
# Announce the deploy
425+
echo "[Now] Announce deploy to #openlibrary-g, #openlibrary, and #open-librarians-g:"
426+
echo "@here, Open Library is in the process of deploying its weekly release. See what's changed: $RELEASE_DIFF_URL"
427+
read -p "Once complete, press Enter to continue..."
428+
429+
echo "[Now] Kick off a fresh docker build: https://github.com/internetarchive/openlibrary/actions/workflows/olbase.yaml"
430+
read -p "Once complete, press Enter to continue..."
431+
432+
echo "[Next] Run olsystem deploy (~2m30 as of 2024-12-06):"
433+
echo "time SERVER_SUFFIX='.us.archive.org' ./scripts/deployment/deploy.sh olsystem"
434+
read -p "[Now] Run olsystem deploy now? [Y/n]..." answer
435+
answer=${answer:-N}
436+
if [[ "$answer" =~ ^[Yy]$ ]]; then
437+
time SERVER_SUFFIX='.us.archive.org' ./scripts/deployment/deploy.sh olsystem
438+
fi
439+
386440
exit 1
387441
fi

0 commit comments

Comments
 (0)