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