1#!/bin/bash 2# Copyright 2015 gRPC authors. 3# 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 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 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. 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 20set -ex 21 22# Create some swap space 23sudo dd if=/dev/zero of=/swap bs=1024 count=10485760 24sudo chmod 600 /swap 25sudo mkswap /swap 26sudo sed -i '$ a\/swap none swap sw 0 0' /etc/fstab 27sudo swapon -a 28 29# Typical apt-get maintenance 30sudo apt-get update 31 32# Install JRE 33sudo apt-get install -y openjdk-8-jre 34sudo apt-get install -y unzip lsof 35 36# Install Docker 37curl -sSL https://get.docker.com/ | sh 38 39# Setup jenkins user (or the user will already exist bcuz magic) 40sudo adduser jenkins --disabled-password || true 41 42# Enable jenkins to use docker without sudo: 43sudo usermod -aG docker jenkins 44 45# Use "overlay" storage driver for docker 46# see https://github.com/grpc/grpc/issues/4988 47printf "{\n\t\"storage-driver\": \"overlay\"\n}" | sudo tee /etc/docker/daemon.json 48 49# Install pip and Google API library to enable using GCP services 50sudo apt-get install -y python-pip 51sudo pip install google-api-python-client 52 53# Install RVM 54# TODO(jtattermusch): why is RVM needed? 55gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 56curl -sSL https://get.rvm.io | bash -s stable --ruby 57 58# Upgrade Linux kernel to 4.9 59wget \ 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 63sudo dpkg -i linux-headers-4.9*.deb linux-image-4.9*.deb 64rm linux-* 65 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 70# disable superfluous warning by shellcheck: 71# shellcheck disable=SC2024 72sudo tee --append ~jenkins/.ssh/authorized_keys < jenkins_master.pub 73 74# Restart for docker to pick up the config changes. 75echo 'Successfully initialized the linux worker, going for reboot in 10 seconds' 76sleep 10 77 78sudo reboot 79