| 1 |
#!/bin/bash |
| 2 |
# Copyright 2021 The 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 at the beginning of your CI script to move |
| 17 |
# the entire source tree to a different directory. |
| 18 |
# That avoids slow finalization (and a number of other problems) |
| 19 |
# caused by kokoro rsyncing the entire /tmpfs/src directory |
| 20 |
# back to the agent. |
| 21 |
# See b/74837748 for more context. |
| 22 |
|
| 23 |
set -ex |
| 24 |
|
| 25 |
CURRENT_DIR="$(pwd)" |
| 26 |
CI_SCRIPT_RELATIVE_TO_SRC="$0" |
| 27 |
|
| 28 |
if [ "${CURRENT_DIR}" == "/tmpfs/altsrc" ] |
| 29 |
then |
| 30 |
# we already respawned under /tmpfs/altsrc, no need to do anything |
| 31 |
echo "Successfully respawned the CI script ${CI_SCRIPT_RELATIVE_TO_SRC} under ${CURRENT_DIR}." |
| 32 |
# scripts in tools/run_tests generate test reports and we need to make sure these reports |
| 33 |
# land in a directory that is going to be rsynced back to the kokoro agent. |
| 34 |
export GRPC_TEST_REPORT_BASE_DIR="/tmpfs/src/github/grpc" |
| 35 |
elif [ "${CURRENT_DIR}" == "/tmpfs/src" ] |
| 36 |
then |
| 37 |
# we need to respawn now |
| 38 |
# - step out of current directory |
| 39 |
# - rename src/github to altsrc/github (/tmpfs/src is the directory that gets rsynced back to kokoro agent once the CI script finishes). |
| 40 |
# Note that we don't want to move the entire /tmpfs/src tree (which contains e.g. the input artifacts as well, |
| 41 |
# and their path is referenced by kokoro env variables), just /tmpfs/src/github |
| 42 |
# which contains all the cloned github repositories (=our workspace in which the build happens) |
| 43 |
echo "Moving workspace from /tmpfs/src to /tmpfs/altsrc and respawning the CI script." |
| 44 |
# once "exec bash" starts, the CI script in the original location will no longer be in use and it will be safe to move |
| 45 |
# the entire "/tmpfs/src/github" tree (moving the bash script file while running is probably safe anyway on unix, but it doesn't |
| 46 |
# hurt to be extra careful) |
| 47 |
exec bash -c "set -ex; cd /tmpfs; mkdir -p altsrc; mv src/github altsrc; cd altsrc; exec '${CI_SCRIPT_RELATIVE_TO_SRC}'" |
| 48 |
else |
| 49 |
# avoid messing with the workspace if we don't see the directory layout |
| 50 |
# that's standard on kokoro (in case this script gets accidentally invoked outside of kokoro) |
| 51 |
echo "Looks the script is currently not running on kokoro, skipping respawn and continuing the original CI script." |
| 52 |
fi |