| c8917cf1 Andy McCall ↶ |
1 |
# The OxygenFlow Android image (oxygenflow#19): a JDK, the Android SDK and |
| 2 |
# NDK, Gradle, cargo-ndk, the crates and Gradle dependencies of the |
| 3 |
# OxygenHub app, so its build and tests run in a job with no network. |
| 4 |
# Built by ./build.sh, which fetches and checks the downloads first. |
| 5 |
FROM rust:1.97.1-slim-bookworm |
| 6 |
|
| 7 |
RUN apt-get update \ |
| 8 |
&& apt-get install -y --no-install-recommends ca-certificates openjdk-17-jdk-headless unzip make git pkg-config \ |
| 9 |
&& rm -rf /var/lib/apt/lists/* |
| 10 |
|
| 11 |
# The guest's PATH is fixed and has no /usr/local/cargo/bin, and a rustup |
| 12 |
# proxy would need RUSTUP_HOME: link the toolchain's own binaries instead. |
| 13 |
RUN rustup target add aarch64-linux-android x86_64-linux-android \ |
| 14 |
&& cargo install --locked --version 4.1.2 --root /opt/cargo-ndk cargo-ndk \ |
| 15 |
&& rm -rf /usr/local/cargo/registry /usr/local/cargo/git \ |
| 16 |
&& tc=$(ls -d /usr/local/rustup/toolchains/*/ | head -1) \ |
| 17 |
&& for b in cargo rustc rustdoc; do ln -sf "$tc/bin/$b" /usr/local/bin/$b; done \ |
| 18 |
&& ln -sf /opt/cargo-ndk/bin/cargo-ndk /usr/local/bin/cargo-ndk |
| 19 |
|
| 20 |
# The SDK: Google's command-line tools (checked by build.sh), then the |
| 21 |
# platform, build tools and NDK the app names, licences accepted here. |
| 22 |
ENV ANDROID_HOME=/opt/android-sdk JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 |
| 23 |
COPY dl/cmdline-tools.zip /tmp/cmdline-tools.zip |
| 24 |
RUN mkdir -p "$ANDROID_HOME/cmdline-tools" \ |
| 25 |
&& unzip -q /tmp/cmdline-tools.zip -d /tmp/ct \ |
| 26 |
&& mv /tmp/ct/cmdline-tools "$ANDROID_HOME/cmdline-tools/latest" \ |
| 27 |
&& rm -rf /tmp/ct /tmp/cmdline-tools.zip \ |
| 28 |
&& yes | "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" --licenses >/dev/null \ |
| 29 |
&& "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" --install \ |
| 30 |
"platforms;android-37.0" "build-tools;36.0.0" "ndk;30.0.16248370" >/dev/null |
| 31 |
|
| 32 |
# Gradle itself (checked by build.sh): jobs run `gradle`, not the wrapper, |
| 33 |
# which would download its distribution. |
| 34 |
ARG GRADLE_VERSION |
| 35 |
COPY dl/gradle.zip /tmp/gradle.zip |
| 36 |
RUN unzip -q /tmp/gradle.zip -d /opt && rm /tmp/gradle.zip \ |
| 37 |
&& ln -sf /opt/gradle-${GRADLE_VERSION}/bin/gradle /usr/local/bin/gradle |
| 38 |
|
| 39 |
# The app's crates, vendored: cargo reads /.cargo/config.toml for any |
| 40 |
# directory under /, so rust-core builds offline. |
| 41 |
COPY vendor /opt/vendor |
| 42 |
COPY cargo-config.toml /.cargo/config.toml |
| 43 |
|
| 44 |
# Gradle's dependencies: build the app once here, with the network, and |
| 45 |
# keep what Gradle fetched as a read-only cache (GRADLE_RO_DEP_CACHE) that |
| 46 |
# a job's own, writable GRADLE_USER_HOME reads first. A failing test does |
| 47 |
# not matter here; only the downloads do. |
| 48 |
COPY app /tmp/app |
| 49 |
RUN cd /tmp/app \ |
| 50 |
&& printf 'sdk.dir=%s\n' "$ANDROID_HOME" > local.properties \ |
| 51 |
&& (GRADLE_USER_HOME=/opt/gradle-home gradle --no-daemon -q --continue \ |
| 52 |
:app:assembleDebug :app:testDebugUnitTest :app:lintDebug :app:validateDebugScreenshotTest || true) \ |
| 53 |
&& test -d /opt/gradle-home/caches/modules-2 \ |
| 54 |
&& cd / && rm -rf /tmp/app /opt/gradle-home/daemon /opt/gradle-home/native /opt/gradle-home/wrapper \ |
| 55 |
/opt/gradle-home/caches/[0-9]* /opt/gradle-home/caches/transforms-* /opt/gradle-home/caches/build-cache-* \ |
| 56 |
/opt/gradle-home/caches/journal-* /opt/gradle-home/caches/jars-* \ |
| 57 |
&& rm -f /opt/gradle-home/caches/modules-2/*.lock /opt/gradle-home/caches/modules-2/gc.properties \ |
| 58 |
&& chmod -R a+rX /opt/gradle-home "$ANDROID_HOME" /opt/vendor |