2018-03-14 00:38:21 +08:00
|
|
|
#!/bin/bash
|
2018-07-12 04:16:29 +08:00
|
|
|
set -eu -o pipefail
|
2018-03-14 00:38:21 +08:00
|
|
|
|
|
|
|
quote() {
|
|
|
|
local arg
|
|
|
|
for arg in "$@"; do
|
|
|
|
printf "'"
|
|
|
|
printf "%s" "$arg" | sed -e "s/'/'\\\\''/g"
|
|
|
|
printf "' "
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2023-03-24 04:21:31 +08:00
|
|
|
readonly docker_image=$1; shift
|
|
|
|
|
2018-05-04 10:48:14 +08:00
|
|
|
readonly grpc_java_dir="$(dirname "$(readlink -f "$0")")/.."
|
|
|
|
if [[ -t 0 ]]; then
|
|
|
|
DOCKER_ARGS="-it"
|
2018-03-14 00:38:21 +08:00
|
|
|
else
|
2018-05-04 10:48:14 +08:00
|
|
|
# The input device on kokoro is not a TTY, so -it does not work.
|
|
|
|
DOCKER_ARGS=
|
2018-03-14 00:38:21 +08:00
|
|
|
fi
|
2018-05-04 10:48:14 +08:00
|
|
|
# Use a trap function to fix file permissions upon exit, without affecting
|
|
|
|
# the original exit code. $DOCKER_ARGS can not be quoted, otherwise it becomes a '' which confuses
|
|
|
|
# docker.
|
|
|
|
exec docker run $DOCKER_ARGS --rm=true -v "${grpc_java_dir}":/grpc-java -w /grpc-java \
|
2023-03-24 04:21:31 +08:00
|
|
|
$docker_image \
|
2018-05-04 10:48:14 +08:00
|
|
|
bash -c "function fixFiles() { chown -R $(id -u):$(id -g) /grpc-java; }; trap fixFiles EXIT; $(quote "$@")"
|