Skip to content

Commit 6986dc6

Browse files
mekarpelesMek
authored andcommitted
improve flow
1 parent 1a184c2 commit 6986dc6

File tree

1 file changed

+49
-26
lines changed

1 file changed

+49
-26
lines changed

scripts/deployment/deploy.sh

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,6 @@ deploy_olsystem() {
236236
# Present follow-up options
237237
echo "[Next] Run openlibrary deploy (~12m00 as of 2024-12-09):"
238238
echo "time SERVER_SUFFIX='.us.archive.org' ./scripts/deployment/deploy.sh openlibrary"
239-
240-
read -p "[Now] Run openlibrary deploy & audit now? [Y/n]..." answer
241-
answer=${answer:-Y}
242-
if [[ "$answer" =~ ^[Yy]$ ]]; then
243-
time SERVER_SUFFIX='.us.archive.org' "$SCRIPT_DIR/deploy.sh" openlibrary review
244-
fi
245239
}
246240

247241
date_to_timestamp() {
@@ -258,8 +252,6 @@ date_to_timestamp() {
258252
else
259253
date -d "$1" +%s
260254
fi
261-
262-
read -p "[Now] Run olsystem deploy now? [Y/n]..." answer
263255
}
264256

265257
tag_deploy() {
@@ -288,6 +280,33 @@ tag_deploy() {
288280
git -C openlibrary push -f [email protected]:internetarchive/openlibrary.git production
289281
}
290282

283+
check_olbase_image_up_to_date() {
284+
echo "[Now] Checking if Docker image is up-to-date"
285+
286+
# Get latest commit timestamp from GitHub API
287+
GITHUB_COMMIT_API="https://api.github.com/repos/internetarchive/openlibrary/commits/master"
288+
GIT_LAST_UPDATED=$(curl -s "$GITHUB_COMMIT_API" | jq -r '.commit.committer.date')
289+
echo "Latest Git commit: $GIT_LAST_UPDATED"
290+
291+
# Get latest Docker image timestamp from Docker Hub
292+
IMAGE_META=$(curl -s https://hub.docker.com/v2/repositories/openlibrary/olbase/tags/latest)
293+
IMAGE_LAST_UPDATED=$(echo "$IMAGE_META" | jq -r '.last_updated')
294+
echo "Latest Docker image: $IMAGE_LAST_UPDATED"
295+
296+
# Convert to timestamps
297+
GIT_LAST_UPDATED_TS=$(date_to_timestamp "$GIT_LAST_UPDATED")
298+
IMAGE_LAST_UPDATED_TS=$(date_to_timestamp "$IMAGE_LAST_UPDATED")
299+
300+
if [ "$GIT_LAST_UPDATED_TS" -gt "$IMAGE_LAST_UPDATED_TS" ]; then
301+
echo "✗ Docker image is NOT up-to-date."
302+
echo -e "[Now] Manage docker image build status at: https://github.com/internetarchive/openlibrary/actions/workflows/olbase.yaml"
303+
return 1
304+
else
305+
echo "✓ Docker image is up-to-date."
306+
return 0
307+
fi
308+
}
309+
291310
deploy_openlibrary() {
292311
echo "[Now] Deploying openlibrary"
293312
COMPOSE_FILE="/opt/openlibrary/compose.yaml:/opt/openlibrary/compose.production.yaml"
@@ -388,11 +407,11 @@ deploy_openlibrary() {
388407
wait
389408
echo " ... Done ✓"
390409

410+
tag_deploy
411+
391412
echo "Finished production deployment at $(date)"
392413
echo "To reboot the servers, please run scripts/deployments/restart_all_servers.sh"
393414

394-
tag_deploy
395-
396415
cleanup $TMP_DIR
397416

398417
echo "[Info] Skipping booklending utils; see \`deploy.sh utils\`"
@@ -405,11 +424,6 @@ check_servers_in_sync() {
405424
time SERVER_SUFFIX='.us.archive.org' "$SCRIPT_DIR/are_servers_in_sync.sh"
406425
echo "[Next] Run restart on all servers (~3m as of 2024-12-09):"
407426
echo "time SERVER_SUFFIX='.us.archive.org' ./scripts/deployment/deploy.sh finalize"
408-
read -p "[Now] Restart services and finalize deploy now? [N/y]..." answer
409-
answer=${answer:-N}
410-
if [[ "$answer" =~ ^[Yy]$ ]]; then
411-
time SERVER_SUFFIX='.us.archive.org' "$SCRIPT_DIR/deploy.sh" finalize
412-
fi
413427
}
414428

415429
clone_booklending_utils() {
@@ -437,15 +451,8 @@ if [ "$1" == "olsystem" ]; then
437451
deploy_olsystem
438452
elif [ "$1" == "openlibrary" ]; then
439453
deploy_openlibrary
440-
441454
if [ "$2" == "review" ]; then
442455
check_servers_in_sync
443-
else
444-
read -p "[Now] Run review audit of servers now? [Y/n]" answer
445-
answer=${answer:-Y}
446-
if [[ "$answer" =~ ^[Yy]$ ]]; then
447-
time SERVER_SUFFIX='.us.archive.org' "$SCRIPT_DIR/deploy.sh" review
448-
fi
449456
fi
450457
elif [ "$1" == "utils" ]; then
451458
clone_booklending_utils
@@ -471,18 +478,34 @@ else
471478
echo "@here, Open Library is in the process of deploying its weekly release. See what's changed: $RELEASE_DIFF_URL"
472479
read -p "Once announced, press Enter to continue..."
473480

474-
# Dockerhub workflow build
475-
echo "[Now] Start a fresh docker build: https://github.com/internetarchive/openlibrary/actions/workflows/olbase.yaml"
476-
read -p "Once built, press Enter to continue..."
481+
if ! check_olbase_image_up_to_date; then
482+
# Dockerhub workflow build
483+
read -p "Once you've clicked 'Run workflow', press Enter to continue..."
484+
fi
477485

478486
# Deploy olsystem
479487
echo "[Next] Run olsystem deploy (~2m30 as of 2024-12-06):"
480488
echo "time SERVER_SUFFIX='.us.archive.org' ./scripts/deployment/deploy.sh olsystem"
481489
read -p "[Now] Run olsystem deploy now? [Y/n]..." answer
482-
answer=${answer:-N}
490+
answer=${answer:-Y}
483491
if [[ "$answer" =~ ^[Yy]$ ]]; then
484492
time SERVER_SUFFIX='.us.archive.org' "$SCRIPT_DIR/deploy.sh" olsystem
485493
fi
486494

495+
until check_olbase_image_up_to_date; do
496+
read -p "Once built, press Enter to continue..."
497+
done
498+
499+
read -p "[Now] Run openlibrary deploy & audit now? [N/y]..." answer
500+
answer=${answer:-Y}
501+
if [[ "$answer" =~ ^[Yy]$ ]]; then
502+
time SERVER_SUFFIX='.us.archive.org' "$SCRIPT_DIR/deploy.sh" openlibrary review
503+
fi
504+
505+
read -p "[Now] Restart services and finalize deploy now? [N/y]..." answer
506+
answer=${answer:-N}
507+
if [[ "$answer" =~ ^[Yy]$ ]]; then
508+
time SERVER_SUFFIX='.us.archive.org' "$SCRIPT_DIR/deploy.sh" finalize
509+
fi
487510
exit 1
488511
fi

0 commit comments

Comments
 (0)