xref: /aosp_15_r20/external/grpc-grpc-java/buildscripts/run_arm64_tests_in_docker.sh (revision e07d83d3ffcef9ecfc9f7f475418ec639ff0e5fe)
1#!/bin/bash
2set -ex
3
4readonly grpc_java_dir="$(dirname "$(readlink -f "$0")")/.."
5
6if [[ -t 0 ]]; then
7  DOCKER_ARGS="-it"
8else
9  # The input device on kokoro is not a TTY, so -it does not work.
10  DOCKER_ARGS=
11fi
12
13
14cat <<EOF >> "${grpc_java_dir}/gradle.properties"
15skipAndroid=true
16skipCodegen=true
17org.gradle.parallel=true
18org.gradle.jvmargs=-Xmx1024m
19EOF
20
21export JAVA_OPTS="-Duser.home=/grpc-java/.current-user-home -Djava.util.prefs.userRoot=/grpc-java/.current-user-home/.java/.userPrefs"
22
23# build under x64 docker image to save time over building everything under
24# aarch64 emulator. We've already built and tested the protoc binaries
25# so for the rest of the build we will be using "-PskipCodegen=true"
26# avoid further complicating the build.
27docker run $DOCKER_ARGS --rm=true -v "${grpc_java_dir}":/grpc-java -w /grpc-java \
28  --user "$(id -u):$(id -g)" -e JAVA_OPTS \
29  openjdk:11-jdk-slim-buster \
30  ./gradlew build -x test
31
32# Build and run java tests under aarch64 image.
33# To be able to run this docker container on x64 machine, one needs to have
34# qemu-user-static properly registered with binfmt_misc.
35# The most important flag binfmt_misc flag we need is "F" (set by "--persistent yes"),
36# which allows the qemu-aarch64-static binary to be loaded eagerly at the time of registration with binfmt_misc.
37# That way, we can emulate aarch64 binaries running inside docker containers transparently, without needing the emulator
38# binary to be accessible from the docker image we're emulating.
39# Note that on newer distributions (such as glinux), simply "apt install qemu-user-static" is sufficient
40# to install qemu-user-static with the right flags.
41# A note on the "docker run" args used:
42# - run docker container under current user's UID to avoid polluting the workspace
43# - set the user.home property to avoid creating a "?" directory under grpc-java
44docker run $DOCKER_ARGS --rm=true -v "${grpc_java_dir}":/grpc-java -w /grpc-java \
45  --user "$(id -u):$(id -g)" -e JAVA_OPTS \
46  arm64v8/openjdk:11-jdk-slim-buster \
47  ./gradlew build
48