1#!/bin/bash 2# Copyright 2017 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 Kokoro Linux performance worker. 17# You shouldn't run this script on your own, 18# use create_linux_kokoro_performance_worker.sh instead. 19 20set -ex 21 22sudo apt-get update 23 24# Install Java 8 JDK (to build gRPC Java) 25sudo apt-get install -y openjdk-8-jdk 26sudo apt-get install -y unzip lsof 27 28sudo apt-get install -y \ 29 autoconf \ 30 autotools-dev \ 31 build-essential \ 32 bzip2 \ 33 ccache \ 34 curl \ 35 gcc \ 36 gcc-multilib \ 37 git \ 38 gyp \ 39 lcov \ 40 libc6 \ 41 libc6-dbg \ 42 libc6-dev \ 43 libcurl4-openssl-dev \ 44 libgtest-dev \ 45 libreadline-dev \ 46 libssl-dev \ 47 libtool \ 48 make \ 49 strace \ 50 python-dev \ 51 python-pip \ 52 python-setuptools \ 53 python-yaml \ 54 python3-dev \ 55 python3-pip \ 56 python3-setuptools \ 57 python3-yaml \ 58 telnet \ 59 unzip \ 60 wget \ 61 zip \ 62 zlib1g-dev 63 64# perftools 65sudo apt-get install -y google-perftools libgoogle-perftools-dev 66 67# netperf 68sudo apt-get install -y netperf 69 70# required to run kokoro_log_reader.py 71sudo apt-get install -y python-psutil python3-psutil 72 73# gcloud tools, including gsutil 74sudo apt-get install -y google-cloud-sdk 75 76# C++ dependencies 77sudo apt-get install -y libgtest-dev libc++-dev clang 78 79# Python dependencies 80sudo pip install --upgrade pip==19.3.1 81sudo pip install tabulate 82sudo pip install google-api-python-client oauth2client 83sudo pip install virtualenv 84 85# pypy is used instead of python for postprocessing benchmark outputs 86# because some reports are huge and pypy is much faster. 87# TODO(jtattermusch): get rid of pypy once possible, it's hard to 88# keep track of all the installed variants of python. 89sudo apt-get install -y pypy pypy-dev 90curl -O https://bootstrap.pypa.io/get-pip.py 91sudo pypy get-pip.py 92sudo pypy -m pip install tabulate 93sudo pypy -m pip install google-api-python-client oauth2client 94# TODO(jtattermusch): for some reason, we need psutil installed 95# in pypy for kokoro_log_reader.py (strange, because the command is 96# "python kokoro_log_reader.py" and pypy is not the system default) 97sudo pypy -m pip install psutil 98 99# Node dependencies (nvm has to be installed under user kbuilder) 100touch .profile 101curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | bash 102# silence shellcheck as it cannot follow the following `source` path statically: 103# shellcheck disable=SC1090 104source ~/.nvm/nvm.sh 105nvm install 0.12 && npm config set cache /tmp/npm-cache 106nvm install 4 && npm config set cache /tmp/npm-cache 107nvm install 5 && npm config set cache /tmp/npm-cache 108nvm alias default 4 109 110# C# dependencies 111sudo apt-get install -y cmake 112 113# C# mono dependencies (http://www.mono-project.com/docs/getting-started/install/linux/#debian-ubuntu-and-derivatives) 114sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF 115echo "deb https://download.mono-project.com/repo/ubuntu stable-bionic main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list 116sudo apt-get update 117sudo apt-get install -y mono-devel 118 119# C# .NET Core dependencies (https://www.microsoft.com/net/download) 120wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb 121sudo dpkg -i packages-microsoft-prod.deb 122 123sudo apt-get install -y apt-transport-https 124sudo apt-get update 125sudo apt-get install -y dotnet-sdk-2.1 126 127# Install .NET Core 1.0.5 Runtime (required to run netcoreapp1.0) 128wget -q https://download.microsoft.com/download/2/4/A/24A06858-E8AC-469B-8AE6-D0CEC9BA982A/dotnet-ubuntu.16.04-x64.1.0.5.tar.gz 129mkdir -p dotnet105_download 130tar zxf dotnet-ubuntu.16.04-x64.1.0.5.tar.gz -C dotnet105_download 131sudo cp -r dotnet105_download/shared/Microsoft.NETCore.App/1.0.5/ /usr/share/dotnet/shared/Microsoft.NETCore.App/ 132# To prevent "Failed to initialize CoreCLR, HRESULT: 0x80131500" with .NET Core 1.0.5 runtime 133wget -q http://security.ubuntu.com/ubuntu/pool/main/i/icu/libicu55_55.1-7ubuntu0.4_amd64.deb 134sudo dpkg -i libicu55_55.1-7ubuntu0.4_amd64.deb 135 136# Install .NET Core 1.1.10 runtime (required to run netcoreapp1.1) 137wget -q -O dotnet_old.tar.gz https://download.visualstudio.microsoft.com/download/pr/b25b5650-0cb8-4699-a347-48d73650da0b/920966211e9bb1907232bbda1faa895a/dotnet-ubuntu.18.04-x64.1.1.10.tar.gz 138mkdir -p dotnet_old 139tar zxf dotnet_old.tar.gz -C dotnet_old 140sudo cp -r dotnet_old/shared/Microsoft.NETCore.App/1.1.10/ /usr/share/dotnet/shared/Microsoft.NETCore.App/ 141 142# Ruby dependencies 143gpg --keyserver hkp://pgp.mit.edu --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB 144curl -sSL https://get.rvm.io | bash -s stable --ruby 145# silence shellcheck as it cannot follow the following `source` path statically: 146# shellcheck disable=SC1090 147source ~/.rvm/scripts/rvm 148 149git clone https://github.com/rbenv/rbenv.git ~/.rbenv 150export PATH="$HOME/.rbenv/bin:$PATH" 151eval "$(rbenv init -)" 152 153git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build 154export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH" 155 156rbenv install 2.4.0 157rbenv global 2.4.0 158ruby -v 159 160# Install bundler (prerequisite for gRPC Ruby) 161gem install bundler 162 163# PHP dependencies 164sudo apt-get install -y php7.2 php7.2-dev php-pear unzip zlib1g-dev 165sudo wget https://phar.phpunit.de/phpunit-8.5.8.phar && \ 166 sudo mv phpunit-8.5.8.phar /usr/local/bin/phpunit && \ 167 sudo chmod +x /usr/local/bin/phpunit 168curl -sS https://getcomposer.org/installer | php 169sudo mv composer.phar /usr/local/bin/composer 170 171# Java dependencies - nothing as we already have Java JDK 8 172 173# Go dependencies 174# Currently, the golang package available via apt-get doesn't have the latest go. 175# Significant performance improvements with grpc-go have been observed after 176# upgrading from go 1.5 to a later version, so a later go version is preferred. 177# Following go install instructions from https://golang.org/doc/install 178GO_VERSION=1.10 179OS=linux 180ARCH=amd64 181curl -O https://storage.googleapis.com/golang/go${GO_VERSION}.${OS}-${ARCH}.tar.gz 182sudo tar -C /usr/local -xzf go$GO_VERSION.$OS-$ARCH.tar.gz 183# Put go on the PATH, keep the usual installation dir 184sudo ln -s /usr/local/go/bin/go /usr/bin/go 185rm go$GO_VERSION.$OS-$ARCH.tar.gz 186 187# Install perf, to profile benchmarks. (need to get the right linux-tools-<> for kernel version) 188sudo apt-get install -y linux-tools-common linux-tools-generic "linux-tools-$(uname -r)" 189# see http://unix.stackexchange.com/questions/14227/do-i-need-root-admin-permissions-to-run-userspace-perf-tool-perf-events-ar 190echo 0 | sudo tee /proc/sys/kernel/perf_event_paranoid 191# see http://stackoverflow.com/questions/21284906/perf-couldnt-record-kernel-reference-relocation-symbol 192echo 0 | sudo tee /proc/sys/kernel/kptr_restrict 193 194# qps workers under perf appear to need a lot of mmap pages under certain scenarios and perf args in 195# order to not lose perf events or time out 196echo 4096 | sudo tee /proc/sys/kernel/perf_event_mlock_kb 197 198# Fetch scripts to generate flame graphs from perf data collected 199# on benchmarks 200git clone -v https://github.com/brendangregg/FlameGraph ~/FlameGraph 201 202# Install scipy and numpy for benchmarking scripts 203sudo apt-get install -y python3-scipy python3-numpy 204 205# Install docker 206curl -sSL https://get.docker.com/ | sh 207# Enable kbuilder to use docker without sudo: 208sudo usermod -aG docker kbuilder 209 210# Add pubkey of Kokoro driver VM to allow SSH 211# silence false-positive shellcheck warning ("< redirect does not affect sudo") 212# shellcheck disable=SC2024 213sudo tee --append ~kbuilder/.ssh/authorized_keys < kokoro_performance.pub 214 215# Kokoro requires /tmpfs/READY file to exist the directory and file itself should 216# be owned by kbuilder. 217sudo mkdir /tmpfs 218sudo chown kbuilder /tmpfs 219touch /tmpfs/READY 220 221# Disable automatic updates to prevent spurious apt-get install failures 222# See https://github.com/grpc/grpc/issues/17794 223sudo sed -i 's/APT::Periodic::Update-Package-Lists "1"/APT::Periodic::Update-Package-Lists "0"/' /etc/apt/apt.conf.d/10periodic 224sudo sed -i 's/APT::Periodic::AutocleanInterval "1"/APT::Periodic::AutocleanInterval "0"/' /etc/apt/apt.conf.d/10periodic 225sudo sed -i 's/APT::Periodic::Update-Package-Lists "1"/APT::Periodic::Update-Package-Lists "0"/' /etc/apt/apt.conf.d/20auto-upgrades 226sudo sed -i 's/APT::Periodic::Unattended-Upgrade "1"/APT::Periodic::Unattended-Upgrade "0"/' /etc/apt/apt.conf.d/20auto-upgrades 227 228# Restart for VM to pick up kernel update 229echo 'Successfully initialized the linux worker, going for reboot in 10 seconds' 230sleep 10 231sudo reboot 232