blob: a5d2706ddb1629517c70083120b3b9b7d496ffbd [file] [log] [blame]
Jan Tattermusch96839f82016-02-06 18:11:39 -08001#!/bin/bash
Jan Tattermusch7897ae92017-06-07 22:57:36 +02002# Copyright 2015 gRPC authors.
Jan Tattermusch96839f82016-02-06 18:11:39 -08003#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02004# 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 Tattermusch96839f82016-02-06 18:11:39 -08007#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02008# http://www.apache.org/licenses/LICENSE-2.0
Jan Tattermusch96839f82016-02-06 18:11:39 -08009#
Jan Tattermusch7897ae92017-06-07 22:57:36 +020010# 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 Tattermusch96839f82016-02-06 18:11:39 -080015
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
Nicolas "Pixel" Noble8ed43992016-09-28 00:14:39 +020022# 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
Jan Tattermusch96839f82016-02-06 18:11:39 -080030sudo apt-get update
31
32# Install JRE
Jan Tattermusch49beb932016-05-09 11:22:04 -070033sudo apt-get install -y openjdk-8-jre
Jan Tattermusch96839f82016-02-06 18:11:39 -080034sudo 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
Matt Kwong654c3672017-04-11 14:31:39 -070047printf "{\n\t\"storage-driver\": \"overlay\"\n}" | sudo tee /etc/docker/daemon.json
Jan Tattermusch96839f82016-02-06 18:11:39 -080048
Matt Kwong112cf662017-05-03 16:00:01 -070049# 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
Jan Tattermusch96839f82016-02-06 18:11:39 -080053# 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
Matt Kwong654c3672017-04-11 14:31:39 -070058# 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
Jan Tattermusch96839f82016-02-06 18:11:39 -080066# 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.
69cat jenkins_master.pub | sudo tee --append ~jenkins/.ssh/authorized_keys
70
Matt Kwong654c3672017-04-11 14:31:39 -070071# Restart for docker to pick up the config changes.
Jan Tattermusch96839f82016-02-06 18:11:39 -080072echo 'Successfully initialized the linux worker, going for reboot in 10 seconds'
73sleep 10
74
75sudo reboot