Skip to content

Commit 7288888

Browse files
authored
Cleanup run_in_docker.sh and corresponding examples. (grpc#29469)
* update docker_runners examples * run_in_docker improvements * run_in_docker.sh should use build_and_run_docker.sh * cleanup run_in_docker.sh and examples
1 parent e26c812 commit 7288888

6 files changed

+49
-76
lines changed

tools/docker_runners/examples/bazel_test_in_docker.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ cd "$(dirname "$0")/../../.."
2121
# TODO(jtattermusch): make sure bazel cache is persisted between runs
2222

2323
# Note that the port server must be running so that the bazel tests can pass.
24+
# (Run "tools/run_tests/start_port_server.py" first)
2425

2526
# use the default docker image used for bazel builds
2627
export DOCKERFILE_DIR=tools/dockerfile/test/bazel
27-
# TODO(jtattermusch): interestingly, the bazel build fails when "--privileged" docker arg is used (it probably has to do with sandboxing)
28-
export DOCKER_EXTRA_ARGS="--privileged=false"
28+
# Using host network allows using port server running on the host machine (and not just in the docker container)
29+
# TODO(jtattermusch): interestingly, the bazel build fails when "--privileged=true" docker arg is used (it probably has to do with sandboxing)
30+
export DOCKER_EXTRA_ARGS="--network=host"
2931
tools/docker_runners/run_in_docker.sh bazel test //test/...

tools/docker_runners/examples/coredump_in_docker.sh

+10-6
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ set -ex
1818
# change to grpc repo root
1919
cd "$(dirname "$0")/../../.."
2020

21-
# use the docker image used as the default for C++ by run_tests.py
22-
# TODO(jtattermusch): document how to get the right docker image name
23-
# for given run_tests.py --compiler/--arch params.
24-
export DOCKERFILE_DIR=tools/dockerfile/test/cxx_debian9_x64
21+
# Use the docker image used as the default for C++ by run_tests.py
22+
# To use the correct docker image for your experiments,
23+
# note that every invocation of run_tests.py with "--use_docker"
24+
# prints the docker image used as a debug message at the end of the run.
25+
# This is expecially important when --compiler/--arch params are
26+
# use, since they usually influence with docker image will be used
27+
# by run_tests.py
28+
export DOCKERFILE_DIR=tools/dockerfile/test/cxx_debian11_x64
2529

26-
# add extra docker args if needed
27-
export DOCKER_EXTRA_ARGS=""
30+
# "--privileged" docker arg is required to be able to update /proc/sys/kernel/core_pattern
31+
export DOCKER_EXTRA_ARGS="--privileged"
2832

2933
# start the docker container with interactive shell
3034
tools/docker_runners/run_in_docker.sh bash

tools/docker_runners/examples/gdb_in_docker.sh

+11-6
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@ set -ex
1818
# change to grpc repo root
1919
cd "$(dirname "$0")/../../.."
2020

21-
# use the docker image used as the default for C++ by run_tests.py
22-
# TODO(jtattermusch): document how to get the right docker image name
23-
# for given run_tests.py --compiler/--arch params.
24-
export DOCKERFILE_DIR=tools/dockerfile/test/cxx_debian9_x64
21+
# Use the docker image used as the default for C++ by run_tests.py
22+
# To use the correct docker image for your experiments,
23+
# note that every invocation of run_tests.py with "--use_docker"
24+
# prints the docker image used as a debug message at the end of the run.
25+
# This is expecially important when --compiler/--arch params are
26+
# use, since they usually influence with docker image will be used
27+
# by run_tests.py
28+
export DOCKERFILE_DIR=tools/dockerfile/test/cxx_debian11_x64
2529

26-
# add extra docker args if needed
27-
export DOCKER_EXTRA_ARGS=""
30+
# "--privileged" docker arg is required to be disable address randomization by gdb
31+
# TODO: is "--security-opt=seccomp=unconfined" actually needed?
32+
export DOCKER_EXTRA_ARGS="--privileged --security-opt=seccomp=unconfined"
2833

2934
# start the docker container with interactive shell
3035
tools/docker_runners/run_in_docker.sh bash

tools/docker_runners/examples/run_tests_c_cpp_in_docker.sh renamed to tools/docker_runners/examples/run_tests_c_in_docker.sh

+8-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ set -ex
1919
cd "$(dirname "$0")/../../.."
2020

2121
# use the docker image used as the default for C++ by run_tests.py
22-
# TODO(jtattermusch): document how to get the right docker image name
23-
# for given run_tests.py --compiler/--arch params.
24-
export DOCKERFILE_DIR=tools/dockerfile/test/cxx_debian9_x64
25-
tools/docker_runners/run_in_docker.sh tools/run_tests/run_tests.py -l c c++ -c dbg
22+
# To use the correct docker image for your experiments,
23+
# note that every invocation of run_tests.py with "--use_docker"
24+
# prints the docker image used as a debug message at the end of the run.
25+
# This is expecially important when --compiler/--arch params are
26+
# use, since they usually influence with docker image will be used
27+
# by run_tests.py
28+
export DOCKERFILE_DIR=tools/dockerfile/test/cxx_debian11_x64
29+
tools/docker_runners/run_in_docker.sh tools/run_tests/run_tests.py -l c -c dbg

tools/docker_runners/examples/run_tests_csharp_in_docker.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ set -ex
1919
cd "$(dirname "$0")/../../.."
2020

2121
# use the docker image used as the default for C# by run_tests.py
22-
export DOCKERFILE_DIR=tools/dockerfile/test/csharp_buster_x64
22+
export DOCKERFILE_DIR=tools/dockerfile/test/csharp_debian11_x64
2323
tools/docker_runners/run_in_docker.sh tools/run_tests/run_tests.py -l csharp -c dbg --compiler coreclr

tools/docker_runners/run_in_docker.sh

+15-57
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
# Runs C# build in a docker container, but using the local workspace.
17-
# Example usage:
18-
# src/csharp/run_in_docker.sh tools/run_tests/run_tests.py -l csharp
16+
# See tools/docker_runners/examples for more usage info.
1917

2018
set -e
2119

@@ -36,60 +34,20 @@ then
3634
exit 1
3735
fi
3836

39-
# Use image name based on Dockerfile location checksum
40-
# For simplicity, currently only testing docker images that have already been pushed
41-
# to dockerhub are supported (see tools/dockerfile/push_testing_images.sh)
42-
# TODO(jtattermusch): add support for building dockerimages locally.
43-
DOCKER_IMAGE=grpctesting/$(basename "$DOCKERFILE_DIR"):$(sha1sum "$DOCKERFILE_DIR/Dockerfile" | cut -f1 -d\ )
44-
45-
# TODO: support building dockerimage locally / pulling it from dockerhub
46-
47-
# If TTY is available, the running container can be conveniently terminated with Ctrl+C.
48-
if [[ -t 0 ]]; then
49-
DOCKER_TTY_ARGS=("-it")
50-
else
51-
# The input device on kokoro is not a TTY, so -it does not work.
52-
DOCKER_TTY_ARGS=()
53-
fi
54-
55-
# args required to be able to run gdb/strace under the docker container
56-
DOCKER_PRIVILEGED_ARGS=(
57-
"--privileged"
58-
"--cap-add=SYS_PTRACE"
59-
"--security-opt=seccomp=unconfined"
60-
)
61-
62-
DOCKER_NETWORK_ARGS=(
63-
# enable IPv6
64-
"--sysctl=net.ipv6.conf.all.disable_ipv6=0"
65-
# use host network, required for the port server to work correctly
66-
"--network=host"
37+
DOCKER_NONROOT_ARGS=(
38+
# run under current user's UID and GID
39+
# Uncomment to run the docker container as current user's UID and GID.
40+
# That way, the files written by the container won't be owned by root (=you won't end up with polluted workspace),
41+
# but it can have some other disadvantages. E.g.:
42+
# - you won't be able install stuff inside the container
43+
# - the home directory inside the container will be broken (you won't be able to write in it).
44+
# That may actually break some language runtimes completely (e.g. grpc python might not build)
45+
# "--user=$(id -u):$(id -g)"
6746
)
6847

69-
DOCKER_CLEANUP_ARGS=(
70-
# delete the container when the containers exits
71-
# (otherwise the container will not release the disk space it used)
72-
"--rm=true"
73-
)
74-
75-
DOCKER_PROPAGATE_ENV_ARGS=(
76-
"--env-file=tools/run_tests/dockerize/docker_propagate_env.list" \
77-
)
78-
79-
# Uncomment to run the docker container as current user's UID and GID.
80-
# That way, the files written by the container won't be owned by root (=you won't end up with polluted workspace),
81-
# but it can have some other disadvantages. E.g.:
82-
# - you won't be able install stuff inside the container
83-
# - the home directory inside the container will be broken (you won't be able to write in it).
84-
# That may actually break some language runtimes completely (e.g. grpc python might not build)
85-
# DOCKER_NONROOT_ARGS=(
86-
# # run under current user's UID and GID
87-
# "--user=$(id -u):$(id -g)"
88-
# )
89-
90-
# Enable command echo just before running the final docker command to make the docker args visible.
91-
set -ex
48+
# the original DOCKER_EXTRA_ARGS + all the args defined in this script
49+
export DOCKER_EXTRA_ARGS="${DOCKER_NONROOT_ARGS[@]} ${DOCKER_EXTRA_ARGS}"
50+
# download the docker images from dockerhub instead of building them locally
51+
export DOCKERHUB_ORGANIZATION=grpctesting
9252

93-
# Run command inside C# docker container.
94-
# - the local clone of grpc repository will be mounted as /workspace.
95-
exec docker run "${DOCKER_TTY_ARGS[@]}" "${DOCKER_PRIVILEGED_ARGS[@]}" "${DOCKER_NETWORK_ARGS[@]}" "${DOCKER_CLEANUP_ARGS[@]}" "${DOCKER_PROPAGATE_ENV_ARGS[@]}" ${DOCKER_EXTRA_ARGS} -v "${grpc_rootdir}":/workspace -w /workspace "${DOCKER_IMAGE}" bash -c "$*"
53+
exec tools/run_tests/dockerize/build_and_run_docker.sh "$@"

0 commit comments

Comments
 (0)