Adam Sadovsky | 62e37f3 | 2014-10-23 18:14:20 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Adam Sadovsky | 78f2245 | 2014-10-23 18:50:04 -0700 | [diff] [blame] | 3 | # Script to rebuild and deploy compilerd and the Docker image (builder) to the |
| 4 | # playground backends. |
Adam Sadovsky | 62e37f3 | 2014-10-23 18:14:20 -0700 | [diff] [blame] | 5 | # |
| 6 | # Usage: |
Adam Sadovsky | 78f2245 | 2014-10-23 18:50:04 -0700 | [diff] [blame] | 7 | # gcutil ssh --project google.com:veyron playground-master |
| 8 | # sudo su - veyron |
Ivan Pilat | ddb6191 | 2014-12-29 21:16:23 -0800 | [diff] [blame] | 9 | # v23 update |
Ivan Pilat | 153037f | 2015-02-02 20:13:50 -0800 | [diff] [blame] | 10 | # bash $VANADIUM_ROOT/release/projects/playground/go/src/playground/compilerd/update.sh |
Adam Sadovsky | 62e37f3 | 2014-10-23 18:14:20 -0700 | [diff] [blame] | 11 | |
| 12 | set -e |
Adam Sadovsky | 78f2245 | 2014-10-23 18:50:04 -0700 | [diff] [blame] | 13 | set -u |
| 14 | |
| 15 | readonly DATE=$(date +"%Y%m%d-%H%M%S") |
Adam Sadovsky | 62e37f3 | 2014-10-23 18:14:20 -0700 | [diff] [blame] | 16 | readonly DISK="pg-data-${DATE}" |
| 17 | |
| 18 | function unmount() { |
| 19 | sudo umount /mnt |
Adam Sadovsky | 99e1d4f | 2014-10-28 19:20:49 -0700 | [diff] [blame] | 20 | gcloud compute --project "google.com:veyron" instances detach-disk --disk=${DISK} $(hostname) --zone us-central1-a |
Adam Sadovsky | 62e37f3 | 2014-10-23 18:14:20 -0700 | [diff] [blame] | 21 | } |
| 22 | |
Adam Sadovsky | d270f6c | 2014-10-31 11:39:03 -0700 | [diff] [blame] | 23 | trap cleanup INT TERM EXIT |
| 24 | |
Adam Sadovsky | 62e37f3 | 2014-10-23 18:14:20 -0700 | [diff] [blame] | 25 | function cleanup() { |
Adam Sadovsky | d270f6c | 2014-10-31 11:39:03 -0700 | [diff] [blame] | 26 | # Unset the trap so that it doesn't run again on exit. |
| 27 | trap - INT TERM EXIT |
Adam Sadovsky | 62e37f3 | 2014-10-23 18:14:20 -0700 | [diff] [blame] | 28 | if [[ -e /mnt/compilerd ]]; then |
Adam Sadovsky | 78f2245 | 2014-10-23 18:50:04 -0700 | [diff] [blame] | 29 | # The disk is still mounted on the master, which means it's not yet mounted |
| 30 | # on any backends. It's safe to unmount and delete it. |
Adam Sadovsky | 62e37f3 | 2014-10-23 18:14:20 -0700 | [diff] [blame] | 31 | unmount |
Adam Sadovsky | 99e1d4f | 2014-10-28 19:20:49 -0700 | [diff] [blame] | 32 | gcloud compute --project "google.com:veyron" disks delete ${DISK} --zone "us-central1-a" |
Adam Sadovsky | 62e37f3 | 2014-10-23 18:14:20 -0700 | [diff] [blame] | 33 | fi |
Adam Sadovsky | 99e1d4f | 2014-10-28 19:20:49 -0700 | [diff] [blame] | 34 | sudo docker rm ${DISK} &> /dev/null || true |
Adam Sadovsky | 62e37f3 | 2014-10-23 18:14:20 -0700 | [diff] [blame] | 35 | } |
Adam Sadovsky | 62e37f3 | 2014-10-23 18:14:20 -0700 | [diff] [blame] | 36 | |
| 37 | function main() { |
Ivan Pilat | ddb6191 | 2014-12-29 21:16:23 -0800 | [diff] [blame] | 38 | if [[ ! -e ~/.gitcookies ]]; then |
| 39 | echo "Unable to access git, missing ~/.gitcookies" |
Adam Sadovsky | 62e37f3 | 2014-10-23 18:14:20 -0700 | [diff] [blame] | 40 | exit 1 |
| 41 | fi |
Ivan Pilat | aee5e9f | 2014-12-15 21:46:05 -0800 | [diff] [blame] | 42 | if [[ ! -e ~/.hgrc ]]; then |
| 43 | echo "Unable to access mercurial, missing ~/.hgrc" |
| 44 | exit 1 |
| 45 | fi |
Adam Sadovsky | 62e37f3 | 2014-10-23 18:14:20 -0700 | [diff] [blame] | 46 | |
Adam Sadovsky | d270f6c | 2014-10-31 11:39:03 -0700 | [diff] [blame] | 47 | local ROLLING="1" |
| 48 | if [[ $# -gt 0 && ("$1" == "--no-rolling") ]]; then |
| 49 | local ROLLING="0" |
| 50 | fi |
| 51 | |
Adam Sadovsky | 99e1d4f | 2014-10-28 19:20:49 -0700 | [diff] [blame] | 52 | gcloud compute --project "google.com:veyron" disks create ${DISK} --size "200" --zone "us-central1-a" --source-snapshot "pg-data-20140702" --type "pd-standard" |
| 53 | gcloud compute --project "google.com:veyron" instances attach-disk --disk=${DISK} $(hostname) --zone us-central1-a |
Adam Sadovsky | 62e37f3 | 2014-10-23 18:14:20 -0700 | [diff] [blame] | 54 | sudo mount /dev/sdb1 /mnt |
| 55 | |
| 56 | # Build the docker image. |
Ivan Pilat | 153037f | 2015-02-02 20:13:50 -0800 | [diff] [blame] | 57 | cd ${VANADIUM_ROOT}/release/projects/playground/go/src/playground |
Ivan Pilat | 8ecbed3 | 2015-01-13 21:30:05 -0800 | [diff] [blame] | 58 | cp ~/.gitcookies ./builder/gitcookies |
| 59 | cp ~/.hgrc ./builder/hgrc |
Adam Sadovsky | 62e37f3 | 2014-10-23 18:14:20 -0700 | [diff] [blame] | 60 | sudo docker build --no-cache -t playground . |
Ivan Pilat | 8ecbed3 | 2015-01-13 21:30:05 -0800 | [diff] [blame] | 61 | rm -f ./builder/gitcookies |
| 62 | rm -f ./builder/hgrc |
Adam Sadovsky | 62e37f3 | 2014-10-23 18:14:20 -0700 | [diff] [blame] | 63 | |
| 64 | # Export the docker image to disk. |
| 65 | sudo docker save -o /mnt/playground.tar.gz playground |
| 66 | |
Adam Sadovsky | d270f6c | 2014-10-31 11:39:03 -0700 | [diff] [blame] | 67 | # TODO(sadovsky): Before deploying the new playground image, we should run it |
| 68 | # with real input and make sure it works (produces the expected output). |
Adam Sadovsky | 78f2245 | 2014-10-23 18:50:04 -0700 | [diff] [blame] | 69 | |
Adam Sadovsky | 62e37f3 | 2014-10-23 18:14:20 -0700 | [diff] [blame] | 70 | # Copy the compilerd binary from the docker image to the disk. |
Adam Sadovsky | 78f2245 | 2014-10-23 18:50:04 -0700 | [diff] [blame] | 71 | # NOTE(sadovsky): The purpose of the following line is to create a container |
| 72 | # out of the docker image, so that we can copy out the compilerd binary. |
| 73 | # Annoyingly, the only way to create the container is to run the image. |
Ivan Pilat | ddb6191 | 2014-12-29 21:16:23 -0800 | [diff] [blame] | 74 | # TODO(sadovsky): Why don't we just build compilerd using "v23 go install"? |
Adam Sadovsky | 78f2245 | 2014-10-23 18:50:04 -0700 | [diff] [blame] | 75 | sudo docker run --name=${DISK} playground &> /dev/null || true |
Ivan Pilat | 153037f | 2015-02-02 20:13:50 -0800 | [diff] [blame] | 76 | sudo docker cp ${DISK}:/usr/local/vanadium/release/projects/playground/go/bin/compilerd /tmp |
Adam Sadovsky | 62e37f3 | 2014-10-23 18:14:20 -0700 | [diff] [blame] | 77 | sudo mv /tmp/compilerd /mnt/compilerd |
| 78 | sudo docker rm ${DISK} |
| 79 | |
| 80 | # Detach the disk so the backends can mount it. |
| 81 | unmount |
| 82 | |
| 83 | # Update the template to use the new disk. |
Ivan Pilat | 8ecbed3 | 2015-01-13 21:30:05 -0800 | [diff] [blame] | 84 | cd compilerd |
Adam Sadovsky | 62e37f3 | 2014-10-23 18:14:20 -0700 | [diff] [blame] | 85 | sed -i -e s/pg-data-20140820/${DISK}/ pool_template.json |
| 86 | gcloud preview replica-pools --zone=us-central1-a update-template --template=pool_template.json playground-pool |
| 87 | git checkout -- pool_template.json |
| 88 | |
Adam Sadovsky | 78f2245 | 2014-10-23 18:50:04 -0700 | [diff] [blame] | 89 | # Perform a rolling restart of all the replicas. |
Adam Sadovsky | 62e37f3 | 2014-10-23 18:14:20 -0700 | [diff] [blame] | 90 | INSTANCES=$(gcloud preview replica-pools --zone=us-central1-a replicas --pool=playground-pool list|grep name:|cut -d: -f2) |
| 91 | for i in ${INSTANCES}; do |
| 92 | gcloud preview replica-pools --zone=us-central1-a replicas --pool=playground-pool restart ${i} |
Adam Sadovsky | d270f6c | 2014-10-31 11:39:03 -0700 | [diff] [blame] | 93 | if [[ "$ROLLING" == "1" ]]; then |
| 94 | sleep 5m |
| 95 | fi |
Adam Sadovsky | 62e37f3 | 2014-10-23 18:14:20 -0700 | [diff] [blame] | 96 | done |
| 97 | } |
| 98 | |
| 99 | main "$@" |