From b0667c5589bfe1b382c49392c58fe4c9433f1fde Mon Sep 17 00:00:00 2001 From: Gaurav Saini <147703805+gauravsaini04@users.noreply.github.com> Date: Tue, 10 Sep 2024 05:27:54 +0530 Subject: [PATCH] [desktop-lite] - vnc_resolution - set thru env var (#1112) * [desktop-lite] - vnc_resolution - set thru env var * mistake in scenarios.json corrected * small change of function addition in desktop-init.sh file * changes as requested (review pr) * changes as suggested --- src/desktop-lite/devcontainer-feature.json | 2 +- src/desktop-lite/install.sh | 10 ++-- test/desktop-lite/scenarios.json | 27 +++++++++++ ...est_vnc_resolution_as_container_env_var.sh | 47 +++++++++++++++++++ .../test_vnc_resolution_as_remote_env_var.sh | 33 +++++++++++++ 5 files changed, 113 insertions(+), 6 deletions(-) create mode 100644 test/desktop-lite/test_vnc_resolution_as_container_env_var.sh create mode 100644 test/desktop-lite/test_vnc_resolution_as_remote_env_var.sh diff --git a/src/desktop-lite/devcontainer-feature.json b/src/desktop-lite/devcontainer-feature.json index 7c2549a0d..135c812b7 100644 --- a/src/desktop-lite/devcontainer-feature.json +++ b/src/desktop-lite/devcontainer-feature.json @@ -1,6 +1,6 @@ { "id": "desktop-lite", - "version": "1.2.4", + "version": "1.2.5", "name": "Light-weight Desktop", "documentationURL": "https://github.com/devcontainers/features/tree/main/src/desktop-lite", "description": "Adds a lightweight Fluxbox based desktop to the container that can be accessed using a VNC viewer or the web. GUI-based commands executed from the built-in VS code terminal will open on the desktop automatically.", diff --git a/src/desktop-lite/install.sh b/src/desktop-lite/install.sh index 5060f9210..6e6fff265 100755 --- a/src/desktop-lite/install.sh +++ b/src/desktop-lite/install.sh @@ -300,11 +300,11 @@ user_name="${USERNAME}" group_name="$(id -gn ${USERNAME})" LOG=/tmp/container-init.log -export DBUS_SESSION_BUS_ADDRESS="${DBUS_SESSION_BUS_ADDRESS:-"autolaunch:"}" -export DISPLAY="${DISPLAY:-:1}" -export VNC_RESOLUTION="${VNC_RESOLUTION:-1440x768x16}" -export LANG="${LANG:-"en_US.UTF-8"}" -export LANGUAGE="${LANGUAGE:-"en_US.UTF-8"}" +export DBUS_SESSION_BUS_ADDRESS="\${DBUS_SESSION_BUS_ADDRESS:-"autolaunch:"}" +export DISPLAY="\${DISPLAY:-:1}" +export VNC_RESOLUTION="\${VNC_RESOLUTION:-1440x768x16}" +export LANG="\${LANG:-"en_US.UTF-8"}" +export LANGUAGE="\${LANGUAGE:-"en_US.UTF-8"}" # Execute the command it not already running startInBackgroundIfNotRunning() diff --git a/test/desktop-lite/scenarios.json b/test/desktop-lite/scenarios.json index d86b321fd..ab920ddb9 100644 --- a/test/desktop-lite/scenarios.json +++ b/test/desktop-lite/scenarios.json @@ -4,5 +4,32 @@ "features": { "desktop-lite": {} } + }, + "test_vnc_resolution_as_container_env_var": { + "image": "ubuntu:noble", + "features": { + "desktop-lite": {} + } + , + "containerEnv": { + "VNC_RESOLUTION": "1920x1080x32" + }, + "forwardPorts": [ + 5901, + 6080 + ] + }, + "test_vnc_resolution_as_remote_env_var": { + "image": "ubuntu:noble", + "features": { + "desktop-lite": {} + }, + "remoteEnv": { + "VNC_RESOLUTION": "1920x1080x32" + }, + "forwardPorts": [ + 5901, + 6080 + ] } } \ No newline at end of file diff --git a/test/desktop-lite/test_vnc_resolution_as_container_env_var.sh b/test/desktop-lite/test_vnc_resolution_as_container_env_var.sh new file mode 100644 index 000000000..cc3dd3261 --- /dev/null +++ b/test/desktop-lite/test_vnc_resolution_as_container_env_var.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +GREEN='\033[0;32m'; NC='\033[0m'; RED='\033[0;31m'; YELLOW='\033[0;33m'; + +# Check if xtigervnc & noVnc processes are running after successful installation and initialization +check_process_running() { + port=$1 + # Get process id of process running on specific port + PID=$(lsof -i :$port | awk 'NR==2 {print $2}') + if [ -n "$PID" ]; then + CMD=$(ps -p $PID -o cmd --no-headers) + echo -e "${GREEN}Command running on port $port: ${YELLOW}$CMD${NC}" + else + echo -e "${RED}No process found listening on port $port.${NC}" + exit 1 + fi +} + +check_w_config_resolution() { + configResolution=$1 + actualResolution=$2 + + if echo "$1" | grep -q "$2"; then + echo -e "\nšŸ‘šŸ‘ ${GREEN}Configured resolution i.e. ${YELLOW}$configResolution${GREEN} has been set as vnc resolution i.e. ${YELLOW}$actualResolution${GREEN} in container.${NC}" + else + echo -e "\nāŒāŒ ${GREEN}Configured resolution i.e. ${YELLOW}$configResolution${GREEN} couldn't be set as vnc resolution i.e. ${YELLOW}$actualResolution${GREEN} in container.${NC}" + fi +} + +check "Whether xtigervnc is Running" check_process_running 5901 +resolution=$(ps -x -ww | grep Xtigervnc | awk "{for(i=1;i<=NF;i++) if (\$i ~ /-geometry/) {print \$(i+1); exit}}") +check "xtigervnc resolution" bash -c '$resolution' +check_w_config_resolution $VNC_RESOLUTION $resolution +sleep 2 +check "Whether no_vnc is Running" check_process_running 6080 + +check "desktop-init-exists" bash -c "ls /usr/local/share/desktop-init.sh" +check "log-exists" bash -c "ls /tmp/container-init.log" +check "log file contents" bash -c "cat /tmp/container-init.log" + +# Report result +reportResults \ No newline at end of file diff --git a/test/desktop-lite/test_vnc_resolution_as_remote_env_var.sh b/test/desktop-lite/test_vnc_resolution_as_remote_env_var.sh new file mode 100644 index 000000000..18409505c --- /dev/null +++ b/test/desktop-lite/test_vnc_resolution_as_remote_env_var.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +# Check if xtigervnc & noVnc processes are running after successful installation and initialization +check_process_running() { + port=$1 + # Get process id of process running on specific port + PID=$(lsof -i :$port | awk 'NR==2 {print $2}') + GREEN='\033[0;32m'; NC='\033[0m'; RED='\033[0;31m'; YELLOW='\033[0;33m'; + if [ -n "$PID" ]; then + CMD=$(ps -p $PID -o cmd --no-headers) + echo -e "${GREEN}Command running on port $port: ${YELLOW}$CMD${NC}" + else + echo -e "${RED}No process found listening on port $port.${NC}" + exit 1 + fi +} + +check "Whether xtigervnc is Running" check_process_running 5901 +check "xtigervnc resolution" bash -c 'ps -x -ww | grep Xtigervnc | awk "{for(i=1;i<=NF;i++) if (\$i ~ /-geometry/) {print \$(i+1); exit}}"' +sleep 2 +check "Whether no_vnc is Running" check_process_running 6080 + +check "desktop-init-exists" bash -c "ls /usr/local/share/desktop-init.sh" +check "log-exists" bash -c "ls /tmp/container-init.log" +check "log file contents" bash -c "cat /tmp/container-init.log" + +# Report result +reportResults \ No newline at end of file