Last active
January 16, 2020 09:28
-
-
Save kirs/8e73fef83db2fd3dd8541df04b5ba3d4 to your computer and use it in GitHub Desktop.
Docker snapshot (CRIU) experiments with Rails app and Redmine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# The script to run actual benchmark | |
set -e -x | |
IMAGE=redmine:latest | |
CHECKPOINT_NAME=checkpoint-redmine | |
GCS_BUCKET=kirs-criu | |
if [ -z "$REDMINE_DB_MYSQL" ] || [ -z "$REDMINE_DB_USERNAME" ] || [ -z "$REDMINE_DB_PASSWORD" ] then | |
echo "The script requires \$REDMINE_DB_MYSQL, \$REDMINE_DB_USERNAME, \$REDMINE_DB_PASSWORD" | |
echo "For testing purposes, it's advised to create a free tier RDS MySQL instance. Example: REDMINE_DB_MYSQL=database-1.cnoiyz3lhp8n.eu-central-1.rds.amazonaws.com -e REDMINE_DB_USERNAME=admin -e REDMINE_DB_PASSWORD=iimZkc4Un1kI5q2ZWDw8" | |
echo "Remember to prepare the DB schema manually from Redmine migrations!" | |
exit 1 | |
fi | |
echo "Cleaning up" | |
docker kill $(docker inspect --format="{{.Id}}" redmine-donor) || true | |
docker kill $(docker inspect --format="{{.Id}}" redmine-clone) || true | |
docker rm redmine-donor || true | |
docker rm redmine-clone || true | |
rm -rf $CHECKPOINT_NAME/ || true | |
rm -rf $CHECKPOINT_NAME.tar.gz checkpoint.tar.gz || true | |
if [ -z "$SKIP_SNAPSHOT_PREPARE" ]; then | |
docker run --name redmine-donor -p 3000:3000 -d -e REDMINE_DB_MYSQL=$REDMINE_DB_MYSQL -e REDMINE_DB_USERNAME=$REDMINE_DB_USERNAME -e REDMINE_DB_PASSWORD=$REDMINE_DB_PASSWORD -e REDMINE_NO_DB_MIGRATE=1 $IMAGE | |
echo "+++ Waiting for container to boot" | |
time (while ! curl localhost:3000 > /dev/null 2>&1; do : ; done ) | |
echo "+++ Creating a checkpoint" | |
sudo time docker checkpoint create redmine-donor $CHECKPOINT_NAME | |
DONOR_CONTAINER_ID=$(docker inspect --format="{{.Id}}" redmine-donor) | |
echo "+++ Packing the checkpoint" | |
sudo time tar cvzf checkpoint.tar.gz -C /var/lib/docker/containers/$DONOR_CONTAINER_ID/checkpoints . | |
echo "+++ Checkpoint size:" | |
ls -l --block-size=M | |
# Remember to provision GCS write permissions through the Service Account! | |
echo "+++ Uploading the checkpoint:" | |
time gsutil cp checkpoint.tar.gz gs://$GCS_BUCKET/checkpoints-experiment/$CHECKPOINT_NAME.tar.gz | |
sudo rm checkpoint.tar.gz | |
fi | |
echo "+++ Downloading the checkpoint:" | |
time gsutil cp gs://$GCS_BUCKET/checkpoints-experiment/$CHECKPOINT_NAME.tar.gz . | |
echo "+++ Preparing the new container" | |
time docker create --name redmine-clone -p 3000:3000 $IMAGE | |
CLONE_CONTAINER_ID=$(docker inspect --format="{{.Id}}" redmine-clone) | |
echo "+++ Unpacking the checkpoint to clone docker dir:" | |
sudo tar -C /var/lib/docker/containers/$CLONE_CONTAINER_ID/checkpoints -xvf $CHECKPOINT_NAME.tar.gz | |
rm $CHECKPOINT_NAME.tar.gz | |
echo "+++ Launching the clone from the snapshot:" | |
time docker start --checkpoint $CHECKPOINT_NAME redmine-clone | |
curl http://localhost:3000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# The script to prepare edge dependencies | |
set -e -x | |
sudo apt-get update | |
curl -fsSL https://get.docker.com -o get-docker.sh | |
sudo sh get-docker.sh | |
sudo usermod -aG docker $(whoami) | |
rm get-docker.sh | |
sudo apt-get install golang-go -y | |
sudo apt-get install libseccomp-dev build-essential -y | |
mkdir -p ~/go/src/github.com/opencontainers | |
cd ~/go/src/github.com/opencontainers | |
git clone https://github.com/opencontainers/runc.git | |
cd runc | |
make BUILDTAGS='seccomp apparmor' | |
sudo make install | |
runc --version | |
# criu deps | |
sudo apt-get install -y libprotobuf-dev libprotobuf-c0-dev protobuf-c-compiler protobuf-compiler python-protobuf libbsd-dev libcap-dev libnl-3-dev libnet-dev jq | |
sudo apt-get install -y --no-install-recommends asciidoc xmlto | |
sudo apt-get install python-pip -y | |
pip install ipaddress | |
cd ~ | |
git clone https://github.com/checkpoint-restore/criu.git | |
cd criu | |
make | |
sudo make install | |
sudo sh -c "echo '{\"experimental\": true, \"debug\": true}' > /etc/docker/daemon.json" | |
sudo systemctl restart docker | |
sudo mkdir -p /etc/criu | |
sudo sh -c "echo 'tcp-established' > /etc/criu/runc.conf" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment