From efa319d2ebdaac2488b9ce810369e0424a137726 Mon Sep 17 00:00:00 2001 From: Justin Travis Date: Thu, 28 Dec 2023 16:19:09 -0500 Subject: [PATCH 1/4] KASM-1209 Redroid Images with Android Studio --- ci-scripts/template-vars.yaml | 14 +++ dockerfile-kasm-redroid | 55 +++++++++++ docs/redroid/README.md | 11 +++ docs/redroid/demo.txt | 9 ++ docs/redroid/description.txt | 1 + .../android_studio/install_android_studio.sh | 43 ++++++++ src/ubuntu/install/redroid/custom_startup.sh | 98 +++++++++++++++++++ src/ubuntu/install/redroid/install_redroid.sh | 18 ++++ 8 files changed, 249 insertions(+) create mode 100644 dockerfile-kasm-redroid create mode 100644 docs/redroid/README.md create mode 100644 docs/redroid/demo.txt create mode 100644 docs/redroid/description.txt create mode 100644 src/ubuntu/install/android_studio/install_android_studio.sh create mode 100644 src/ubuntu/install/redroid/custom_startup.sh create mode 100644 src/ubuntu/install/redroid/install_redroid.sh diff --git a/ci-scripts/template-vars.yaml b/ci-scripts/template-vars.yaml index fe446cc..7c665ae 100644 --- a/ci-scripts/template-vars.yaml +++ b/ci-scripts/template-vars.yaml @@ -115,6 +115,20 @@ multiImages: changeFiles: - dockerfile-kasm-qbittorrent - src/ubuntu/install/qbittorrent/** + - name: redroid + base: core-ubuntu-jammy + dockerfile: dockerfile-kasm-redroid + changeFiles: + - dockerfile-kasm-redroid + - src/ubuntu/install/redroid/** + - src/ubuntu/install/android_studio/** + - src/ubuntu/install/misc/** + - src/ubuntu/install/sublime_text/** + - src/ubuntu/install/vs_code/** + - src/ubuntu/install/chrome/** + - src/ubuntu/install/chromium/** + - src/ubuntu/install/tools/** + - src/ubuntu/install/cleanup/** - name: remmina base: core-ubuntu-focal dockerfile: dockerfile-kasm-remmina diff --git a/dockerfile-kasm-redroid b/dockerfile-kasm-redroid new file mode 100644 index 0000000..9d25435 --- /dev/null +++ b/dockerfile-kasm-redroid @@ -0,0 +1,55 @@ +ARG BASE_TAG="develop" +ARG BASE_IMAGE="core-ubuntu-jammy" +FROM kasmweb/$BASE_IMAGE:$BASE_TAG +USER root + +ENV HOME /home/kasm-default-profile +ENV STARTUPDIR /dockerstartup +WORKDIR $HOME + +### Envrionment config +ENV DEBUG=false \ + DEBIAN_FRONTEND=noninteractive \ + SKIP_CLEAN=true \ + KASM_RX_HOME=$STARTUPDIR/kasmrx \ + DONT_PROMPT_WSL_INSTALL="No_Prompt_please" \ + INST_DIR=$STARTUPDIR/install \ + INST_SCRIPTS="/ubuntu/install/dind/install_dind.sh \ + /ubuntu/install/tools/install_tools_deluxe.sh \ + /ubuntu/install/misc/install_tools.sh \ + /ubuntu/install/chrome/install_chrome.sh \ + /ubuntu/install/chromium/install_chromium.sh \ + /ubuntu/install/sublime_text/install_sublime_text.sh \ + /ubuntu/install/vs_code/install_vs_code.sh \ + /ubuntu/install/redroid/install_redroid.sh \ + /ubuntu/install/android_studio/install_android_studio.sh \ + /ubuntu/install/cleanup/cleanup.sh" + +# Startup Scripts +COPY ./src/ubuntu/install/redroid/custom_startup.sh $STARTUPDIR/custom_startup.sh +RUN chmod 755 $STARTUPDIR/custom_startup.sh +COPY ./src/ubuntu/install/dind/dockerd.conf /etc/supervisor/conf.d/ +RUN cp /usr/share/extra/backgrounds/bg_kasm.png /usr/share/extra/backgrounds/bg_default.png + +# Copy install scripts +COPY ./src/ $INST_DIR + +# Run installations +RUN \ + for SCRIPT in $INST_SCRIPTS; do \ + bash ${INST_DIR}${SCRIPT}; \ + done && \ + $STARTUPDIR/set_user_permission.sh $HOME && \ + rm -f /etc/X11/xinit/Xclients && \ + chown 1000:0 $HOME && \ + mkdir -p /home/kasm-user && \ + chown -R 1000:0 /home/kasm-user && \ + rm -Rf ${INST_DIR} + + +# Userspace Runtime +ENV HOME /home/kasm-user +WORKDIR $HOME +USER 1000 + +CMD ["--tail-log"] \ No newline at end of file diff --git a/docs/redroid/README.md b/docs/redroid/README.md new file mode 100644 index 0000000..97850a5 --- /dev/null +++ b/docs/redroid/README.md @@ -0,0 +1,11 @@ +# About This Image + +This Image contains a browser-accessible version of [Redroid](https://github.com/remote-android/redroid-doc). + +![Screenshot][Image_Screenshot] + +[Image_Screenshot]: https://f.hubspotusercontent30.net/hubfs/5856039/dockerhub/image-screenshots/redroid.png "Image Screenshot" + +# Environment Variables + +* `APP_ARGS` - Additional arguments to pass to the application when launched. diff --git a/docs/redroid/demo.txt b/docs/redroid/demo.txt new file mode 100644 index 0000000..8064874 --- /dev/null +++ b/docs/redroid/demo.txt @@ -0,0 +1,9 @@ +# Live Demo + + + +**Launch a real-time demo in a new browser window:** Live Demo. + + + +∗*Note: Demo is limited to 3 minutes and has upload/downloads restricted for security purposes.* diff --git a/docs/redroid/description.txt b/docs/redroid/description.txt new file mode 100644 index 0000000..0a86cd8 --- /dev/null +++ b/docs/redroid/description.txt @@ -0,0 +1 @@ +Redroid (Remote-Android) for Kasm Workspaces diff --git a/src/ubuntu/install/android_studio/install_android_studio.sh b/src/ubuntu/install/android_studio/install_android_studio.sh new file mode 100644 index 0000000..effb50d --- /dev/null +++ b/src/ubuntu/install/android_studio/install_android_studio.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +set -ex + + +ARCH=$(arch | sed 's/aarch64/arm64/g' | sed 's/x86_64/amd64/g') +if [ "$ARCH" == "arm64" ] ; then + echo "Chrome not supported on arm64, skipping Chrome installation" + exit 0 +fi + +apt-get update +apt-get install -y libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386 openjdk-18-jdk + +ANDROID_STUDIO_DOWNLOAD_URL="https://redirector.gvt1.com/edgedl/android/studio/ide-zips/2023.1.1.26/android-studio-2023.1.1.26-linux.tar.gz" + +curl -o /tmp/android_studio.tar.gz -L "${ANDROID_STUDIO_DOWNLOAD_URL}" + +mkdir -p /opt +cd /tmp +tar -zxvf /tmp/android_studio.tar.gz -C /opt/ +rm /tmp/android_studio.tar.gz +ln -sf /opt/android-studio/bin/studio.sh /bin/android-studio +chown 1000:1000 /opt/android-studio + + +cat >/usr/share/applications/android-studio.desktop < /dev/null + then + /usr/bin/filter_ready + /usr/bin/desktop_ready + set +e + sudo /usr/bin/supervisord -n & + set -e + start_android + fi + if ! pgrep -x $SCRCPY_PGREP > /dev/null + then + /usr/bin/filter_ready + /usr/bin/desktop_ready + start_scrcpy + fi + sleep 1 + done + set -x + + fi + +} + +kasm_startup diff --git a/src/ubuntu/install/redroid/install_redroid.sh b/src/ubuntu/install/redroid/install_redroid.sh new file mode 100644 index 0000000..198cf36 --- /dev/null +++ b/src/ubuntu/install/redroid/install_redroid.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +set -ex + +ARCH=$(arch | sed 's/x86_64/amd64/g') + +apt-get update +apt-get install -y android-tools-adb android-tools-fastboot \ + ffmpeg libsdl2-2.0-0 adb wget \ + gcc git pkg-config meson ninja-build libsdl2-dev \ + libavcodec-dev libavdevice-dev libavformat-dev libavutil-dev \ + libswresample-dev libusb-1.0-0 libusb-1.0-0-dev jq + + +mkdir -p /opt/ +cd /opt/ +git clone https://github.com/Genymobile/scrcpy +cd scrcpy +./install_release.sh \ No newline at end of file From 3cd02e4952e22ad0d2c33dc6a754ffe0baa0252f Mon Sep 17 00:00:00 2001 From: Justin Travis Date: Thu, 28 Dec 2023 19:13:07 -0500 Subject: [PATCH 2/4] KASM-1209 Check for host modules --- docs/redroid/README.md | 12 +++++- docs/redroid/demo.txt | 4 +- src/ubuntu/install/redroid/custom_startup.sh | 42 ++++++++++++-------- 3 files changed, 39 insertions(+), 19 deletions(-) diff --git a/docs/redroid/README.md b/docs/redroid/README.md index 97850a5..e2f62ea 100644 --- a/docs/redroid/README.md +++ b/docs/redroid/README.md @@ -5,7 +5,17 @@ This Image contains a browser-accessible version of [Redroid](https://github.com ![Screenshot][Image_Screenshot] [Image_Screenshot]: https://f.hubspotusercontent30.net/hubfs/5856039/dockerhub/image-screenshots/redroid.png "Image Screenshot" +## Important !! + +This image requires host level kernel modules to be installed and loaded. +See [Redroid Docs](https://github.com/remote-android/redroid-doc?tab=readme-ov-file#getting-started) for more details + # Environment Variables -* `APP_ARGS` - Additional arguments to pass to the application when launched. +* `REDROID_GPU_GUEST_MODE` - Used to instruct redroid to utilize GPU rendering. Options are `auto`, `guest`, and `host` +* `REDROID_FPS` - Set the maximum FPS for redroid and scrcpy +* `REDROID_WIDTH` - Set the desired width of the redroid device +* `REDROID_HEIGHT` - Set the desired height of the redroid device +* `REDROID_DPI` - Set the desired DPI of the redroid device +* `REDROID_SHOW_CONSOLE` - Display the scrcpy console after launching the redroid device. \ No newline at end of file diff --git a/docs/redroid/demo.txt b/docs/redroid/demo.txt index 8064874..6eb92d4 100644 --- a/docs/redroid/demo.txt +++ b/docs/redroid/demo.txt @@ -1,9 +1,9 @@ # Live Demo - + **Launch a real-time demo in a new browser window:** Live Demo. - + ∗*Note: Demo is limited to 3 minutes and has upload/downloads restricted for security purposes.* diff --git a/src/ubuntu/install/redroid/custom_startup.sh b/src/ubuntu/install/redroid/custom_startup.sh index d956bca..793c7b8 100644 --- a/src/ubuntu/install/redroid/custom_startup.sh +++ b/src/ubuntu/install/redroid/custom_startup.sh @@ -7,32 +7,44 @@ DEFAULT_ARGS="-n" ARGS=${APP_ARGS:-$DEFAULT_ARGS} ANDROID_VERSION=${ANDROID_VERSION:-"13.0.0"} REDROID_GPU_GUEST_MODE=${REDROID_GPU_GUEST_MODE:-"guest"} -REDROID_FPS=${REDROID_FPS:-"60"} +REDROID_FPS=${REDROID_FPS:-"30"} REDROID_WIDTH=${REDROID_WIDTH:-"720"} REDROID_HEIGHT=${REDROID_HEIGHT:-"1280"} REDROID_DPI=${REDROID_DPI:-"320"} REDROID_SHOW_CONSOLE=${REDROID_SHOW_CONSOLE:-"1"} +ICON_ERROR="/usr/share/icons/ubuntu-mono-dark/status/22/system-devices-panel-alert.svg" + + LAUNCH_CONFIG='/dockerstartup/redroid_launch_selections.json' # Launch Config Based Workflow if [ -e ${LAUNCH_CONFIG} ]; then ANDROID_VERSION="$(jq -r '.android_version' ${LAUNCH_CONFIG})" fi -function audio_patch() { - # The devices start with audio quite low - set +e - for ((i=1; i<=10; i++)); do - adb -s localhost:5555 shell input keyevent KEYCODE_VOLUME_UP & - sleep 0.2 - done - set -e +function check_modules() { + if lsmod | grep -q binder_linux; then + echo "binder_linux module is loaded." + else + msg="Host level module binder_linux is not loaded. Cannot continue.\nSee https://github.com/remote-android/redroid-doc?tab=readme-ov-file#getting-started for more details." + echo msg + notify-send -u critical -t 0 -i "${ICON_ERROR}" "Redroid Error" "${msg}" + exit 1 + fi + + # Check for ashmem_linux module + if lsmod | grep -q ashmem_linux; then + echo "ashmem_linux module is loaded." + else + msg="Host level module ashmem_linux is not loaded. Cannot continue.\nSee https://github.com/remote-android/redroid-doc?tab=readme-ov-file#getting-started for more details." + echo msg + notify-send -u critical -t 0 -i "${ICON_ERROR}" "Redroid Error" "${msg}" + exit 1 + fi } start_android() { - /usr/bin/filter_ready - /usr/bin/desktop_ready sleep 5 xfce4-terminal --hide-menubar --command "bash -c \"sudo docker pull redroid/redroid:${ANDROID_VERSION}-latest \"" sudo docker run -itd --rm --privileged \ @@ -48,7 +60,6 @@ start_android() { sleep 2 adb connect localhost:5555 sleep 5 - audio_patch } start_scrcpy() { @@ -74,8 +85,6 @@ kasm_startup() { do if ! pgrep -x $DOCKER_PGREP > /dev/null then - /usr/bin/filter_ready - /usr/bin/desktop_ready set +e sudo /usr/bin/supervisord -n & set -e @@ -83,8 +92,6 @@ kasm_startup() { fi if ! pgrep -x $SCRCPY_PGREP > /dev/null then - /usr/bin/filter_ready - /usr/bin/desktop_ready start_scrcpy fi sleep 1 @@ -95,4 +102,7 @@ kasm_startup() { } +/usr/bin/filter_ready +/usr/bin/desktop_ready +check_modules kasm_startup From 92fecee17205e312291696fb787ff15cca64855c Mon Sep 17 00:00:00 2001 From: Justin Travis Date: Fri, 29 Dec 2023 09:15:27 -0500 Subject: [PATCH 3/4] KASM-1209 Add ability to disable autostart and host checks --- docs/redroid/README.md | 4 +++- src/ubuntu/install/redroid/custom_startup.sh | 20 +++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/docs/redroid/README.md b/docs/redroid/README.md index e2f62ea..c16f83a 100644 --- a/docs/redroid/README.md +++ b/docs/redroid/README.md @@ -18,4 +18,6 @@ See [Redroid Docs](https://github.com/remote-android/redroid-doc?tab=readme-ov-f * `REDROID_WIDTH` - Set the desired width of the redroid device * `REDROID_HEIGHT` - Set the desired height of the redroid device * `REDROID_DPI` - Set the desired DPI of the redroid device -* `REDROID_SHOW_CONSOLE` - Display the scrcpy console after launching the redroid device. \ No newline at end of file +* `REDROID_SHOW_CONSOLE` - Display the scrcpy console after launching the redroid device. +* `REDROID_DISABLE_AUTOSTART` - If set to "1", the container will not automatically pull and start the redroid container and scrcpy. +* `REDROID_DISABLE_HOST_CHECKS` - If set to "1", the container will not check for the presence of required host level kernel modules. diff --git a/src/ubuntu/install/redroid/custom_startup.sh b/src/ubuntu/install/redroid/custom_startup.sh index 793c7b8..f8bd860 100644 --- a/src/ubuntu/install/redroid/custom_startup.sh +++ b/src/ubuntu/install/redroid/custom_startup.sh @@ -12,6 +12,8 @@ REDROID_WIDTH=${REDROID_WIDTH:-"720"} REDROID_HEIGHT=${REDROID_HEIGHT:-"1280"} REDROID_DPI=${REDROID_DPI:-"320"} REDROID_SHOW_CONSOLE=${REDROID_SHOW_CONSOLE:-"1"} +REDROID_DISABLE_AUTOSTART=${REDROID_DISABLE_AUTOSTART:-"0"} +REDROID_DISABLE_HOST_CHECKS=${REDROID_DISABLE_HOST_CHECKS:-"0"} ICON_ERROR="/usr/share/icons/ubuntu-mono-dark/status/22/system-devices-panel-alert.svg" @@ -88,11 +90,15 @@ kasm_startup() { set +e sudo /usr/bin/supervisord -n & set -e - start_android + if [ "$REDROID_DISABLE_AUTOSTART" == "0" ]; then + start_android + fi fi - if ! pgrep -x $SCRCPY_PGREP > /dev/null - then - start_scrcpy + if [ "$REDROID_DISABLE_AUTOSTART" == "0" ]; then + if ! pgrep -x $SCRCPY_PGREP > /dev/null + then + start_scrcpy + fi fi sleep 1 done @@ -104,5 +110,9 @@ kasm_startup() { /usr/bin/filter_ready /usr/bin/desktop_ready -check_modules + + +if [ "$REDROID_DISABLE_HOST_CHECKS" == "0" ]; then + check_modules +fi kasm_startup From ec9e124bd30601b833b2857a5abcbf37fb283301 Mon Sep 17 00:00:00 2001 From: Justin Travis Date: Mon, 1 Jan 2024 09:59:08 -0500 Subject: [PATCH 4/4] KASM-1209 Cleanup --- docs/redroid/README.md | 9 +++++---- docs/redroid/demo.txt | 6 +++--- .../install/android_studio/install_android_studio.sh | 4 +++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/docs/redroid/README.md b/docs/redroid/README.md index c16f83a..abfa1ec 100644 --- a/docs/redroid/README.md +++ b/docs/redroid/README.md @@ -1,6 +1,7 @@ # About This Image This Image contains a browser-accessible version of [Redroid](https://github.com/remote-android/redroid-doc). +redroid (Remote-Android) is a multi-arch, GPU enabled, Android in Cloud solution. ![Screenshot][Image_Screenshot] @@ -14,10 +15,10 @@ See [Redroid Docs](https://github.com/remote-android/redroid-doc?tab=readme-ov-f # Environment Variables * `REDROID_GPU_GUEST_MODE` - Used to instruct redroid to utilize GPU rendering. Options are `auto`, `guest`, and `host` -* `REDROID_FPS` - Set the maximum FPS for redroid and scrcpy -* `REDROID_WIDTH` - Set the desired width of the redroid device -* `REDROID_HEIGHT` - Set the desired height of the redroid device -* `REDROID_DPI` - Set the desired DPI of the redroid device +* `REDROID_FPS` - Set the maximum FPS for redroid and scrcpy. +* `REDROID_WIDTH` - Set the desired width of the redroid device. +* `REDROID_HEIGHT` - Set the desired height of the redroid device. +* `REDROID_DPI` - Set the desired DPI of the redroid device. * `REDROID_SHOW_CONSOLE` - Display the scrcpy console after launching the redroid device. * `REDROID_DISABLE_AUTOSTART` - If set to "1", the container will not automatically pull and start the redroid container and scrcpy. * `REDROID_DISABLE_HOST_CHECKS` - If set to "1", the container will not check for the presence of required host level kernel modules. diff --git a/docs/redroid/demo.txt b/docs/redroid/demo.txt index 6eb92d4..152a949 100644 --- a/docs/redroid/demo.txt +++ b/docs/redroid/demo.txt @@ -1,9 +1,9 @@ # Live Demo - + -**Launch a real-time demo in a new browser window:** Live Demo. +**Launch a real-time demo in a new browser window:** Live Demo. - + ∗*Note: Demo is limited to 3 minutes and has upload/downloads restricted for security purposes.* diff --git a/src/ubuntu/install/android_studio/install_android_studio.sh b/src/ubuntu/install/android_studio/install_android_studio.sh index effb50d..b8ee382 100644 --- a/src/ubuntu/install/android_studio/install_android_studio.sh +++ b/src/ubuntu/install/android_studio/install_android_studio.sh @@ -4,13 +4,15 @@ set -ex ARCH=$(arch | sed 's/aarch64/arm64/g' | sed 's/x86_64/amd64/g') if [ "$ARCH" == "arm64" ] ; then - echo "Chrome not supported on arm64, skipping Chrome installation" + echo "Android studio not supported on arm64, skipping installation" exit 0 fi apt-get update apt-get install -y libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386 openjdk-18-jdk +# https://developer.android.com/studio/archive +# curl https://developer.android.com/studio | grep android-studio | grep -i "linux.tar.gz" | grep ide-zips | cut -d '"' -f2 ANDROID_STUDIO_DOWNLOAD_URL="https://redirector.gvt1.com/edgedl/android/studio/ide-zips/2023.1.1.26/android-studio-2023.1.1.26-linux.tar.gz" curl -o /tmp/android_studio.tar.gz -L "${ANDROID_STUDIO_DOWNLOAD_URL}"