joaquim-verges/ProjectorAndroidStudio

Modify to run on JetBrains Spaces

Opened this issue · 2 comments

Hi, @joaquim-verges you stopped updating this 2 years ago. Is it because it's not a practical tool for Android development?

I'm trying to create a Dockerfile to run this on JetBrains Spaces. I was hoping to find some more reference, or stop trying if your experience was bad.

FROM ubuntu:20.04

ENV LANG=C.UTF-8

MAINTAINER Alexander Sedov <alexander.sedov@jetbrains.com>

ARG TARGETARCH

# Support various rvm, nvm etc stuff which requires executing profile scripts (-l)
SHELL ["/bin/bash", "-lc"]
CMD ["/bin/bash", "-l"]

# Set debconf to run non-interactively
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections

RUN apt-get update && apt-get install -y apt-utils apt-transport-https software-properties-common

# Newest git
RUN apt-add-repository ppa:git-core/ppa -y && apt-get update

RUN set -ex -o pipefail && apt-get install -y \
    # Useful utilities \
    curl unzip wget socat man-db rsync moreutils vim lsof \
    # VCS \
    git subversion subversion-tools mercurial \
    # Database clients \
    mongodb-clients mysql-client postgresql-client jq redis-tools \
    # C/C++ \
    build-essential cmake g++ m4 \
    # R \
    r-base r-base-dev \
    # TeX \
    texlive \
    # JVM \
    openjdk-8-jre-headless openjdk-11-jdk-headless openjdk-17-jdk-headless maven ant clojure scala \
    # Python 3 \
    python3-matplotlib python3-numpy python3-pip python3-scipy python3-pandas python3-dev pipenv \
    # Jetbrains Projector dependencies
    libxext6 libxrender1 libxtst6 libfreetype6 libxi6 \
    # Python 2 \
    python2-dev python-pip-whl \
    # Ruby \
    ruby-full \
    && \
    # Setup Java \
    update-alternatives --get-selections | grep usr/lib/jvm | awk '{print $1}' | \
    grep -v jpackage | grep -v jexec | \
    while IFS= read line; do echo $line; update-alternatives --set $line /usr/lib/jvm/java-11-openjdk-$TARGETARCH/bin/$line; done && \
    java -version && javac -version && \
    # Check Python \
    python3 --version && python2 --version && pip3 --version && \
    # Go \
    curl -fsSL "https://dl.google.com/go/$(curl -fsSL 'https://golang.org/VERSION?m=text').linux-$TARGETARCH.tar.gz" -o /tmp/go.tar.gz && \
    tar -C /usr/local -xzf /tmp/go.tar.gz && rm /tmp/go.tar.gz && \
    for x in /usr/local/go/bin/*; do echo $x; ln -vs $x /usr/local/bin/$(basename $x); done && ls -la /usr/local/bin && go version

## Nodejs, npm, yarn
RUN set -ex -o pipefail &&  \
    curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && \
    curl -fsSL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | tee /usr/share/keyrings/yarnkey.gpg >/dev/null && \
    echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | tee /etc/apt/sources.list.d/yarn.list && \
    apt-get update && apt-get install -y nodejs yarn

## PHP
RUN set -ex -o pipefail && \
    add-apt-repository ppa:ondrej/php -y && \
    apt-get install -y --no-install-recommends php8.0-cli php8.0-common php8.0-curl php8.0-xml php8.0-mbstring && \
    wget https://github.com/composer/composer/releases/download/2.2.1/composer.phar -O /usr/bin/composer -q && \
    chmod +x /usr/bin/composer

## dotNet
RUN if [ "$TARGETARCH" == "arm64" ] ; \
    then echo "Skipping installation of .NET packages, as they are only available for arm64 starting from Ubuntu 22.04" ; \
    else set -ex -o pipefail && \
      wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb && \
      dpkg -i packages-microsoft-prod.deb && \
      rm packages-microsoft-prod.deb && \
      apt-get update && \
      apt-get install -y dotnet-sdk-6.0 ; \
    fi

# Jetbrains Projector
RUN pip3 install projector-installer \
    projector --help

## Android Studio
RUN wget -q -O android-studio.tar.gz https://redirector.gvt1.com/edgedl/android/studio/ide-zips/2023.2.1.17/android-studio-2023.2.1.17-linux.tar.gz && \
    mkdir -p /opt/android-studio && \
    tar -xzf android-studio.tar.gz -C /opt/android-studio --strip-components=1 && \
    rm android-studio.tar.gz

# Set environment variable (if needed)
ENV ANDROID_HOME /opt/android-sdk
ENV PATH $PATH:/opt/android-studio/bin


# ... (previous content of the Dockerfile)

# Download and install Android Studio with Projector
RUN 
    wget -q -O projector-server.tar.gz 'https://github.com/JetBrains/projector-server/releases/download/v1.8.1/projector-server-v1.8.1.zip' && \
    mkdir -p /opt/projector-server && \
    tar -xzf projector-server.tar.gz -C /opt/projector-server --strip-components=1 && \
    rm projector-server.tar.gz


### Cloud Tools
## The awscli tools use a different naming scheme for arm64 builds
RUN if [ "$TARGETARCH" == "arm64" ] ; \
        then AWS_TOOLS_ARCH=aarch64 ; \
        else AWS_TOOLS_ARCH=x86_64 ; \
    fi && \
    set -ex -o pipefail && \
    # Docker \
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg && \
    echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
      $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list && \
    apt-get install -y docker.io && \
    docker --version && \
    # Kubernetes \
    curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg && \
    echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | tee /etc/apt/sources.list.d/kubernetes.list && \
    apt-get update && apt-get install -y kubectl && \
    kubectl version --client && \
    # aws-cli \
    curl -fsSL "https://awscli.amazonaws.com/awscli-exe-linux-$AWS_TOOLS_ARCH.zip" -o /tmp/awscliv2.zip && \
    mkdir -p /tmp/aws.extracted && \
    unzip -q /tmp/awscliv2.zip -d /tmp/aws.extracted && \
    /tmp/aws.extracted/aws/install && \
    rm -rf /tmp/aws.extracted /tmp/awscliv2.zip && \
    /usr/local/bin/aws --version && \
    # gcloud \
    curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - && \
    echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | tee /etc/apt/sources.list.d/google-cloud-sdk.list && \
    apt-get update && apt-get install -y google-cloud-sdk && \
    gcloud --version && \
    # rclone \
    curl -fsSL https://downloads.rclone.org/v1.56.2/rclone-v1.56.2-linux-$TARGETARCH.zip -o /tmp/rclone.zip && \
    mkdir -p /tmp/rclone.extracted && unzip -q /tmp/rclone.zip -d /tmp/rclone.extraced && \
    install -g root -o root -m 0755 -v /tmp/rclone.extraced/*/rclone /usr/local/bin && \
    rm -rf /tmp/rclone.extraced /tmp/rclone.zip && \
    rclone --version

## Docker compose (https://docs.docker.com/compose/install/)
## There are no arm64 builds of docker-compose for version 1.x.x, so version 2.x.x is used
RUN if [ "$TARGETARCH" == "arm64" ] ; \
      then DOCKER_COMPOSE_VERSION=v2.14.0 ; \
      else DOCKER_COMPOSE_VERSION=1.29.2 ; \
    fi && \
    set -ex -o pipefail && \
    curl -fsSL "https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && \
    chmod +x /usr/local/bin/docker-compose && \
    rm -f /usr/bin/docker-compose && \
    ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

RUN echo "############################### Versions #####################################" && \
    java -version &&  \
    javac -version && \
    echo "" && \
    python3 --version &&  \
    python2 --version &&  \
    pip3 --version && \
    echo "" && \
    go version && \
    echo "" && \
    echo ".NET SDK" && \
    if [ "$TARGETARCH" != "arm64" ] ; then dotnet --list-sdks ; else echo "Not available for arm64" ; fi && \
    echo "" && \
    echo ".NET Runtimes" && \
    if [ "$TARGETARCH" != "arm64" ] ; then dotnet --list-runtimes ; else echo "Not available for arm64" ; fi && \
    echo "" && \
    echo "Nodejs: $(node --version)" &&  \
    echo "Npm: $(npm --version)" &&  \
    echo "Yarn: $(yarn --version)" && \
    echo "" && \
    ruby --version && \
    echo "" && \
    php -v && \
    composer -V && \
    echo "" && \
    docker --version &&  \
    docker-compose --version && \
    echo "" && \
    echo "Kubectl: $(kubectl version --client)" && \
    echo "" && \
    gcloud --version && \
    echo "" && \
    rclone --version && \
    echo "" && \
    adb -- version && \
    echo "" && \
    adb devices && \
    echo "############################### Versions #####################################"

RUN ssh -R 5037:localhost:5037 remote-builder

RUN projector config add
# Enter a new configuration name: AndroidStudio
# Do you want to choose a Projector-installed IDE? [y/n]: n
# Enter the path to IDE: /path/to/your/android-studio
# Enter a desired Projector port (press ENTER for default) [10005]: 8888
# Use secure connection (this option requires installing a projector's certificate to browser)? [y/n]: y

RUN projector run AndroidStudio

Still use it from time to time! That said there is another jetbains gateway that is supposed to replace this workflow, but I still like it personally

Good to hear! I will try to complete this Docker build to support the Projector approach.
By any chance is the JetBrains Gateway approach you mentioned part of the JetBrains Spaces system? If you have any references of the alternative approach, I'd be grateful.

Btw, I saw a video covering your process:
Remote development in Jetbrains IDEs using projector (Intellij)
Remote development in Jetbrains IDEs using projector (Intellij)
https://youtu.be/Yg3quJAKlgs?si=UdeW1LoqQ3KMKmZ-