@@ -13,15 +13,18 @@ if [[ -z "$1" || "$1" == "--help" ]]; then
1313 echo " PATCH_ON=host|container Whether to apply the patch on the host or inside"
1414 echo " the container."
1515 echo " Default: container unless patching www nginx changes"
16- echo " CONTAINER=container_name Default: openlibrary-web-1 for ol-web hosts,"
17- echo " openlibrary-web_nginx-1 for ol-www0"
16+ echo " SERVICE=container_name Default: web for ol-web hosts, web_nginx for ol-www0"
1817 echo " APPLY_OPTIONS='' Options to pass to git apply. E.g. use -R to"
1918 echo " un-apply a patch. See 'git apply --help' for options."
19+ echo " RESET='' If 'true', resets the container before applying the patch."
2020 exit 1
2121fi
2222
23- PR_NUMBER=$1
24- PATCH_URL=" https://patch-diff.githubusercontent.com/raw/internetarchive/openlibrary/pull/${PR_NUMBER} .diff"
23+ if [[ " $1 " == https* ]]; then
24+ PATCH_URL=" $1 "
25+ else
26+ PATCH_URL=" https://patch-diff.githubusercontent.com/raw/internetarchive/openlibrary/pull/${1} .diff"
27+ fi
2528echo " Note: Patch Deploys cannot rebuild js/css"
2629echo
2730
@@ -30,21 +33,21 @@ SERVERS=${SERVERS:-"ol-web0 ol-web1 ol-web2"}
3033PROXY=" http://http-proxy.us.archive.org:8080"
3134APPLY_OPTIONS=${APPLY_OPTIONS:- " " }
3235
33- echo " Applying patch # ${PR_NUMBER } to ${SERVERS} :"
36+ echo " Applying patch ${PATCH_URL } to ${SERVERS} :"
3437
3538for host in $SERVERS ; do
3639 # Determine default container name based on host
3740 if [[ " $host " == " ol-www0" ]]; then
38- CONTAINER =${CONTAINER :- " openlibrary- web_nginx-1 " }
39- if [[ " $CONTAINER " == " openlibrary- web_nginx-1 " ]]; then
41+ SERVICE =${SERVICE :- " web_nginx" }
42+ if [[ " $SERVICE " == " web_nginx" ]]; then
4043 # If deploying nginx configs, must apply only to host
4144 PATCH_ON=${PATCH_ON:- host}
4245 else
4346 PATCH_ON=${PATCH_ON:- container}
4447 fi
4548 else
4649 PATCH_ON=${PATCH_ON:- container}
47- CONTAINER =${CONTAINER :- " openlibrary- web-1 " }
50+ SERVICE =${SERVICE :- " web" }
4851 fi
4952
5053 TMP_OUTPUT_FILE=$( mktemp)
@@ -58,20 +61,49 @@ for host in $SERVERS; do
5861 " > $TMP_OUTPUT_FILE
5962 STATUS=$?
6063 else
61- echo -n " $host $CONTAINER ... "
64+ echo -n " $host / $SERVICE ..."
65+
66+ if [ " $RESET " == " true" ]; then
67+ echo -n " recreating ... "
68+ ssh ${host} .us.archive.org "
69+ export COMPOSE_FILE='/opt/openlibrary/compose.yaml:/opt/openlibrary/compose.production.yaml'
70+ export HOSTNAME=\$ HOSTNAME
71+ docker compose up -d --no-deps --force-recreate ${SERVICE} 2>&1
72+ " > $TMP_OUTPUT_FILE
73+
74+ if [ $? -eq 0 ]; then
75+ echo -n ' ✓'
76+ rm $TMP_OUTPUT_FILE
77+ else
78+ echo -n ' ✗'
79+ cat $TMP_OUTPUT_FILE
80+ rm $TMP_OUTPUT_FILE
81+ exit 1
82+ fi
83+ fi
84+
85+ echo -n " applying patch ... "
6286 ssh ${host} .us.archive.org "
63- docker exec ${CONTAINER} bash -c '
87+ export COMPOSE_FILE='/opt/openlibrary/compose.yaml:/opt/openlibrary/compose.production.yaml'
88+ export HOSTNAME=\$ HOSTNAME
89+ docker compose exec ${SERVICE} bash -c '
6490 HTTPS_PROXY=${PROXY} curl -sL ${PATCH_URL} | git apply $APPLY_OPTIONS
6591 ' 2>&1
6692 " > $TMP_OUTPUT_FILE
93+
6794 STATUS=$?
6895 fi
6996
7097 if [ $STATUS -eq 0 ]; then
7198 rm $TMP_OUTPUT_FILE
7299
73- echo -n ' ✓. Restarting ... '
74- ssh ${host} .us.archive.org " docker restart ${CONTAINER} 2>&1" > $TMP_OUTPUT_FILE
100+ echo -n ' ✓ restarting ... '
101+ ssh ${host} .us.archive.org "
102+ export COMPOSE_FILE='/opt/openlibrary/compose.yaml:/opt/openlibrary/compose.production.yaml'
103+ export HOSTNAME=\$ HOSTNAME
104+ docker compose restart ${SERVICE} 2>&1
105+ " > $TMP_OUTPUT_FILE
106+
75107 if [ $? -eq 0 ]; then
76108 echo ' ✓'
77109 rm $TMP_OUTPUT_FILE
0 commit comments