-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CI job for Flutter Android App (#158)
* add dockerfile for flutter android app Signed-off-by: Danil Uzlov <[email protected]> * add commands to build flutter android app Signed-off-by: Danil Uzlov <[email protected]> * add command to build flutter test for android Signed-off-by: Danil Uzlov <[email protected]> * add flutter-android cloudbuild Signed-off-by: Danil Uzlov <[email protected]> * add bazel remote cache support to flutter makefile Signed-off-by: Danil Uzlov <[email protected]> * fix test apk target Signed-off-by: Danil Uzlov <[email protected]> * adjust artifact output location Signed-off-by: Danil Uzlov <[email protected]> * fix python dependency in dockerfile Signed-off-by: Danil Uzlov <[email protected]> * use separate ndk layer in dockerfile Signed-off-by: Danil Uzlov <[email protected]> * fix android/test_apk make target Signed-off-by: Danil Uzlov <[email protected]> * fix docker flutter android apk make target Signed-off-by: Danil Uzlov <[email protected]> * fix result dir check in instrumented test Signed-off-by: Danil Uzlov <[email protected]> * refactor flutter android dockerfile Signed-off-by: Danil Uzlov <[email protected]> * fix test apks Signed-off-by: Danil Uzlov <[email protected]> * switch to e2 8core build machines Signed-off-by: Danil Uzlov <[email protected]> * refactor cloudbuild files Signed-off-by: Danil Uzlov <[email protected]> * remove docker buildkit Signed-off-by: Danil Uzlov <[email protected]> * fix typo * fix release apk upload Signed-off-by: Danil Uzlov <[email protected]> * add comments Signed-off-by: Danil Uzlov <[email protected]> * fix envs in dockerfile Signed-off-by: Danil Uzlov <[email protected]> * add proper docker image build command Signed-off-by: Danil Uzlov <[email protected]> * adjust gitignore Signed-off-by: Danil Uzlov <[email protected]> * fix formatting Signed-off-by: Danil Uzlov <[email protected]> * fix linter Signed-off-by: Danil Uzlov <[email protected]> * add ANDROID_NDK_HOME to dockerfile Signed-off-by: Danil Uzlov <[email protected]> * fix image tag in docker/android/apk command Signed-off-by: Danil Uzlov <[email protected]> * fix typo Signed-off-by: Danil Uzlov <[email protected]>
- Loading branch information
Showing
9 changed files
with
255 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
substitutions: | ||
_IMAGE_NAME: mlperf-mobile-flutter-android | ||
# Building apks with flutter requires a lot of memory. | ||
# Builds on standard machines with 4GB of RAM can unexpectedly hang. | ||
# Also the build is mostly CPU-intensive, so using 8-core machines | ||
# reduces build time up to 3 times. | ||
options: | ||
machineType: 'E2_HIGHCPU_8' | ||
|
||
steps: | ||
# We need this step to correctly identify dockerfile tag | ||
- id: fetch-repo-history | ||
name: gcr.io/cloud-builders/git | ||
timeout: 10s | ||
args: | ||
- fetch | ||
- --unshallow | ||
# Download DOCKERFILE_COMMIT tag if it exists to skip docker image generation, | ||
# or download the :latest tag and use it as a cache, | ||
# or skip downloading if :latest doesn't exist yet. | ||
# This being a separate step helps readability in Cloud Build console. | ||
- id: cache-old-image | ||
name: gcr.io/cloud-builders/docker | ||
timeout: 600s # 10 minutes | ||
entrypoint: bash | ||
args: | ||
- -xc | ||
- | | ||
DOCKERFILE_COMMIT=$$(git log -n 1 --pretty=format:%H -- flutter/android/docker/Dockerfile) | ||
docker pull gcr.io/$PROJECT_ID/$_IMAGE_NAME:$$DOCKERFILE_COMMIT \ | ||
|| docker pull gcr.io/$PROJECT_ID/$_IMAGE_NAME:latest \ | ||
|| true | ||
# This step overrides the :latest tag of the image, so that we can use it in later steps. | ||
- id: build-new-image | ||
name: gcr.io/cloud-builders/docker | ||
timeout: 1800s # 30 minutes | ||
entrypoint: bash | ||
args: | ||
- -xc | ||
- | | ||
DOCKERFILE_COMMIT=$$(git log -n 1 --pretty=format:%H -- flutter/android/docker/Dockerfile) | ||
docker build \ | ||
-t gcr.io/$PROJECT_ID/$_IMAGE_NAME:$$DOCKERFILE_COMMIT \ | ||
-t gcr.io/$PROJECT_ID/$_IMAGE_NAME:latest \ | ||
--cache-from gcr.io/$PROJECT_ID/$_IMAGE_NAME:$$DOCKERFILE_COMMIT \ | ||
--cache-from gcr.io/$PROJECT_ID/$_IMAGE_NAME:latest \ | ||
flutter/android/docker | ||
# If the build fails artifacts are not uploaded automatically, so we save them manually before build | ||
- id: push-new-image | ||
name: gcr.io/cloud-builders/docker | ||
timeout: 1800s # 30 minutes | ||
entrypoint: bash | ||
args: | ||
- -xc | ||
- | | ||
DOCKERFILE_COMMIT=$$(git log -n 1 --pretty=format:%H -- flutter/android/docker/Dockerfile) | ||
docker push gcr.io/$PROJECT_ID/$_IMAGE_NAME:$$DOCKERFILE_COMMIT | ||
docker push gcr.io/$PROJECT_ID/$_IMAGE_NAME:latest | ||
- id: build-apks | ||
name: gcr.io/$PROJECT_ID/$_IMAGE_NAME:latest | ||
# Image upload usually takes only few seconds. | ||
# However, if we generated a new image and the build failed, it can cancel the upload. | ||
# Let's wait for the upload to finish before starting the actual build. | ||
waitFor: [] | ||
timeout: 10800s # 3 hours | ||
entrypoint: bash | ||
env: | ||
- BAZEL_CACHE_ARG=--remote_cache=https://storage.googleapis.com/$_BAZEL_CACHE_BUCKET --google_default_credentials | ||
args: | ||
- -xc | ||
- | | ||
cd flutter || exit $? | ||
make ci/android/test_apk || exit $? | ||
mkdir -p /workspace/output/artifacts || exit $? | ||
cp /workspace/flutter/build/app/outputs/flutter-apk/app-release.apk /workspace/output/artifacts/mlperf_app_release.apk || exit $? | ||
cp /workspace/flutter/build/app/outputs/apk/debug/app-debug.apk /workspace/output/artifacts/mlperf_app_test_main.apk || exit $? | ||
cp /workspace/flutter/build/app/outputs/apk/androidTest/debug/app-debug-androidTest.apk /workspace/output/artifacts/mlperf_app_test_helper.apk || exit $? | ||
- id: instrument-test-on-firebase | ||
name: gcr.io/cloud-builders/gcloud | ||
waitFor: | ||
- build-apks | ||
timeout: 3600s # 1 hour | ||
entrypoint: bash | ||
args: | ||
- -xc | ||
- | | ||
# redfin is Pixel 5e | ||
gcloud firebase test android run \ | ||
--type instrumentation \ | ||
--app output/artifacts/mlperf_app_test_main.apk \ | ||
--test output/artifacts/mlperf_app_test_helper.apk \ | ||
--timeout 45m \ | ||
--device model=redfin,version=30,locale=en,orientation=portrait | ||
- id: crawler-test-on-firebase | ||
name: gcr.io/cloud-builders/gcloud | ||
waitFor: | ||
- build-apks | ||
timeout: 3600s # 1 hour | ||
entrypoint: bash | ||
args: | ||
- -xc | ||
- | | ||
# x1q is SM-G981U1 (Samsung Galaxy S20 5G) | ||
gcloud firebase test android run \ | ||
--type robo \ | ||
--app output/artifacts/mlperf_app_release.apk \ | ||
--device model=x1q,version=29,locale=en,orientation=portrait \ | ||
--timeout 90s | ||
# We uploaded both tags earlier, but this option also adds them to the artifacts page of the build | ||
images: | ||
- gcr.io/$PROJECT_ID/$_IMAGE_NAME | ||
|
||
artifacts: | ||
objects: | ||
location: gs://$_ARTIFACT_BUCKET/$_ARTIFACT_FOLDER/$COMMIT_SHA-flutter | ||
paths: | ||
- output/artifacts/mlperf_app_release.apk | ||
- output/artifacts/mlperf_app_test_main.apk | ||
- output/artifacts/mlperf_app_test_helper.apk | ||
|
||
timeout: 18000s # 5 hours |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ key.properties | |
**/*.jks | ||
|
||
/app/src/main/jniLibs/ | ||
.kotlin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
.../android/app/src/androidTest/java/org/mlcommons/android/mlperfbench/MainActivityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.mlcommons.android.mlperfbench; | ||
|
||
import androidx.test.rule.ActivityTestRule; | ||
import dev.flutter.plugins.integration_test.FlutterTestRunner; | ||
import org.junit.Rule; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(FlutterTestRunner.class) | ||
public class MainActivityTest { | ||
@Rule | ||
public ActivityTestRule<MainActivity> rule = | ||
new ActivityTestRule<>(MainActivity.class, true, false); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
FROM ubuntu:20.04 | ||
|
||
# Without DEBIAN_FRONTEND=noninteractive arg apt-get waits for user input. | ||
# Docker desktop shows all previously defined args for each of the commands, | ||
# which makes reading layer info harder, so we set this env for for individual commands only. | ||
# JDK package downloads ~500 MB from slow mirrors, which can take a lot of time, | ||
# so a separate layer for it makes image rebuild faster in case we change any other dependencies. | ||
RUN apt-get update >/dev/null && DEBIAN_FRONTEND=noninteractive apt-get install -y openjdk-8-jdk-headless | ||
RUN apt-get update >/dev/null && DEBIAN_FRONTEND=noninteractive apt-get install -y \ | ||
apt-transport-https \ | ||
curl \ | ||
git \ | ||
gnupg \ | ||
make \ | ||
protobuf-compiler \ | ||
python3 \ | ||
python3-pip | ||
RUN ln -s /usr/bin/python3 /usr/bin/python | ||
RUN python3 -m pip install numpy absl-py | ||
|
||
# Bazel is not present in standard repositories | ||
RUN curl -L https://bazel.build/bazel-release.pub.gpg | apt-key add - && \ | ||
echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list && \ | ||
apt-get update >/dev/null && DEBIAN_FRONTEND=noninteractive apt-get install -y bazel=4.2.1 | ||
|
||
ENV ANDROID_SDK_ROOT=/opt/android | ||
WORKDIR $ANDROID_SDK_ROOT/cmdline-tools | ||
# sdkmanager expects to be placed into `$ANDROID_SDK_ROOT/cmdline-tools/tools` | ||
RUN curl -L https://dl.google.com/android/repository/commandlinetools-linux-7583922_latest.zip | jar x && \ | ||
mv cmdline-tools tools && \ | ||
chmod --recursive +x tools/bin | ||
ENV PATH=$PATH:$ANDROID_SDK_ROOT/cmdline-tools/tools/bin | ||
|
||
RUN yes | sdkmanager --licenses >/dev/null | ||
# Build tools 29.0.2 are required by Flutter 2.5.3 | ||
# Build tools 30 are required by bazel 4.2.1 | ||
RUN yes | sdkmanager \ | ||
"tools" \ | ||
"platform-tools" \ | ||
"build-tools;29.0.2" \ | ||
"build-tools;30.0.3" \ | ||
"platforms;android-30" | ||
# Install NDK in a separate layer to decrease max layer size. | ||
RUN yes | sdkmanager "ndk;21.4.7075529" | ||
ENV ANDROID_NDK_ROOT=$ANDROID_SDK_ROOT/ndk/21.4.7075529 | ||
ENV ANDROID_NDK_HOME=$ANDROID_NDK_ROOT | ||
|
||
ENV HOME=/image-workdir | ||
WORKDIR $HOME | ||
|
||
ENV PUB_CACHE=$HOME/flutter/.pub-cache | ||
ENV PATH=$PATH:$HOME/flutter/bin:$PUB_CACHE/bin | ||
RUN curl -L https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_2.5.3-stable.tar.xz | tar Jxf - | ||
RUN dart pub global activate protoc_plugin | ||
|
||
ENV GRADLE_USER_HOME=$HOME/.gradle | ||
ENV ANDROID_SDK_HOME=$HOME/.android | ||
|
||
RUN mkdir $ANDROID_SDK_HOME && \ | ||
keytool -genkey -v -keystore $ANDROID_SDK_HOME/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US" | ||
|
||
RUN chmod --recursive a=u $HOME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters