# syntax=docker/dockerfile:1 # # Android APKs (docs/building.md, docs/android.md): a debug APK, installable # as is, for arm64-v8a and x86_64 (emulators). # # docker build --ssh default -f docker/android.Dockerfile -o dist/android . # docker build --ssh default -f docker/android.Dockerfile --build-arg ABIS=arm64-v8a -o dist/android . # # or scripts/docker-build.sh android. --ssh default hands the build your # ssh-agent, which must hold a key that can read the private VoelinProtocol # repository (docs/building.md, "Depending on VoelinProtocol"). A signed # release APK needs your keystore (docs/release.md), passed as build secrets: # # docker build --ssh default -f docker/android.Dockerfile --build-arg APK=release \ # --secret id=keystore,src=release.jks --secret id=signing,src=signing.env \ # -o dist/android . # # signing.env holds VOELIN_SIGNING_STORE_PASSWORD, VOELIN_SIGNING_KEY_ALIAS and # VOELIN_SIGNING_KEY_PASSWORD lines (NAME=value). Without them a release APK is # unsigned. FROM ubuntu:24.04 AS toolchain ARG DEBIAN_FRONTEND=noninteractive # JDK 17 (Gradle, the Android Gradle plugin), CMake + Ninja (the bundled libopus). RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential ca-certificates cmake curl git ninja-build openjdk-17-jdk-headless \ openssh-client pkg-config python3 unzip \ && rm -rf /var/lib/apt/lists/* # Extra CA certificates (PEM, one or more), for building behind a # TLS-inspecting proxy; scripts/docker-build.sh passes $BUILD_CA_CERT as this # secret. One file per certificate, so the Java truststore gets each one too. RUN --mount=type=secret,id=ca,required=false \ if [ -s /run/secrets/ca ]; then \ awk '/-----BEGIN CERTIFICATE-----/ { n++ } n { print > ("/usr/local/share/ca-certificates/build-ca-" n ".crt") }' \ /run/secrets/ca \ && update-ca-certificates; \ fi # Java tools do not read HTTPS_PROXY: turn it into JVM properties for # sdkmanager and Gradle when it is set (GRADLE_OPTS for the wrapper's JVM, # -D arguments for the build JVM). COPY <<-'EOF' /usr/local/bin/java-proxy-opts #!/bin/sh p=${HTTPS_PROXY:-${https_proxy:-}} [ -n "$p" ] || exit 0 hp=${p#*://}; hp=${hp%%/*}; hp=${hp##*@} echo "-Dhttps.proxyHost=${hp%:*} -Dhttps.proxyPort=${hp##*:} -Dhttp.proxyHost=${hp%:*} -Dhttp.proxyPort=${hp##*:}" EOF RUN chmod +x /usr/local/bin/java-proxy-opts # The SDK packages the release workflow installs (.github/workflows/release.yml, # package-android job). ENV ANDROID_HOME=/opt/android-sdk ARG CMDLINE_TOOLS=commandlinetools-linux-16111833_latest.zip ARG CMDLINE_TOOLS_SHA1=e025545c62a8e64c7559119566a569fb1dec5f60 ARG NDK_VERSION=27.3.13750724 RUN curl -sSfL -o /tmp/tools.zip "https://dl.google.com/android/repository/$CMDLINE_TOOLS" \ && echo "$CMDLINE_TOOLS_SHA1 /tmp/tools.zip" | sha1sum -c - \ && mkdir -p "$ANDROID_HOME/cmdline-tools" \ && unzip -q /tmp/tools.zip -d "$ANDROID_HOME/cmdline-tools" \ && mv "$ANDROID_HOME/cmdline-tools/cmdline-tools" "$ANDROID_HOME/cmdline-tools/latest" \ && rm /tmp/tools.zip \ && export JAVA_OPTS="$(java-proxy-opts)" \ && yes | "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" --licenses >/dev/null \ && "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" \ "ndk;$NDK_VERSION" "platforms;android-36" "build-tools;36.0.0" >/dev/null ENV ANDROID_NDK_HOME=$ANDROID_HOME/ndk/$NDK_VERSION ANDROID_NDK_ROOT=$ANDROID_HOME/ndk/$NDK_VERSION ENV RUSTUP_HOME=/usr/local/rustup CARGO_HOME=/usr/local/cargo PATH=/usr/local/cargo/bin:$PATH COPY rust-toolchain.toml /tmp/toolchain/ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \ | sh -s -- -y --no-modify-path --profile minimal --default-toolchain none \ && cd /tmp/toolchain && rustup toolchain install \ && rustup target add --toolchain "$(sed -n 's/^channel = "\(.*\)"/\1/p' rust-toolchain.toml)" \ aarch64-linux-android x86_64-linux-android armv7-linux-androideabi \ && cargo install --locked cargo-ndk --version 4.1.2 \ && rm -rf "$CARGO_HOME/registry" FROM toolchain AS build # Comma-separated Android ABIs: arm64-v8a, x86_64, armeabi-v7a. ARG ABIS=arm64-v8a,x86_64 # debug (installable as is) or release (signed with the build secrets). ARG APK=debug # BuildKit secrets do not invalidate cached RUN steps. A signed CI build # supplies a fresh non-secret nonce so a rotated key cannot reuse an old APK. ARG SIGNING_CACHE_BUST=unsigned WORKDIR /src # voelin-identity comes from the private VoelinProtocol repository, fetched # over SSH by Cargo through the system git, with the agent that # `docker build --ssh default` forwards (scripts/docker-build.sh passes it): # the key stays in the agent and never reaches a layer. The host key is the # reviewed line from .gitea/known_hosts. Cargo resolves the whole workspace, so # the first cargo command needs this: the `cargo fetch` below, the only step # that is given the agent. COPY .gitea/known_hosts /etc/ssh/ssh_known_hosts ENV CARGO_NET_GIT_FETCH_WITH_CLI=true COPY . . # Only this step is given the agent, and it only fetches (the packages of every # target, so the Android ones too): no build script, procedural macro or test of # the workspace runs in it. The build below has no ssh mount (so no agent socket # and no key in reach of the code it compiles and runs). RUN --mount=type=ssh,required=true \ --mount=type=cache,id=voelin-cargo-registry,target=/usr/local/cargo/registry \ cargo fetch --locked # Gradle starts cargo-ndk, which starts cargo: the variable makes every one of # them offline, as `--offline` does for the other Dockerfiles (the Gradle task # is left as it is, because a developer's own build has network and no # `cargo fetch`). The build uses what the step above fetched (the registry in # the cache mount shared with it, the git checkout of VoelinProtocol in its # layer) or fails. ENV CARGO_NET_OFFLINE=true RUN --mount=type=cache,id=voelin-cargo-registry,target=/usr/local/cargo/registry \ --mount=type=cache,id=voelin-target-android,target=/src/target \ --mount=type=cache,id=voelin-gradle,target=/root/.gradle \ --mount=type=secret,id=keystore,required=false \ --mount=type=secret,id=signing,required=false \ set -e; : "$SIGNING_CACHE_BUST"; \ if [ "$APK" = release ] && [ -f /run/secrets/keystore ]; then \ export VOELIN_SIGNING_STORE_FILE=/run/secrets/keystore; \ set -a; . /run/secrets/signing; set +a; \ fi; \ proxy="$(java-proxy-opts)"; \ export GRADLE_OPTS="$proxy"; \ task="assemble$(echo "$APK" | sed 's/./\U&/')"; \ (cd android && ./gradlew --no-daemon $proxy "$task" -Pvoelin.abis="$ABIS") \ && scripts/package.sh android /out FROM scratch AS artifacts COPY --from=build /out /