Run grpc_android job under docker for better maintainability. (#31504)

* run grpc_android in a docker container

* add TODO

* fixup android_ndk dockerfile
pull/31528/head
Jan Tattermusch 2 years ago committed by GitHub
parent 7b0fc97bfc
commit 78fd1f637a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 36
      templates/tools/dockerfile/test/android_ndk/Dockerfile.template
  2. 26
      tools/dockerfile/test/android_ndk/Dockerfile
  3. 51
      tools/internal_ci/linux/grpc_android.sh
  4. 62
      tools/internal_ci/linux/grpc_android_in_docker.sh

@ -16,29 +16,41 @@
FROM debian:stretch
<%include file="../apt_get_basic.include"/>
<%include file="../run_tests_python_deps.include"/>
<%include file="../cmake.include"/>
<%include file="../run_tests_addons.include"/>
<%include file="../../apt_get_basic.include"/>
<%include file="../../run_tests_python_deps.include"/>
<%include file="../../cmake.include"/>
<%include file="../../run_tests_addons.include"/>
# Java required by Android SDK
RUN apt-get update && apt-get -y install openjdk-8-jdk && apt-get clean
# Install Android SDK
ENV ANDROID_SDK_VERSION 4333796
RUN mkdir -p /opt/android-sdk && cd /opt/android-sdk && \
wget -q https://dl.google.com/android/repository/sdk-tools-linux-$ANDROID_SDK_VERSION.zip && \
unzip -q sdk-tools-linux-$ANDROID_SDK_VERSION.zip && \
RUN mkdir -p /opt/android-sdk && cd /opt/android-sdk && ${'\\'}
wget -q https://dl.google.com/android/repository/sdk-tools-linux-$ANDROID_SDK_VERSION.zip && ${'\\'}
unzip -q sdk-tools-linux-$ANDROID_SDK_VERSION.zip && ${'\\'}
rm sdk-tools-linux-$ANDROID_SDK_VERSION.zip
ENV ANDROID_SDK_PATH /opt/android-sdk
ENV ANDROID_HOME /opt/android-sdk
RUN yes | $ANDROID_SDK_PATH/tools/bin/sdkmanager --licenses # accept all licenses
# Install Android NDK and cmake using sdkmanager
# Install ndk-bundle and cmake using sdkmanager
RUN mkdir -p ~/.android && touch ~/.android/repositories.cfg
RUN yes | $ANDROID_SDK_PATH/tools/bin/sdkmanager --licenses # accept all licenses
RUN $ANDROID_SDK_PATH/tools/bin/sdkmanager ndk-bundle 'cmake;3.6.4111459'
ENV ANDROID_NDK_PATH $ANDROID_SDK_PATH/ndk-bundle
ENV ANDROID_SDK_CMAKE $ANDROID_SDK_PATH/cmake/3.6.4111459/bin/cmake
# Install Android NDK
RUN curl -L -o android-ndk.zip http://dl.google.com/android/repository/android-ndk-r16b-linux-x86_64.zip && ${'\\'}
unzip -q android-ndk.zip -d /opt && ${'\\'}
rm -f android-ndk.zip
ENV ANDROID_NDK_PATH /opt/android-ndk-r16b
ENV ANDROID_NDK_HOME /opt/android-ndk-r16b
# Install gcloud
RUN curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-407.0.0-linux-x86_64.tar.gz && ${'\\'}
tar -xf google-cloud-cli-407.0.0-linux-x86_64.tar.gz && ${'\\'}
./google-cloud-sdk/install.sh --bash-completion=false --path-update=true && ${'\\'}
rm -rf google-cloud-cli-407.0.0-linux-x86_64.tar.gz
RUN ln -s /google-cloud-sdk/bin/gcloud /usr/local/bin/gcloud
# Define the default command.
CMD ["bash"]

@ -93,15 +93,31 @@ RUN apt-get update && apt-get -y install openjdk-8-jdk && apt-get clean
# Install Android SDK
ENV ANDROID_SDK_VERSION 4333796
RUN mkdir -p /opt/android-sdk && cd /opt/android-sdk && wget -q https://dl.google.com/android/repository/sdk-tools-linux-$ANDROID_SDK_VERSION.zip && unzip -q sdk-tools-linux-$ANDROID_SDK_VERSION.zip && rm sdk-tools-linux-$ANDROID_SDK_VERSION.zip
RUN mkdir -p /opt/android-sdk && cd /opt/android-sdk && \
wget -q https://dl.google.com/android/repository/sdk-tools-linux-$ANDROID_SDK_VERSION.zip && \
unzip -q sdk-tools-linux-$ANDROID_SDK_VERSION.zip && \
rm sdk-tools-linux-$ANDROID_SDK_VERSION.zip
ENV ANDROID_SDK_PATH /opt/android-sdk
ENV ANDROID_HOME /opt/android-sdk
RUN yes | $ANDROID_SDK_PATH/tools/bin/sdkmanager --licenses # accept all licenses
# Install Android NDK and cmake using sdkmanager
# Install ndk-bundle and cmake using sdkmanager
RUN mkdir -p ~/.android && touch ~/.android/repositories.cfg
RUN yes | $ANDROID_SDK_PATH/tools/bin/sdkmanager --licenses # accept all licenses
RUN $ANDROID_SDK_PATH/tools/bin/sdkmanager ndk-bundle 'cmake;3.6.4111459'
ENV ANDROID_NDK_PATH $ANDROID_SDK_PATH/ndk-bundle
ENV ANDROID_SDK_CMAKE $ANDROID_SDK_PATH/cmake/3.6.4111459/bin/cmake
# Install Android NDK
RUN curl -L -o android-ndk.zip http://dl.google.com/android/repository/android-ndk-r16b-linux-x86_64.zip && \
unzip -q android-ndk.zip -d /opt && \
rm -f android-ndk.zip
ENV ANDROID_NDK_PATH /opt/android-ndk-r16b
ENV ANDROID_NDK_HOME /opt/android-ndk-r16b
# Install gcloud
RUN curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-407.0.0-linux-x86_64.tar.gz && \
tar -xf google-cloud-cli-407.0.0-linux-x86_64.tar.gz && \
./google-cloud-sdk/install.sh --bash-completion=false --path-update=true && \
rm -rf google-cloud-cli-407.0.0-linux-x86_64.tar.gz
RUN ln -s /google-cloud-sdk/bin/gcloud /usr/local/bin/gcloud
# Define the default command.
CMD ["bash"]

@ -15,52 +15,11 @@
set -ex
# Accept the Android SDK licences.
yes | /opt/android-sdk/current/tools/bin/sdkmanager --licenses
# change to grpc repo root
# Enter the gRPC repo root
cd $(dirname $0)/../../..
REPO_ROOT="$(pwd)"
git submodule update --init
# Build protoc and grpc_cpp_plugin. Codegen is not cross-compiled to Android
mkdir -p cmake/build
pushd cmake/build
cmake -DgRPC_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release ../..
make protoc grpc_cpp_plugin -j2
popd
PROTOC=${REPO_ROOT}/cmake/build/third_party/protobuf/protoc
PLUGIN=${REPO_ROOT}/cmake/build/grpc_cpp_plugin
# Build and run interop instrumentation tests on Firebase Test Lab
cd "${REPO_ROOT}/src/android/test/interop/"
./gradlew assembleDebug \
"-Pprotoc=${PROTOC}" \
"-Pgrpc_cpp_plugin=${PLUGIN}"
./gradlew assembleDebugAndroidTest \
"-Pprotoc=${PROTOC}" \
"-Pgrpc_cpp_plugin=${PLUGIN}"
gcloud firebase test android run \
--type instrumentation \
--app app/build/outputs/apk/debug/app-debug.apk \
--test app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk \
--device model=Nexus6P,version=27,locale=en,orientation=portrait \
--device model=Nexus6P,version=26,locale=en,orientation=portrait \
--device model=Nexus6P,version=25,locale=en,orientation=portrait \
--device model=Nexus6P,version=24,locale=en,orientation=portrait \
--device model=Nexus6P,version=23,locale=en,orientation=portrait \
--device model=Nexus6,version=22,locale=en,orientation=portrait \
--device model=Nexus6,version=21,locale=en,orientation=portrait \
--device model=walleye,version=28,locale=en,orientation=portrait
# Build hello world example
source tools/internal_ci/helper_scripts/prepare_build_linux_rc
cd "${REPO_ROOT}/examples/android/helloworld"
./gradlew build \
"-Pprotoc=${PROTOC}" \
"-Pgrpc_cpp_plugin=${PLUGIN}"
export DOCKERFILE_DIR=tools/dockerfile/test/android_ndk
export DOCKER_RUN_SCRIPT=tools/internal_ci/linux/grpc_android_in_docker.sh
exec tools/run_tests/dockerize/build_and_run_docker.sh

@ -0,0 +1,62 @@
#!/usr/bin/env bash
# Copyright 2022 The gRPC Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -ex
# change to grpc repo root
cd $(dirname $0)/../../..
REPO_ROOT="$(pwd)"
# Build protoc and grpc_cpp_plugin. Codegen is not cross-compiled to Android
mkdir -p cmake/build
pushd cmake/build
cmake -DgRPC_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release ../..
make protoc grpc_cpp_plugin -j8
popd
PROTOC=${REPO_ROOT}/cmake/build/third_party/protobuf/protoc
PLUGIN=${REPO_ROOT}/cmake/build/grpc_cpp_plugin
# Build and run interop instrumentation tests on Firebase Test Lab
cd "${REPO_ROOT}/src/android/test/interop/"
./gradlew assembleDebug --parallel \
"-Pprotoc=${PROTOC}" \
"-Pgrpc_cpp_plugin=${PLUGIN}"
./gradlew assembleDebugAndroidTest \
"-Pprotoc=${PROTOC}" \
"-Pgrpc_cpp_plugin=${PLUGIN}"
# TODO(jtattermusch): make it easier to run this test locally
# under docker. The issue is that "gcloud firebase" requires being authenticated
# with gcloud first (while on CI we can rely on GCE default credentials).
gcloud firebase test android run \
--type instrumentation \
--app app/build/outputs/apk/debug/app-debug.apk \
--test app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk \
--device model=Nexus6P,version=27,locale=en,orientation=portrait \
--device model=Nexus6P,version=26,locale=en,orientation=portrait \
--device model=Nexus6P,version=25,locale=en,orientation=portrait \
--device model=Nexus6P,version=24,locale=en,orientation=portrait \
--device model=Nexus6P,version=23,locale=en,orientation=portrait \
--device model=Nexus6,version=22,locale=en,orientation=portrait \
--device model=Nexus6,version=21,locale=en,orientation=portrait \
--device model=walleye,version=28,locale=en,orientation=portrait
# Build hello world example
cd "${REPO_ROOT}/examples/android/helloworld"
./gradlew build \
"-Pprotoc=${PROTOC}" \
"-Pgrpc_cpp_plugin=${PLUGIN}"
Loading…
Cancel
Save