Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scripts for production deployments #4395

Merged
merged 12 commits into from
Jan 25, 2021
21 changes: 21 additions & 0 deletions scripts/deployment/continue_production_deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

set -o xtrace

# https://github.com/internetarchive/openlibrary/wiki/Deployment-Scratchpad

# This script must be run on each Open Library host to continue a new deployment.

export HOSTNAME="${HOSTNAME:-$HOST}"
if [[ $HOSTNAME != ol-home0.* ]]; then
# ~2 - 4 min
time docker image prune -f
# Decompress the .tar.gz image that was transfered from ol-home0
cd /opt/olimages
# ~4min
time docker load < /opt/olimages/oldev_latest.tar.gz
fi

# Add a git SHA tag to the Docker image to facilitate rapid rollback
echo "FROM oldev:latest" | docker build -t "oldev:$(git rev-parse HEAD)" -
docker image ls
75 changes: 75 additions & 0 deletions scripts/deployment/start_production_deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

set -o xtrace

# https://github.com/internetarchive/openlibrary/wiki/Deployment-Scratchpad

# This script must be run on ol-home0 to start a new deployment.

echo "Starting production deployment at $(date)"
export HOSTNAME="${HOSTNAME:-$HOST}"
if [[ $HOSTNAME != ol-home0.* ]]; then
echo "FATAL: Must only be run on ol-home0" ;
exit 1 ;
fi

# `sudo git pull origin master` the core Open Library repos:
# 1. https://github.com/internetarchive/olsystem
# 2. https://git.archive.org/jake/booklending_utils
# 3. https://github.com/internetarchive/openlibrary
# 4. https://github.com/internetarchive/infogami

### Needed to log into BOOKLENDING_UTILS

REPO_DIRS="/opt/olsystem /opt/booklending_utils /opt/openlibrary /opt/openlibrary/vendor/infogami"
for REPO_DIR in $REPO_DIRS
do
cd $REPO_DIR
sudo git pull origin master
done

# These commands were run once and probably do not need to be repeated
sudo mkdir -p /opt/olimages
sudo chown root:staff /opt/olimages
sudo chmod g+w /opt/olimages
sudo chmod g+s /opt/olimages
docker image prune -f

# Build the oldev Docker production image
cd /opt/openlibrary
export COMPOSE_FILE="docker-compose.yml:docker-compose.production.yml"
time docker-compose build --pull web
docker-compose run -uroot --rm home make i18n

# Compress the image in a .tar.gz file for transfer to other hosts
cd /opt/olimages
time docker save oldev:latest | gzip > oldev_latest.tar.gz

# Transfer the .tar.gz image and four repo dirs to other hosts
SERVERS="ol-covers0 ol-web1 ol-web2"
for SERVER in $SERVERS
do
echo "Starting rsync of oldev_latest.tar.gz to $REMOTE_HOST..."
time rsync -a --no-owner --group --verbose oldev_latest.tar.gz "$SERVER:/opt/olimages/"
if [[ $HOSTNAME == ol-web* ]]; then
REPO_DIRS="/opt/olsystem /opt/booklending_utils /opt/openlibrary /opt/openlibrary/vendor/infogami"
else
REPO_DIRS="/opt/olsystem /opt/openlibrary /opt/openlibrary/vendor/infogami"
fi
for REPO_DIR in $REPO_DIRS
do
echo "Starting rsync of $REPO_DIR to $SERVER..."
time rsync -a -r --no-owner --group --verbose $REPO_DIR "$SERVER:$REPO_DIR"
done
echo -e "Finished rsync to $SERVER...\n"
done

# Uncompress and tag oldev_latest.tar.gz that we have rsynced over
bash /opt/openlibrary/scripts/deployment/continue_production_deployment.sh
for SERVER in $SERVERS
do
ssh $SERVER /opt/openlibrary/scripts/deployment/continue_production_deployment.sh
done

echo "Finished production deployment at $(date)"
echo "To reboot the servers, please run scripts/deployments/restart_all_servers.sh"