Optimized Android images and replaced redir by Socat

This commit is contained in:
Halim Qarroum
2023-03-14 16:54:48 +00:00
parent f83cb18032
commit 7a3b901e16
4 changed files with 28 additions and 1182 deletions
+11 -18
View File
@@ -5,28 +5,20 @@ LABEL maintainer "Halim Qarroum <hqm.post@gmail.com>"
LABEL description "A Docker image allowing to run an Android emulator"
LABEL version "1.0.0"
# `redir.c` will be used to redirect
# localhost ADB ports to the container interface.
COPY deps/redir/redir.c /usr/src/redir.c
# Installing required packages.
RUN apk update && \
apk upgrade && \
apk add --no-cache \
alpine-sdk \
bash \
unzip \
wget \
libvirt-daemon \
dbus \
polkit \
socat \
virt-manager && \
# Compile `redir`.
gcc /usr/src/redir.c -o /usr/bin/redir && \
strip /usr/bin/redir && \
# Cleanup APK.
apk del alpine-sdk && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /var/cache/apk/*
rm -rf /tmp/* /var/tmp/* /var/cache/apk/*
# Arguments that can be overriden at build-time.
ARG INSTALL_ANDROID_SDK=1
@@ -49,7 +41,7 @@ ENV ANDROID_SDK_ROOT=/opt/android \
QTWEBENGINE_DISABLE_SANDBOX=1 \
ANDROID_EMULATOR_WAIT_TIME_BEFORE_KILL=10
# Exporting environment variables for keeping in the path
# Exporting environment variables to keep in the path
# Android SDK binaries and shared libraries.
ENV PATH "${PATH}:${ANDROID_SDK_ROOT}/platform-tools"
ENV PATH "${PATH}:${ANDROID_SDK_ROOT}/emulator"
@@ -70,16 +62,17 @@ RUN mkdir /root/.android/ && \
# Exporting ADB keys.
COPY keys/* /root/.android/
# Copy the startup scripts.
COPY scripts/* /opt/
# Make the scripts executable.
RUN chmod +x /opt/*.sh
# This layer will download the Android command-line tools
# The following layers will download the Android command-line tools
# to install the Android SDK, emulator and system images.
# It will then install the Android SDK and emulator.
COPY scripts/install-sdk.sh /opt/
RUN chmod +x /opt/install-sdk.sh
RUN /opt/install-sdk.sh
# Copy the container scripts in the image.
COPY scripts/start-emulator.sh /opt/
COPY scripts/emulator-monitoring.sh /opt/
RUN chmod +x /opt/*.sh
# Set the entrypoint
ENTRYPOINT ["/opt/start-emulator.sh"]
+11 -18
View File
@@ -1,34 +1,26 @@
FROM nvidia/cuda:12.1.0-runtime-ubuntu22.04
FROM nvidia/cuda:12.1.0-base-ubuntu22.04
# Docker labels.
LABEL maintainer "Halim Qarroum <hqm.post@gmail.com>"
LABEL description "A Docker image allowing to run an Android emulator"
LABEL version "1.1.0"
# `redir.c` will be used to redirect
# localhost ADB ports to the container interface.
COPY deps/redir/redir.c /usr/src/redir.c
# Installing required packages.
RUN apt update -y && \
apt install -y --no-install-recommends \
build-essential \
DEBIAN_FRONTEND=noninteractive apt install -y --no-install-recommends \
bash \
unzip \
wget \
libvirt-daemon \
dbus \
openjdk-11-jdk \
ca-certificates-java \
virt-manager \
libvulkan1 \
xvfb \
libgl1-mesa-glx \
libgl1-mesa-dri \
socat \
iproute2 && \
# Compile `redir`.
gcc /usr/src/redir.c -o /usr/bin/redir && \
strip /usr/bin/redir && \
rm -rf /var/lib/apt/lists/*
# Arguments that can be overriden at build-time.
@@ -73,16 +65,17 @@ RUN mkdir /root/.android/ && \
# Exporting ADB keys.
COPY keys/* /root/.android/
# Copy the startup scripts.
COPY scripts/* /opt/
# Make the scripts executable.
RUN chmod +x /opt/*.sh
# This layer will download the Android command-line tools
# The following layers will download the Android command-line tools
# to install the Android SDK, emulator and system images.
# It will then install the Android SDK and emulator.
COPY scripts/install-sdk.sh /opt/
RUN chmod +x /opt/install-sdk.sh
RUN /opt/install-sdk.sh
# Copy the container scripts in the image.
COPY scripts/start-emulator.sh /opt/
COPY scripts/emulator-monitoring.sh /opt/
RUN chmod +x /opt/*.sh
# Set the entrypoint
ENTRYPOINT ["/opt/start-emulator.sh"]
-1140
View File
File diff suppressed because it is too large Load Diff
+6 -6
View File
@@ -13,10 +13,11 @@ ADB_PORT=5555
echo "Starting the ADB server ..."
adb -a -P 5037 server nodaemon &
# Detect ip and forward ADB ports outside to outside interface
ip=$(ip addr list eth0 | grep "inet " | cut -d' ' -f6 | cut -d/ -f1)
redir --laddr="$ip" --lport="$EMULATOR_CONSOLE_PORT" --caddr=127.0.0.1 --cport="$EMULATOR_CONSOLE_PORT" &
redir --laddr="$ip" --lport="$ADB_PORT" --caddr=127.0.0.1 --cport="$ADB_PORT" &
# Detect ip and forward ADB ports from the container's network
# interface to localhost.
LOCAL_IP=$(ip addr list eth0 | grep "inet " | cut -d' ' -f6 | cut -d/ -f1)
socat tcp-listen:"$EMULATOR_CONSOLE_PORT",bind="$LOCAL_IP",fork tcp:127.0.0.1:"$EMULATOR_CONSOLE_PORT" &
socat tcp-listen:"$ADB_PORT",bind="$LOCAL_IP",fork tcp:127.0.0.1:"$ADB_PORT" &
export USER=root
@@ -39,7 +40,7 @@ if [ "$GPU_ACCELERATED" == "true" ]; then
export GPU_MODE="host"
Xvfb "$DISPLAY" -screen 0 1920x1080x16 -nolisten tcp &
else
export GPU_MODE="auto"
export GPU_MODE="swiftshader_indirect"
fi
# Asynchronously write updates on the standard output
@@ -49,7 +50,6 @@ wait_for_boot &
# Start the emulator with no audio, no GUI, and no snapshots.
echo "Starting the emulator ..."
emulator \
-verbose \
-avd android \
-gpu "$GPU_MODE" \
-no-boot-anim \