mirror of
https://github.com/HQarroum/docker-android.git
synced 2026-07-15 06:47:07 +02:00
Update the build process to build CUDA images
This commit is contained in:
@@ -5,6 +5,7 @@ on:
|
|||||||
branches: [ "main" ]
|
branches: [ "main" ]
|
||||||
paths:
|
paths:
|
||||||
- 'Dockerfile'
|
- 'Dockerfile'
|
||||||
|
- 'Dockerfile.gpu'
|
||||||
- '.github/workflows/*'
|
- '.github/workflows/*'
|
||||||
- 'deps/*'
|
- 'deps/*'
|
||||||
- 'keys/*'
|
- 'keys/*'
|
||||||
@@ -17,7 +18,14 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
version: [33, 32, 31, 30, 29, 28]
|
version: [33, 32, 31, 30, 29, 28]
|
||||||
image: [{ name: 'google_apis', suffix: '' }, { name: 'google_apis_playstore', suffix: '-playstore' }]
|
image: [
|
||||||
|
{ name: 'google_apis', suffix: '' },
|
||||||
|
{ name: 'google_apis_playstore', suffix: '-playstore' }
|
||||||
|
]
|
||||||
|
gpu: [
|
||||||
|
{ file: 'Dockerfile', suffix: '' },
|
||||||
|
{ file: 'Dockerfile.gpu', suffix: '-cuda' }
|
||||||
|
]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Login to Docker Hub
|
- name: Login to Docker Hub
|
||||||
@@ -29,13 +37,20 @@ jobs:
|
|||||||
uses: docker/build-push-action@v4
|
uses: docker/build-push-action@v4
|
||||||
with:
|
with:
|
||||||
push: true
|
push: true
|
||||||
tags: halimqarroum/docker-android:api-${{ matrix.version }}${{ matrix.image.suffix }}
|
file: ${{ matrix.gpu.file }}
|
||||||
|
tags: halimqarroum/docker-android:api-${{ matrix.version }}${{ matrix.image.suffix }}${{ matrix.gpu.suffix }}
|
||||||
build-args: |
|
build-args: |
|
||||||
API_LEVEL=${{ matrix.version }}
|
API_LEVEL=${{ matrix.version }}
|
||||||
IMG_TYPE=${{ matrix.image.name }}
|
IMG_TYPE=${{ matrix.image.name }}
|
||||||
|
|
||||||
# Builds a minimal image without any Android SDK images.
|
# Builds a minimal image without any Android SDK images.
|
||||||
build-minimal:
|
build-minimal:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
gpu: [
|
||||||
|
{ file: 'Dockerfile', suffix: '' },
|
||||||
|
{ file: 'Dockerfile.gpu', suffix: '-cuda' }
|
||||||
|
]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Login to Docker Hub
|
- name: Login to Docker Hub
|
||||||
@@ -47,5 +62,6 @@ jobs:
|
|||||||
uses: docker/build-push-action@v4
|
uses: docker/build-push-action@v4
|
||||||
with:
|
with:
|
||||||
push: true
|
push: true
|
||||||
tags: halimqarroum/docker-android:minimal
|
file: ${{ matrix.gpu.file }}
|
||||||
|
tags: halimqarroum/docker-android:minimal${{ matrix.gpu.suffix }}
|
||||||
build-args: INSTALL_ANDROID_SDK=0
|
build-args: INSTALL_ANDROID_SDK=0
|
||||||
|
|||||||
+19
-22
@@ -1,4 +1,4 @@
|
|||||||
FROM nvidia/cuda:12.1.0-runtime-ubuntu22.04
|
FROM adoptopenjdk/openjdk11:alpine-jre
|
||||||
|
|
||||||
# Docker labels.
|
# Docker labels.
|
||||||
LABEL maintainer "Halim Qarroum <hqm.post@gmail.com>"
|
LABEL maintainer "Halim Qarroum <hqm.post@gmail.com>"
|
||||||
@@ -10,26 +10,23 @@ LABEL version "1.0.0"
|
|||||||
COPY deps/redir/redir.c /usr/src/redir.c
|
COPY deps/redir/redir.c /usr/src/redir.c
|
||||||
|
|
||||||
# Installing required packages.
|
# Installing required packages.
|
||||||
RUN apt update -y && \
|
RUN apk update && \
|
||||||
apt install -y --no-install-recommends \
|
apk upgrade && \
|
||||||
build-essential \
|
apk add --no-cache \
|
||||||
bash \
|
alpine-sdk \
|
||||||
unzip \
|
bash \
|
||||||
wget \
|
unzip \
|
||||||
libvirt-daemon \
|
wget \
|
||||||
dbus \
|
libvirt-daemon \
|
||||||
openjdk-11-jdk \
|
dbus \
|
||||||
ca-certificates-java \
|
polkit \
|
||||||
virt-manager \
|
virt-manager && \
|
||||||
libvulkan1 \
|
# Compile `redir`.
|
||||||
xvfb \
|
gcc /usr/src/redir.c -o /usr/bin/redir && \
|
||||||
libgl1-mesa-glx \
|
strip /usr/bin/redir && \
|
||||||
libgl1-mesa-dri \
|
# Cleanup APK.
|
||||||
iproute2 && \
|
apk del alpine-sdk && \
|
||||||
# Compile `redir`.
|
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /var/cache/apk/*
|
||||||
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.
|
# Arguments that can be overriden at build-time.
|
||||||
ARG INSTALL_ANDROID_SDK=1
|
ARG INSTALL_ANDROID_SDK=1
|
||||||
@@ -38,7 +35,7 @@ ARG IMG_TYPE=google_apis
|
|||||||
ARG ARCHITECTURE=x86_64
|
ARG ARCHITECTURE=x86_64
|
||||||
ARG CMD_LINE_VERSION=9477386_latest
|
ARG CMD_LINE_VERSION=9477386_latest
|
||||||
ARG DEVICE_ID=pixel
|
ARG DEVICE_ID=pixel
|
||||||
ARG GPU_ACCELERATED=true
|
ARG GPU_ACCELERATED=false
|
||||||
|
|
||||||
# Environment variables.
|
# Environment variables.
|
||||||
ENV ANDROID_SDK_ROOT=/opt/android \
|
ENV ANDROID_SDK_ROOT=/opt/android \
|
||||||
|
|||||||
@@ -0,0 +1,88 @@
|
|||||||
|
FROM nvidia/cuda:12.1.0-runtime-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 \
|
||||||
|
bash \
|
||||||
|
unzip \
|
||||||
|
wget \
|
||||||
|
libvirt-daemon \
|
||||||
|
dbus \
|
||||||
|
openjdk-11-jdk \
|
||||||
|
ca-certificates-java \
|
||||||
|
virt-manager \
|
||||||
|
libvulkan1 \
|
||||||
|
xvfb \
|
||||||
|
libgl1-mesa-glx \
|
||||||
|
libgl1-mesa-dri \
|
||||||
|
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.
|
||||||
|
ARG INSTALL_ANDROID_SDK=1
|
||||||
|
ARG API_LEVEL=33
|
||||||
|
ARG IMG_TYPE=google_apis
|
||||||
|
ARG ARCHITECTURE=x86_64
|
||||||
|
ARG CMD_LINE_VERSION=9477386_latest
|
||||||
|
ARG DEVICE_ID=pixel
|
||||||
|
ARG GPU_ACCELERATED=true
|
||||||
|
|
||||||
|
# Environment variables.
|
||||||
|
ENV ANDROID_SDK_ROOT=/opt/android \
|
||||||
|
ANDROID_PLATFORM_VERSION="platforms;android-$API_LEVEL" \
|
||||||
|
PACKAGE_PATH="system-images;android-${API_LEVEL};${IMG_TYPE};${ARCHITECTURE}" \
|
||||||
|
API_LEVEL=$API_LEVEL \
|
||||||
|
DEVICE_ID=$DEVICE_ID \
|
||||||
|
ARCHITECTURE=$ARCHITECTURE \
|
||||||
|
ABI=${IMG_TYPE}/${ARCHITECTURE} \
|
||||||
|
GPU_ACCELERATED=$GPU_ACCELERATED \
|
||||||
|
QTWEBENGINE_DISABLE_SANDBOX=1 \
|
||||||
|
ANDROID_EMULATOR_WAIT_TIME_BEFORE_KILL=10
|
||||||
|
|
||||||
|
# Exporting environment variables for keeping in the path
|
||||||
|
# Android SDK binaries and shared libraries.
|
||||||
|
ENV PATH "${PATH}:${ANDROID_SDK_ROOT}/platform-tools"
|
||||||
|
ENV PATH "${PATH}:${ANDROID_SDK_ROOT}/emulator"
|
||||||
|
ENV PATH "${PATH}:${ANDROID_SDK_ROOT}/cmdline-tools/tools/bin"
|
||||||
|
ENV LD_LIBRARY_PATH "$ANDROID_SDK_ROOT/emulator/lib64:$ANDROID_SDK_ROOT/emulator/lib64/qt/lib"
|
||||||
|
|
||||||
|
# Set the working directory to /opt
|
||||||
|
WORKDIR /opt
|
||||||
|
|
||||||
|
# Exposing the Android emulator console port
|
||||||
|
# and the ADB port.
|
||||||
|
EXPOSE 5554 5555
|
||||||
|
|
||||||
|
# Initializing the required directories.
|
||||||
|
RUN mkdir /root/.android/ && \
|
||||||
|
touch /root/.android/repositories.cfg
|
||||||
|
|
||||||
|
# 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
|
||||||
|
# to install the Android SDK, emulator and system images.
|
||||||
|
# It will then install the Android SDK and emulator.
|
||||||
|
RUN /opt/install-sdk.sh
|
||||||
|
|
||||||
|
# Set the entrypoint
|
||||||
|
ENTRYPOINT ["/opt/start-emulator.sh"]
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
[](https://deepsource.io/gh/HQarroum/docker-android/?ref=repository-badge)
|
[](https://deepsource.io/gh/HQarroum/docker-android/?ref=repository-badge)
|
||||||

|

|
||||||
|
|
||||||
Current version: **1.0.0**
|
Current version: **1.1.0**
|
||||||
|
|
||||||
## 📋 Table of contents
|
## 📋 Table of contents
|
||||||
|
|
||||||
|
|||||||
@@ -23,12 +23,18 @@ export USER=root
|
|||||||
# Creating the Android Virtual Emulator.
|
# Creating the Android Virtual Emulator.
|
||||||
echo "Creating the Android Virtual Emulator ..."
|
echo "Creating the Android Virtual Emulator ..."
|
||||||
echo "Using package '$PACKAGE_PATH', ABI '$ABI' and device '$DEVICE_ID' for creating the emulator"
|
echo "Using package '$PACKAGE_PATH', ABI '$ABI' and device '$DEVICE_ID' for creating the emulator"
|
||||||
echo no | avdmanager create avd -f -n android --abi "$ABI" -k "$PACKAGE_PATH" --device "$DEVICE_ID"
|
echo no | avdmanager create avd \
|
||||||
|
--force \
|
||||||
|
--name android \
|
||||||
|
--abi "$ABI" \
|
||||||
|
--package "$PACKAGE_PATH" \
|
||||||
|
--device "$DEVICE_ID"
|
||||||
|
|
||||||
# If GPU acceleration is enabled, we create a virtual framebuffer
|
# If GPU acceleration is enabled, we create a virtual framebuffer
|
||||||
# to be used by the emulator when running with GPU acceleration.
|
# to be used by the emulator when running with GPU acceleration.
|
||||||
|
# We also set the GPU mode to `host` to force the emulator to use
|
||||||
|
# GPU acceleration.
|
||||||
if [ "$GPU_ACCELERATED" == "true" ]; then
|
if [ "$GPU_ACCELERATED" == "true" ]; then
|
||||||
echo "Running with GPU acceleration enabled"
|
|
||||||
export DISPLAY=":0.0"
|
export DISPLAY=":0.0"
|
||||||
export GPU_MODE="host"
|
export GPU_MODE="host"
|
||||||
Xvfb "$DISPLAY" -screen 0 1920x1080x16 -nolisten tcp &
|
Xvfb "$DISPLAY" -screen 0 1920x1080x16 -nolisten tcp &
|
||||||
@@ -48,4 +54,4 @@ emulator \
|
|||||||
-gpu "$GPU_MODE" \
|
-gpu "$GPU_MODE" \
|
||||||
-no-boot-anim \
|
-no-boot-anim \
|
||||||
-no-window \
|
-no-window \
|
||||||
-no-snapshot-save || update_state "ANDROID_STOPPED"
|
-no-snapshot || update_state "ANDROID_STOPPED"
|
||||||
|
|||||||
Reference in New Issue
Block a user