Sign inSign up

oveits/intellij-desktop

By oveits

•Updated over 5 years ago

Image
0

3.3K

oveits/intellij-desktop repository overview

⁠TODO

  • to Dockerfile: remove version from idea foldername (pros and cons to be discussed) ln -s ${IDEA_HOME} /headless/idea-IC

  • Find out how to place a desktop item to the desktop for intellij

  • Start intellij on bootup of the container

  • Consider to make [email protected]⁠:vocon-IT/intellij-desktop.git open source, so it can be used by our customers. In the moment, other cannot deploy the IntelliJ Desktop as described in the first chapter below

  • Improve the IntelliJ bash prompt to show the foldername and the git branch

  • Add .ssh to the list of mapped volumes

  • Add ssh-agent to .bashrc

  • Link /home/centos/.gitconfig to /headless/.gitconfig

  • allow docker and kubectl commands from inside the container (by mapping volumes to executables and .kube and .docker? )

  • save last used resolution and use as default for next bootup (read with xrandr and save to /home/centos/.vocloud?)

  • for development, create and use docker images with tags derived from the branch name (e.g. vocon/intellij-desktop:caas-53-whatever-branchname )

  • Adjust and test noVNC resolutions to minus 24 pixel height

    • FHD
    • UHD (150%)
    • UHD (125%)
    • UHD (100%)
  • Bug: if display is changed via Display Icon, then the .vocloud/.resolution.sh file is not updated, leading to a false resolution after next container reboot. To fix this, redefine the Display Desktop icon.

  • Bug: if display is changed via Application -> ... -> Display or context menu -> ... -> Display , then the .vocloud/.resolution.sh file is not updated, leading to a false resolution after next container reboot. To fix this, redefine the Display Desktop icon.

  • Bug: (workaround given) IntelliJ crashes, upon opening project oveits/docker-headless-vnc-container⁠

    • Workaround: After an IntelliJ crash, make sure that IntelliJ starts without any project opened next time
  • Add IntelliJ Icon on the Desktop

  • Install jq on the container to be able to use the Hetzner Bash Scripts

  • Adapt the Idea Version and the Idea Path to be the same

⁠Deploy IntelliJ Desktop on Kubernetes

On a machine with kubectl installed (e.g. the kubernetes master), run the following commands:

[ -d intellij-desktop ] || git clone [email protected]:vocon-IT/intellij-desktop.git
bash intellij-desktop/deploy.sh

⁠Deploy Intellij Desktop via Job on Kubernetes

On a machine with kubectl installed, define the necessary variables for running the job:

export CLOUDFLARE_API_TOKEN=changeme
export TARGET_ENVIRONMENT_DNS=changeToTargetDNSEntry

Then clone the project and run the job script:

[ -d intellij-desktop ] || git clone [email protected]:vocon-IT/intellij-desktop.git
bash intellij-desktop/deploy-via-kubectl.sh

⁠Access IntelliJ Desktop

⁠Access IntelliJ Desktop via VNC Viewer (preferred; allow cut&paste from your own PC)

Cut&Paste following code to the Kubernetes Node the IntelliJ Desktop will be running on:

IP=$(ifconfig eth0 | grep -v inet6 | grep inet | awk '{print $2}')
VNC_PASSWORD=$(cat deploy/intellijDesktopDeployment.yaml | grep passw | awk -F [\"] '{print $2}')

cat <<EOF > /tmp/8356823

Host: $IP
Port: 5901
Password: $VNC_PASSWORD
EOF

cat /tmp/8356823 && rm /tmp/8356823

Create a connection in a VNC viewer with the date printed above and connect to the machine.

⁠Access IntelliJ Desktop via Browser

Open a browser and head to following URL (change password in the URL, if you have not used a default password in the deployment file above.

echo "http://${IP}:6901/?password=${VNC_PASSWORD}/"

⁠HTTPS

For HTTPS deployment, see the letsencrypt-issuer⁠ project:

⁠Adapt Resolution

  • double-click the "Display" desktop icon
  • choose resolution from drop-down
  • Apply
  • Close

If the Display icon is not available on the desktop, you might also find it via following path:

  • right-click on Desktop
  • Applications
  • Settings
  • Display

Then again:

  • choose resolution from drop-down
  • Apply
  • Close

⁠Start IntelliJ

  • right click on Desktop
  • Open Terminal here
bash ${IDEA_HOME}/bin/idea_wrapper.sh &

⁠How to add a new application to IntelliJ Desktop

Note: kubectl and Docker is required for the rebuild step, so perform at least the rebuild step on the VM hosting the IntelliJDesktop container. the rebuild step requires kubectl, which is not yet available on IntelliJDesktop. The other steps can be perfomed on IntelliJDesktop for better editing, if needed.

  • Git clone the project and go to project root.
  • Add a shell script that installs the application in project root.
  • Add following lines the the Dockerfile:
    ADD my-installation-script.sh $HOME/install
    RUN bash $HOME/install/my-installation-script.sh && rm $HOME/install/my-installation-script.sh
    
    Adapt the script name as required. Note that the lines must be added before the USER 1000 line, if the installation must be done as root (and after the User 1000 line, if it needs to be installed as user)
  • Add the code for desktop_icons to <project-root>/desktop_icons. In the installation script above, add the line
    [ -r /my_icon.sh ] && bash /my_icon.sh && rm /my_icon.sh
    
    Here an example for a Desktop Icon script:
    # Create Desktop Launcher
    cat << 'EOF' > /headless/Desktop/vscode.desktop
    [Desktop Entry]
    Version=1.0
    Type=Application
    Encoding=UTF-8
    Exec=/usr/share/code/code --no-sandbox --unity-launch %F
    Icon=com.visualstudio.code
    StartupNotify=false
    Categories=X-XFCE;X-Xfce-Toplevel;
    OnlyShowIn=XFCE;
    Name=Visual Studio Code
    Comment=Code Editing. Redefined.
    
    Path=
    Terminal=false
    
    EOF
    
    chmod 777 /headless/Desktop/vscode.desktop
    [ -d /usr/share/applications/ ] && cp /headless/Desktop/vscode.desktop /usr/share/applications/
    
    The last two line are needed in order to for the Desktop icon to work without prompt and to be able to add the application to the menu (see the bullet point "Add a menu item" below).
  • Add Volumes and Ports: on <project-root>/deploy/deploy.yaml, add any needed volumes and ports, if needed. Note that you als need to add a mkdir -p /home/centos/.vocloud/<folder> statement to <project-root>/deploy.sh for a successful bootup of the POD in the rebuild.sh step.
  • Optional: add a menu item: in <project root>/entrypoint_post_vnc_startup.sh, search for Creating custom Application Menu and add a line
    Menu>
        <Name>Applications</Name>
    
        ...
    
        <Layout>
            <Filename>my-program.desktop</Filename>
    
    The filename must match the one you have specified in your ..._icon.sh shell script.
  • Rebuild the project:
    bash rebuild.sh
    

⁠Delete IntelliJ Desktop from the virtual Machine

On a machine with kubectl connection to the kubernetes cluster (e.g. on the Kubernetes master), perform following command:

kubectl delete deploy intellij-desktop

⁠Developer Hints

⁠Reinstall and Restart the intellij POD after changing some code

Run in the local GIT repo intellij-desktop (confirm with y):

bash rebuild.sh

This will perform the following steps:

IMAGE=$(cat deploy/intellijDesktopDeployment.yaml | egrep "^[ ]*image:" | awk '{print $2}') \
  && sudo docker build -t ${IMAGE} . \
  && sudo docker push ${IMAGE} \
  && OLD_POD=$(kubectl get pod | awk '{print $1}' | grep intellij) \
  && bash deploy.sh \
  && kubectl delete POD $OLD_POD \
  && watch kubectl get pod

You can stop watching the outcome of the get pod command by pressing Ctrl-C.

⁠Start an exec session into the intellij container

Note: you need to wait for the POD to be up and running

kubectl exec -it $(kubectl get pod | grep Running | grep intellij-desktop | awk '{print $1}') bash

⁠Usage

⁠Features

⁠Keyboard Layout
For changing the keyboard layout used on the machine, just change your own keyboard mapping by pressing Windows Key + Space.

⁠Cloning the project

Clone a repository⁠

Setting up an SSH Key on Bitbucket for authentication: Set up a SSH Key⁠.

⁠Starting the container directly with Docker (not kubernetes):

Docker command for running the latest container version with port mapping ('5091' - VNC and '6091' - HTML), volume mapping for persisting Intellij settings and Projects created inside the vocon folder.

docker run -it --rm -p 5901:5901 -p 6901:6901 \
	-v ~/intellij/.Idea.share:/headless/.local/share/JetBrains \
	-v ~/intellij/.Idea.java:/headless/.java \
	-v ~/intellij/.Idea.maven:/headless/.m2 \
	-v ~/intellij/.Idea:/headless/.IdeaIC \
	-v ~/vocon:/headless/vocon \
gabrielnarodrigues/intellij-desktop:latest bash

⁠Resolutions

⁠Starting the container with a custom resolution

You can use the docker run command specifying the environmnent variable VNC_RESOLUTION.

docker run -e VNC_RESOLUTION=3840x2120 gabrielnarodrigues/intellij-desktop:latest

⁠Adding more custom resolutions

Inside the '/entrypoint_post_vnc_startup.sh' file, look for the declaration of the String Array and add the wanted resolution. After the changes, the image needs to be rebuilt and the container started with the new version.

declare -a addResolutions=(
"1920 1056 60"
"2560 1416 60"
"2560 1440 60"
"3072 1704 60"
"3072 1728 60"
"3840 2136 60"
"3840 2160 60"
)

⁠Retrieving resolution from the browser via Javascript

For retrieving user information about the used resolution of his PC, you can use the following commands:

screen.width + "x" + screen.height
window.screen.width * window.devicePixelRatio + "x" + window.screen.height * window.devicePixelRatio

For correct sizing when using the no-VNC version (browser), it's recommended to extract a minimum of 23 pixels (we have chosen 24 pixels) of the length of the resolution for better fitting inside the browser window. i.e.:

4k: 3840x2136
FHD: 1920x1056

⁠Manual Test

⁠Sprint Boot Hello World

Following https://spring.io/guides/gs/testing-web/⁠

⁠Step 1: Install Spring Assistant

(was not mentioned on the guide, but I wanted to use Initializr from within IntelliJ)

--> IntelliJ --> File --> Settings --> Plugins --> Spring Assistant --> Install --> Reboot IDE

⁠Step 2: Create Project

--> IntelliJ --> File --> New --> Project --> Spring Assistant -->

Tag summary

Content type

Image

Digest

Size

1.8 GB

Last updated

over 5 years ago

docker pull oveits/intellij-desktop:feature_CAAS-629-reconnect-to-existing-cloud-des