Jan Tattermusch | 96839f8 | 2016-02-06 18:11:39 -0800 | [diff] [blame] | 1 | #!/bin/bash |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 2 | # Copyright 2015 gRPC authors. |
Jan Tattermusch | 96839f8 | 2016-02-06 18:11:39 -0800 | [diff] [blame] | 3 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
Jan Tattermusch | 96839f8 | 2016-02-06 18:11:39 -0800 | [diff] [blame] | 7 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
Jan Tattermusch | 96839f8 | 2016-02-06 18:11:39 -0800 | [diff] [blame] | 9 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
Jan Tattermusch | 96839f8 | 2016-02-06 18:11:39 -0800 | [diff] [blame] | 15 | |
| 16 | # Initializes a fresh GCE VM to become a jenkins linux worker. |
| 17 | # You shouldn't run this script on your own, use create_linux_worker.sh |
| 18 | # instead. |
| 19 | |
| 20 | set -ex |
| 21 | |
Nicolas "Pixel" Noble | 8ed4399 | 2016-09-28 00:14:39 +0200 | [diff] [blame] | 22 | # Create some swap space |
| 23 | sudo dd if=/dev/zero of=/swap bs=1024 count=10485760 |
| 24 | sudo chmod 600 /swap |
| 25 | sudo mkswap /swap |
| 26 | sudo sed -i '$ a\/swap none swap sw 0 0' /etc/fstab |
| 27 | sudo swapon -a |
| 28 | |
| 29 | # Typical apt-get maintenance |
Jan Tattermusch | 96839f8 | 2016-02-06 18:11:39 -0800 | [diff] [blame] | 30 | sudo apt-get update |
| 31 | |
| 32 | # Install JRE |
Jan Tattermusch | 49beb93 | 2016-05-09 11:22:04 -0700 | [diff] [blame] | 33 | sudo apt-get install -y openjdk-8-jre |
Jan Tattermusch | 96839f8 | 2016-02-06 18:11:39 -0800 | [diff] [blame] | 34 | sudo apt-get install -y unzip lsof |
| 35 | |
| 36 | # Install Docker |
| 37 | curl -sSL https://get.docker.com/ | sh |
| 38 | |
| 39 | # Setup jenkins user (or the user will already exist bcuz magic) |
| 40 | sudo adduser jenkins --disabled-password || true |
| 41 | |
| 42 | # Enable jenkins to use docker without sudo: |
| 43 | sudo usermod -aG docker jenkins |
| 44 | |
| 45 | # Use "overlay" storage driver for docker |
| 46 | # see https://github.com/grpc/grpc/issues/4988 |
Matt Kwong | 654c367 | 2017-04-11 14:31:39 -0700 | [diff] [blame] | 47 | printf "{\n\t\"storage-driver\": \"overlay\"\n}" | sudo tee /etc/docker/daemon.json |
Jan Tattermusch | 96839f8 | 2016-02-06 18:11:39 -0800 | [diff] [blame] | 48 | |
Matt Kwong | 112cf66 | 2017-05-03 16:00:01 -0700 | [diff] [blame] | 49 | # Install pip and Google API library to enable using GCP services |
| 50 | sudo apt-get install -y python-pip |
| 51 | sudo pip install google-api-python-client |
| 52 | |
Jan Tattermusch | 96839f8 | 2016-02-06 18:11:39 -0800 | [diff] [blame] | 53 | # Install RVM |
| 54 | # TODO(jtattermusch): why is RVM needed? |
| 55 | gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 |
| 56 | curl -sSL https://get.rvm.io | bash -s stable --ruby |
| 57 | |
Matt Kwong | 654c367 | 2017-04-11 14:31:39 -0700 | [diff] [blame] | 58 | # Upgrade Linux kernel to 4.9 |
| 59 | wget \ |
| 60 | kernel.ubuntu.com/~kernel-ppa/mainline/v4.9.20/linux-headers-4.9.20-040920_4.9.20-040920.201703310531_all.deb \ |
| 61 | kernel.ubuntu.com/~kernel-ppa/mainline/v4.9.20/linux-headers-4.9.20-040920-generic_4.9.20-040920.201703310531_amd64.deb \ |
| 62 | kernel.ubuntu.com/~kernel-ppa/mainline/v4.9.20/linux-image-4.9.20-040920-generic_4.9.20-040920.201703310531_amd64.deb |
| 63 | sudo dpkg -i linux-headers-4.9*.deb linux-image-4.9*.deb |
| 64 | rm linux-* |
| 65 | |
Jan Tattermusch | 96839f8 | 2016-02-06 18:11:39 -0800 | [diff] [blame] | 66 | # Add pubkey of jenkins@grpc-jenkins-master to authorized keys of jenkins@ |
| 67 | # This needs to happen as the last step to prevent Jenkins master from connecting |
| 68 | # to a machine that hasn't been properly setup yet. |
| 69 | cat jenkins_master.pub | sudo tee --append ~jenkins/.ssh/authorized_keys |
| 70 | |
Matt Kwong | 654c367 | 2017-04-11 14:31:39 -0700 | [diff] [blame] | 71 | # Restart for docker to pick up the config changes. |
Jan Tattermusch | 96839f8 | 2016-02-06 18:11:39 -0800 | [diff] [blame] | 72 | echo 'Successfully initialized the linux worker, going for reboot in 10 seconds' |
| 73 | sleep 10 |
| 74 | |
| 75 | sudo reboot |