@@ -23,12 +23,14 @@ set -e
2323
2424# See https://github.com/internetarchive/openlibrary/wiki/Deployment-Scratchpad
2525SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
26- SERVER_SUFFIX=${SERVER_SUFFIX:- " " }
26+ SERVER_SUFFIX=${SERVER_SUFFIX:- " .us.archive.org " }
2727SERVER_NAMES=${SERVERS:- " ol-home0 ol-covers0 ol-web0 ol-web1 ol-web2 ol-www0" }
2828SERVERS=$( echo $SERVER_NAMES | sed " s/ /$SERVER_SUFFIX /g" ) $SERVER_SUFFIX
2929KILL_CRON=${KILL_CRON:- " " }
3030LATEST_TAG=$( curl -s https://api.github.com/repos/internetarchive/openlibrary/releases/latest | sed -n ' s/.*"tag_name": "\([^"]*\)".*/\1/p' )
3131RELEASE_DIFF_URL=" https://github.com/internetarchive/openlibrary/compare/$LATEST_TAG ...master"
32+ COMPOSE_FILE=" /opt/openlibrary/compose.yaml:/opt/openlibrary/compose.production.yaml"
33+ DEPLOY_TAG=" deploy-$( date +%Y-%m-%d-at-%H-%M) "
3234
3335# Install GNU parallel if not there
3436# Check is GNU-specific because some hosts had something else called parallel installed
@@ -255,7 +257,6 @@ date_to_timestamp() {
255257}
256258
257259tag_deploy () {
258- DEPLOY_TAG=" deploy-$( date +%Y-%m-%d-at-%H-%M) "
259260 OL_REPO=" $1 "
260261 # Check if tag does NOT exist
261262 if ! git -C " $OL_REPO " rev-parse " $DEPLOY_TAG " > /dev/null 2>&1 ; then
@@ -300,7 +301,6 @@ check_olbase_image_up_to_date() {
300301
301302deploy_openlibrary () {
302303 echo " [Now] Deploying openlibrary"
303- COMPOSE_FILE=" /opt/openlibrary/compose.yaml:/opt/openlibrary/compose.production.yaml"
304304 TMP_DIR=$( mktemp -d)
305305
306306 cd $TMP_DIR
@@ -355,23 +355,9 @@ deploy_openlibrary() {
355355 fi
356356
357357 echo " Pull the latest docker images..."
358- # We need to fetch by the exact image sha, since the registry mirror on the prod servers
359- # has a cache which means fetching the `latest` image could be stale.
360- # Assert latest docker image is up-to-date
361- IMAGE_META=$( curl -s https://hub.docker.com/v2/repositories/openlibrary/olbase/tags/latest)
362- OLBASE_DIGEST=$( echo $IMAGE_META | jq -r ' .images[0].digest' )
363- for SERVER_NAME in $SERVER_NAMES ; do
364- SERVER=" $SERVER_NAME$SERVER_SUFFIX "
365358
366- echo " $SERVER_NAME ... "
367- ssh -t $SERVER "
368- set -e;
369- docker pull openlibrary/olbase@$OLBASE_DIGEST
370- echo 'FROM openlibrary/olbase@$OLBASE_DIGEST ' | docker build --tag openlibrary/olbase:latest -f - .
371- COMPOSE_FILE='$COMPOSE_FILE ' HOSTNAME=\$ HOSTNAME docker compose --profile $SERVER_NAME pull
372- source /opt/olsystem/bin/build_env.sh;
373- COMPOSE_FILE='$COMPOSE_FILE ' HOSTNAME=\$ HOSTNAME docker compose --profile $SERVER_NAME build
374- " & > /dev/null &
359+ for SERVER_NAME in $SERVER_NAMES ; do
360+ deploy_image " $SERVER_NAME "
375361 done
376362
377363 wait
@@ -389,6 +375,37 @@ deploy_openlibrary() {
389375 echo " time SERVER_SUFFIX='$SERVER_SUFFIX ' ./scripts/deployment/deploy.sh review"
390376}
391377
378+ deploy_image () {
379+ local SERVER_NAME=$1
380+ local SERVER=" ${SERVER_NAME}${SERVER_SUFFIX} "
381+
382+ # Lazy-fetch OLBASE_DIGEST if not set
383+ if [ -z " $OLBASE_DIGEST " ]; then
384+ # We need to fetch by the exact image sha, since the registry mirror on the prod servers
385+ # has a cache which means fetching the `latest` image could be stale.
386+ # Assert latest docker image is up-to-date
387+ echo " Fetching OLBASE_DIGEST ..."
388+ IMAGE_META=$( curl -s https://hub.docker.com/v2/repositories/openlibrary/olbase/tags/latest)
389+ OLBASE_DIGEST=$( echo " $IMAGE_META " | jq -r ' .images[0].digest' )
390+ fi
391+
392+ echo " Pulling docker image $OLBASE_DIGEST to $SERVER_NAME ... "
393+
394+ echo $SERVER
395+ echo $OLBASE_DIGEST
396+ echo $IMAGE_META
397+ echo $COMPOSE_FILE
398+ ssh -t " $SERVER " "
399+ set -e;
400+ docker pull openlibrary/olbase@${OLBASE_DIGEST}
401+ echo 'FROM openlibrary/olbase@${OLBASE_DIGEST} ' | docker build --tag openlibrary/olbase:latest -f - .
402+ COMPOSE_FILE='${COMPOSE_FILE} ' HOSTNAME=\$ HOSTNAME docker compose --profile ${SERVER_NAME} pull
403+ source /opt/olsystem/bin/build_env.sh;
404+ COMPOSE_FILE='${COMPOSE_FILE} ' HOSTNAME=\$ HOSTNAME docker compose --profile ${SERVER_NAME} build
405+ " & > /dev/null &
406+ }
407+
408+
392409check_servers_in_sync () {
393410 echo " [Now] Ensuring git repo & docker images in sync across servers (~50s as of 2024-12-09):"
394411 time SERVER_SUFFIX=" $SERVER_SUFFIX " " $SCRIPT_DIR /are_servers_in_sync.sh"
@@ -483,7 +500,7 @@ deploy_wizard() {
483500 read -p " [Now] Run olsystem deploy now? [Y/n]..." answer
484501 answer=${answer:- Y}
485502 if [[ " $answer " =~ ^[Yy]$ ]]; then
486- time olsystem
503+ time deploy_olsystem
487504 fi
488505 echo " "
489506
@@ -492,7 +509,7 @@ deploy_wizard() {
492509 done
493510 echo " "
494511
495- read -p " [Info] Skipping clone_booklending_utils, run manually if needed" answer
512+ read -p " [Info] Skipping clone_booklending_utils, run manually if needed. Press Enter to continue... " answer
496513 echo " "
497514
498515 read -p " [Now] Run openlibrary deploy & audit now? [N/y]..." answer
@@ -523,6 +540,8 @@ elif [ "$1" == "openlibrary" ]; then
523540 if [ " $2 " == " --review" ]; then
524541 check_servers_in_sync
525542 fi
543+ elif [ " $1 " == " image" ]; then
544+ deploy_image $2
526545elif [ " $1 " == " review" ]; then
527546 check_servers_in_sync
528547elif [ " $1 " == " rebuild" ]; then
0 commit comments