From 7e75fea461cd44957f42415f57d01b95d5e8856e Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 19 Oct 2026 02:38:13 +0000 Subject: [PATCH] Dockerfile for building the Android app The toolchain CI builds with (JDK 21, SDK platform 37, NDK 29, CMake 3.31.6, gawk for proot) on Ubuntu 24.04, plus the unit tests' host compilers and SSH tools. `docker build --target apk --output out .` gives the debug APK; the default target is an image to run Gradle in. The submodules come from the checked-out tree (D-Modem-RE is private). A proxy's CA can be given as a build secret, and HTTPS_PROXY is passed on to Java. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0172Hejd12i4aYikYW9vgpZs --- .dockerignore | 15 ++++++ .gitignore | 3 ++ Dockerfile | 106 +++++++++++++++++++++++++++++++++++++++++++ README.md | 9 ++++ docker/java-proxy.sh | 16 +++++++ 5 files changed, 149 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker/java-proxy.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..d78fa5f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,15 @@ +# what the Dockerfile's build doesn't need from the tree +.git +**/.git +.gradle +**/build +/build-host* +/build-fallback +/build-apple +**/.cxx +**/.kotlin +**/.build +.idea +local.properties +/out +ios/DModem/DModem.xcodeproj diff --git a/.gitignore b/.gitignore index ba4471d..b7555ae 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,6 @@ ios/DModem/Tunnel/DModemTunnel.entitlements .build/ # the native host build (cmake -S native-test -B build-host), or a link to one /build-host + +# the Dockerfile's APKs (docker build --target apk --output out .) +/out/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2a9ae88 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,106 @@ +# syntax=docker/dockerfile:1 +# SPDX-License-Identifier: AGPL-3.0-only +# Copyright (C) 2026 Neo-Desktop +# +# The Android app built in a container, with what CI builds it with +# (.github/workflows/android.yml): JDK 21, the SDK's platform 37, NDK 29, +# CMake 3.31.6, and gawk for proot; and for the unit tests, the host's +# compilers (the engine's host build, native-test) and the SSH tools. +# +# D-Modem-RE is a private submodule, so it isn't cloned here: check the +# submodules out first (git submodule update --init --recursive), and the +# build takes them from the tree. +# +# The debug APK, into ./out: +# docker build --target apk --output out . +# +# A shell with the toolchain and the source (the unit tests' tools too): +# docker build -t dmodem-android . +# docker run --rm -it dmodem-android sh -c \ +# 'cmake -S native-test -B build-host -G Ninja && cmake --build build-host && ./gradlew testDebugUnitTest' +# +# The release APK (unsigned): --build-arg TASK=assembleRelease +# +# Behind a proxy that re-signs TLS, its CA: +# --secret id=ca,src=/path/to/ca.crt (and --network host if it's local) + +ARG UBUNTU=24.04 + +FROM ubuntu:${UBUNTU} AS toolchain + +ARG CMDLINE_TOOLS=11076708 +ARG CMDLINE_TOOLS_SHA256=2d2d50857e4eb553af5a6dc3ad507a17adf43d115264b1afc116f95c92e5e258 +ARG PLATFORM=android-37.0 +ARG BUILD_TOOLS=36.0.0 +ARG NDK=29.0.14206865 +ARG CMAKE=3.31.6 + +ENV DEBIAN_FRONTEND=noninteractive \ + ANDROID_HOME=/opt/android-sdk \ + ANDROID_SDK_ROOT=/opt/android-sdk \ + GRADLE_USER_HOME=/root/.gradle \ + LANG=C.UTF-8 \ + LC_ALL=C.UTF-8 + +COPY docker/java-proxy.sh /etc/java-proxy.sh + +# the CA, if one's given, first: everything after fetches through it +RUN --mount=type=secret,id=ca,required=false \ + if [ -s /run/secrets/ca ]; then \ + mkdir -p /usr/local/share/ca-certificates && cp /run/secrets/ca /usr/local/share/ca-certificates/build-ca.crt; \ + fi \ + && apt-get update \ + && apt-get install -y --no-install-recommends \ + ca-certificates curl unzip git make gawk python3 \ + openjdk-21-jdk-headless \ + openssh-client openssh-server putty-tools mksh \ + cmake ninja-build g++ libssl-dev \ + && update-ca-certificates \ + && mkdir -p /run/sshd \ + && rm -rf /var/lib/apt/lists/* + +# the SDK: its command-line tools, then the packages the build uses +RUN . /etc/java-proxy.sh \ + && mkdir -p $ANDROID_HOME/cmdline-tools \ + && curl -fsSL -o /tmp/clt.zip https://dl.google.com/android/repository/commandlinetools-linux-${CMDLINE_TOOLS}_latest.zip \ + && echo "$CMDLINE_TOOLS_SHA256 /tmp/clt.zip" | sha256sum -c - \ + && unzip -q /tmp/clt.zip -d $ANDROID_HOME/cmdline-tools \ + && mv $ANDROID_HOME/cmdline-tools/cmdline-tools $ANDROID_HOME/cmdline-tools/latest \ + && rm /tmp/clt.zip \ + && yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses > /dev/null \ + && $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager \ + "platform-tools" "platforms;${PLATFORM}" "build-tools;${BUILD_TOOLS}" \ + "ndk;${NDK}" "cmake;${CMAKE}" > /dev/null + +ENV PATH=$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$PATH + +WORKDIR /src + +# Gradle itself and the dependencies, from the build files alone: a layer +# kept while only the source changes +COPY gradlew gradlew.bat settings.gradle.kts build.gradle.kts gradle.properties ./ +COPY gradle gradle +COPY app/build.gradle.kts app/proguard-rules.pro app/ +COPY shared/build.gradle.kts shared/ +RUN . /etc/java-proxy.sh \ + && (./gradlew --no-daemon -q help || true) + +FROM toolchain AS build +ARG TASK=assembleDebug +COPY . . +RUN test -f external/d-modem-re/CMakeLists.txt && test -f external/proot/src/GNUmakefile \ + || { echo "the submodules aren't checked out: git submodule update --init --recursive" >&2; exit 1; } +RUN . /etc/java-proxy.sh \ + && echo "sdk.dir=$ANDROID_HOME" > local.properties \ + && ./gradlew --no-daemon ${TASK} \ + && mkdir -p /out && find app/build/outputs/apk -name '*.apk' -exec cp {} /out/ \; + +# just the APKs: docker build --target apk --output out . +FROM scratch AS apk +COPY --from=build /out/ / + +# the default: the toolchain with the source, to run Gradle in +FROM toolchain +COPY . . +RUN echo "sdk.dir=$ANDROID_HOME" > local.properties +CMD ["./gradlew", "--no-daemon", "assembleDebug"] diff --git a/README.md b/README.md index 4bdf48c..e68fe6c 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,15 @@ for each ABI. `./gradlew connectedDebugAndroidTest` runs the instrumented tests on a device or emulator (the native library loads and answers AT commands). +Or in Docker, with the same toolchain as CI (the submodules checked out +first: the build takes them from the tree), the debug APK into `out/`: + + docker build --target apk --output out . + +`docker build -t dmodem-android .` makes an image with the toolchain and +the source to run Gradle in; the `Dockerfile` has the rest (a release +build, the unit tests, a proxy's CA). + The native library alone, without Gradle: cmake -S app/src/main/cpp -B build-arm64 -G Ninja \ diff --git a/docker/java-proxy.sh b/docker/java-proxy.sh new file mode 100644 index 0000000..81ad274 --- /dev/null +++ b/docker/java-proxy.sh @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: AGPL-3.0-only +# Copyright (C) 2026 Neo-Desktop +# +# Sourced by the Dockerfile's steps: an HTTPS_PROXY (Docker passes the +# usual proxy variables to a build) handed to Java as well, which doesn't +# read them (Gradle, sdkmanager). +p=${HTTPS_PROXY:-${https_proxy:-}} +if [ -n "$p" ]; then + hp=${p#*://} + hp=${hp#*@} + hp=${hp%%/*} + host=${hp%:*} + port=${hp##*:} + [ "$port" = "$hp" ] && port=443 + export JAVA_TOOL_OPTIONS="${JAVA_TOOL_OPTIONS:-} -Dhttps.proxyHost=$host -Dhttps.proxyPort=$port -Dhttp.proxyHost=$host -Dhttp.proxyPort=$port -Dhttp.nonProxyHosts=localhost|127.*" +fi