@@ -30,7 +30,7 @@ if [[ "${RUN_SLOW_INTEGRATION_TESTS:-}" != "yes" ]]; then
3030fi
3131export RUN_SLOW_INTEGRATION_TESTS
3232
33- if [[ $# -eq 1 ]]; then
33+ if [[ $# -ge 1 ]]; then
3434 export BUILD_NAME=" ${1} "
3535elif [[ -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)."
227227sudo docker image ls
228228echo " ================================================================"
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" )
361362fi
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
367382exit_status=$?
368383echo " Build finished with ${exit_status} exit status $( date) ."
0 commit comments