mirror of
https://github.com/juanfont/headscale.git
synced 2026-11-24 22:26:29 +09:00
Headless KVM emulator (google_apis, API 33) plus a small helper app: a device-owner DPC that sets the Tailscale app's managed configuration, and a probe that resolves and fetches as an ordinary app, through the VPN. Updates tailscale/tailscale#15660
82 lines
3.3 KiB
Docker
82 lines
3.3 KiB
Docker
# Android emulator for integration tests (integration/androidic).
|
|
# Adapted from tailscale-android docker/Dockerfile.android-integration
|
|
# (Copyright (c) Tailscale Inc & AUTHORS, BSD-3-Clause).
|
|
#
|
|
# Needs a host with /dev/kvm; the container must run with --device /dev/kvm.
|
|
|
|
FROM --platform=linux/amd64 eclipse-temurin:21-jdk-noble
|
|
|
|
ARG ANDROID_API=33
|
|
ARG ANDROID_CMDLINE_TOOLS_VERSION=9477386
|
|
ARG ANDROID_BUILD_TOOLS=34.0.0
|
|
|
|
ENV ANDROID_HOME=/opt/android-sdk
|
|
ENV ANDROID_SDK_ROOT=/opt/android-sdk
|
|
ENV ANDROID_AVD_HOME=/root/.android/avd
|
|
ENV PATH=$PATH:/opt/android-sdk/cmdline-tools/latest/bin:/opt/android-sdk/platform-tools:/opt/android-sdk/emulator
|
|
|
|
RUN apt-get -o Acquire::Retries=5 update && \
|
|
apt-get -o Acquire::Retries=5 -y install --no-install-recommends \
|
|
ca-certificates \
|
|
curl \
|
|
libdbus-1-3 \
|
|
libfontconfig1 \
|
|
libgl1 \
|
|
libglib2.0-0 \
|
|
libnss3 \
|
|
libpulse0 \
|
|
libstdc++6 \
|
|
libvulkan1 \
|
|
libx11-6 \
|
|
libxcb-cursor0 \
|
|
libxcb1 \
|
|
libxext6 \
|
|
libxi6 \
|
|
libxrender1 \
|
|
libxtst6 \
|
|
unzip \
|
|
zip && \
|
|
apt-get -y clean && \
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
RUN mkdir -p /opt/android-sdk/cmdline-tools /tmp/android-sdk && \
|
|
curl -fsSL -o /tmp/android-sdk/commandlinetools.zip \
|
|
"https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_CMDLINE_TOOLS_VERSION}_latest.zip" && \
|
|
unzip -q /tmp/android-sdk/commandlinetools.zip -d /tmp/android-sdk && \
|
|
mv /tmp/android-sdk/cmdline-tools /opt/android-sdk/cmdline-tools/latest && \
|
|
rm -rf /tmp/android-sdk
|
|
|
|
RUN yes | sdkmanager --licenses >/dev/null && \
|
|
sdkmanager \
|
|
"build-tools;${ANDROID_BUILD_TOOLS}" \
|
|
"emulator" \
|
|
"platform-tools" \
|
|
"platforms;android-${ANDROID_API}" \
|
|
"system-images;android-${ANDROID_API};google_apis;x86_64"
|
|
|
|
RUN mkdir -p /root/.android && touch /root/.android/repositories.cfg && \
|
|
echo "no" | avdmanager create avd -n test \
|
|
-k "system-images;android-${ANDROID_API};google_apis;x86_64" --device pixel
|
|
|
|
# Test helper app: MDM device policy controller and in-VPN probe.
|
|
COPY integration/androidic/helper /tmp/helper
|
|
RUN cd /tmp/helper && \
|
|
bt=/opt/android-sdk/build-tools/${ANDROID_BUILD_TOOLS} && \
|
|
jar=/opt/android-sdk/platforms/android-${ANDROID_API}/android.jar && \
|
|
$bt/aapt2 compile --dir res -o res.zip && \
|
|
$bt/aapt2 link -I $jar --manifest AndroidManifest.xml -o unsigned.apk res.zip && \
|
|
javac --release 11 -classpath $jar -d classes $(find src -name '*.java') && \
|
|
$bt/d8 --lib $jar --release --output . $(find classes -name '*.class') && \
|
|
zip -q unsigned.apk classes.dex && \
|
|
$bt/zipalign -f 4 unsigned.apk aligned.apk && \
|
|
keytool -genkeypair -keystore k.jks -storepass android -keypass android \
|
|
-alias k -keyalg RSA -dname CN=helper -validity 10000 && \
|
|
$bt/apksigner sign --ks k.jks --ks-pass pass:android --out /opt/helper.apk aligned.apk && \
|
|
rm -rf /tmp/helper
|
|
|
|
# Headless boot; slirp NAT lets the guest reach the container's docker
|
|
# network. -no-snapshot keeps every test on a cold, clean device.
|
|
CMD ["emulator", "-avd", "test", "-no-window", "-no-audio", "-no-snapshot", \
|
|
"-no-boot-anim", "-gpu", "swiftshader_indirect", "-memory", "4096", "-cores", "4", \
|
|
"-netdelay", "none", "-netspeed", "full"]
|