Skip to content
This repository was archived by the owner on Dec 8, 2021. It is now read-only.

Commit 6311fd7

Browse files
author
Takashi Matsuo
authored
testing: allow build.sh to run arbitrary commands in the container (#1168)
* testing: allow build.sh to run arbitrary commands in the container * add `--rm` flag for command mode * Always add `--rm` flag
1 parent 31d7507 commit 6311fd7

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

ci/kokoro/docker/build.sh

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ if [[ "${RUN_SLOW_INTEGRATION_TESTS:-}" != "yes" ]]; then
3030
fi
3131
export RUN_SLOW_INTEGRATION_TESTS
3232

33-
if [[ $# -eq 1 ]]; then
33+
if [[ $# -ge 1 ]]; then
3434
export BUILD_NAME="${1}"
3535
elif [[ -n "${KOKORO_JOB_NAME:-}" ]]; then
3636
# Kokoro injects the KOKORO_JOB_NAME environment variable, the value of this
@@ -227,8 +227,6 @@ echo "Docker image created $(date)."
227227
sudo docker image ls
228228
echo "================================================================"
229229

230-
echo "================================================================"
231-
echo "Running the full build $(date)."
232230
# The default user for a Docker container has uid 0 (root). To avoid creating
233231
# root-owned files in the build directory we tell docker to use the current
234232
# user ID, if known.
@@ -350,6 +348,9 @@ docker_flags=(
350348
"--volume" "/v/cmake-out/home"
351349
"--volume" "/v/cmake-out"
352350
"--volume" "${PWD}/${BUILD_OUTPUT}:/v/${BUILD_OUTPUT}"
351+
352+
# No need to preserve the container.
353+
"--rm"
353354
)
354355

355356
# When running the builds from the command-line they get a tty, and the scripts
@@ -360,9 +361,23 @@ if [[ -t 0 ]]; then
360361
docker_flags+=("-it")
361362
fi
362363

363-
sudo docker run "${docker_flags[@]}" "${IMAGE}:tip" \
364-
"/v/${in_docker_script}" "${CMAKE_SOURCE_DIR}" \
365-
"${BUILD_OUTPUT}"
364+
# If more than two arguments are given, arguments after the first one will
365+
# become the commands run in the container, otherwise run $in_docker_script with
366+
# appropriate arguments.
367+
echo "================================================================"
368+
if [[ $# -ge 2 ]]; then
369+
echo "Running the given commands '" "${@:2}" "' in the container $(date)."
370+
readonly commands=( "${@:2}" )
371+
else
372+
echo "Running the full build $(date)."
373+
readonly commands=(
374+
"/v/${in_docker_script}"
375+
"${CMAKE_SOURCE_DIR}"
376+
"${BUILD_OUTPUT}"
377+
)
378+
fi
379+
380+
sudo docker run "${docker_flags[@]}" "${IMAGE}:tip" "${commands[@]}"
366381

367382
exit_status=$?
368383
echo "Build finished with ${exit_status} exit status $(date)."

0 commit comments

Comments
 (0)