| 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 |
# Source this rc script to prepare the environment for linux builds |
| 17 |
|
| 18 |
# Need to increase open files limit for c tests |
| 19 |
ulimit -n 32768 |
| 20 |
|
| 21 |
# 1. Move docker's storage location to scratch disk so we don't run out of space. |
| 22 |
# 2. Use container registry mirror for pulling docker images (should make downloads faster) |
| 23 |
# See https://cloud.google.com/container-registry/docs/using-dockerhub-mirroring |
| 24 |
GRPC_DOCKER_OPTS="--data-root=/tmpfs/docker --registry-mirror=https://mirror.gcr.io" |
| 25 |
|
| 26 |
# Update global docker configuration to have GRPC_DOCKER_OPTS |
| 27 |
P1NAME=$(ps -p 1 -o comm=) |
| 28 |
if [[ $P1NAME == *"systemd"* ]]; then |
| 29 |
# https://stackoverflow.com/questions/27763340 |
| 30 |
sudo sed -i -E "s|ExecStart=(.*)//|EnvironmentFile=/etc/default/docker\nExecStart=\nExecStart=\1// \$DOCKER_OPTS|" /lib/systemd/system/docker.service |
| 31 |
sudo systemctl daemon-reload |
| 32 |
echo "DOCKER_OPTS=\"${GRPC_DOCKER_OPTS}\"" | sudo tee --append /etc/default/docker |
| 33 |
sudo systemctl restart docker.service |
| 34 |
else |
| 35 |
echo "DOCKER_OPTS=\"\${DOCKER_OPTS} ${GRPC_DOCKER_OPTS}\"" | sudo tee --append /etc/default/docker |
| 36 |
sudo service docker restart |
| 37 |
fi |
| 38 |
|
| 39 |
# Download Docker images from DockerHub |
| 40 |
export DOCKERHUB_ORGANIZATION=grpctesting |
| 41 |
|
| 42 |
git submodule update --init |
| 43 |
|
| 44 |
python3 -m pip install six |
| 45 |
|
| 46 |
# check whether /tmpfs is mounted correctly |
| 47 |
(mount | grep -q 'on /tmpfs ') || (mount; echo 'BAD KOKORO WORKER WARNING: it seems that /tmpfs volume with scratch disk is not mounted in the kokoro worker. This can result in unexpected "out of disk space" errors.') |
| 48 |
|
| 49 |
# Uncomment the following line to debug "out of disk space" errors by print available disk space every 30seconds in the background |
| 50 |
# bash -c "while true; do echo 'periodic background disk usage check:'; df -h / /tmpfs; sleep 30; done;" & |