Add a simple way to run grpc-java test inside emulated ARM64 docker container

This commit is contained in:
Jan Tattermusch 2021-01-19 18:05:22 +01:00 committed by GitHub
parent 1b23cf4f39
commit 76c5a651a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 0 deletions

3
.gitignore vendored
View File

@ -35,3 +35,6 @@ bin
# Emacs
*~
\#*\#
# ARM tests
qemu-arm-static

View File

@ -0,0 +1,10 @@
# This docker image uses magic to seamlessly run its contents using qemu ARM emulator on x86 host.
# See https://ownyourbits.com/2018/06/27/running-and-building-arm-docker-containers-in-x86/
# We want to test on arm64v8
FROM arm64v8/debian:buster
# Make the host's qemu-arm-static emulator available from inside the docker container.
COPY qemu-arm-static /usr/bin
RUN apt-get update && apt-get install -y --no-install-recommends openjdk-11-jdk-headless && apt-get clean

View File

@ -0,0 +1,26 @@
#!/bin/bash
set -ex
readonly grpc_java_dir="$(dirname "$(readlink -f "$0")")/.."
# Build magic docker image that can run on x86 host, but looks like an ARM machine
# from the inside (qemu-user-static is used for emulation)
# Run "sudo apt install qemu-user-static binfmt-support" install the emulator
# on the host machine.
# Also see https://ownyourbits.com/2018/06/27/running-and-building-arm-docker-containers-in-x86/
cp /usr/bin/qemu-arm-static "${grpc_java_dir}/buildscripts/grpc-java-linux-arm64-tests"
docker build -t grpc-java-linux-arm64-tests "${grpc_java_dir}/buildscripts/grpc-java-linux-arm64-tests"
if [[ -t 0 ]]; then
DOCKER_ARGS="-it"
else
# The input device on kokoro is not a TTY, so -it does not work.
DOCKER_ARGS=
fi
# - run docker container under current user's UID to avoid polluting the workspace
# - set the user.home property to avoid creating a "?" directory under grpc-java
exec docker run $DOCKER_ARGS --rm=true -v "${grpc_java_dir}":/grpc-java -w /grpc-java \
--user "$(id -u):$(id -g)" -e "JAVA_OPTS=-Duser.home=/grpc-java/.current-user-home" \
grpc-java-linux-arm64-tests \
bash -c "./gradlew build -PskipAndroid=true -PskipCodegen=true"