From 8b1294a17c44cd6491838e1b210191e83bd37af2 Mon Sep 17 00:00:00 2001 From: Gaurav Saini <147703805+gauravsaini04@users.noreply.github.com> Date: Mon, 2 Sep 2024 10:06:28 +0000 Subject: [PATCH 1/5] [desktop-lite] - vnc_resolution - set thru env var --- src/desktop-lite/install.sh | 12 +++---- test/desktop-lite/scenarios.json | 16 +++++++++ .../test_vnc_resolution_as_env_var.sh | 33 +++++++++++++++++++ 3 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 test/desktop-lite/test_vnc_resolution_as_env_var.sh diff --git a/src/desktop-lite/install.sh b/src/desktop-lite/install.sh index 5060f9210..c334b222c 100755 --- a/src/desktop-lite/install.sh +++ b/src/desktop-lite/install.sh @@ -296,15 +296,15 @@ EOF cat << EOF > /usr/local/share/desktop-init.sh #!/bin/bash -user_name="${USERNAME}" +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..7789f5eae 100644 --- a/test/desktop-lite/scenarios.json +++ b/test/desktop-lite/scenarios.json @@ -4,5 +4,21 @@ "features": { "desktop-lite": {} } + }, + "test_vnc_resolution_as_env_var": { + "image": "ubuntu:noble", + "features": { + "desktop-lite": {}, + "containerEnv": { + "VNC_RESOLUTION": "1920x1080x32" + }, + "remoteEnv": { + "VNC_RESOLUTION": "1920x1080x32" + }, + "forwardPorts": [ + 5901, + 6080 + ] + } } } \ No newline at end of file diff --git a/test/desktop-lite/test_vnc_resolution_as_env_var.sh b/test/desktop-lite/test_vnc_resolution_as_env_var.sh new file mode 100644 index 000000000..18409505c --- /dev/null +++ b/test/desktop-lite/test_vnc_resolution_as_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 From a302402978f5f9912bdede16982812514ca6408f Mon Sep 17 00:00:00 2001 From: Gaurav Saini <147703805+gauravsaini04@users.noreply.github.com> Date: Mon, 2 Sep 2024 10:14:33 +0000 Subject: [PATCH 2/5] mistake in scenarios.json corrected --- test/desktop-lite/scenarios.json | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/test/desktop-lite/scenarios.json b/test/desktop-lite/scenarios.json index 7789f5eae..48ac1087b 100644 --- a/test/desktop-lite/scenarios.json +++ b/test/desktop-lite/scenarios.json @@ -8,17 +8,18 @@ "test_vnc_resolution_as_env_var": { "image": "ubuntu:noble", "features": { - "desktop-lite": {}, - "containerEnv": { - "VNC_RESOLUTION": "1920x1080x32" - }, - "remoteEnv": { - "VNC_RESOLUTION": "1920x1080x32" - }, - "forwardPorts": [ - 5901, - 6080 - ] + "desktop-lite": {} } + , + "containerEnv": { + "VNC_RESOLUTION": "1920x1080x32" + }, + "remoteEnv": { + "VNC_RESOLUTION": "1920x1080x32" + }, + "forwardPorts": [ + 5901, + 6080 + ] } } \ No newline at end of file From 71bf03e9f5b913c40c430792b84529dc4de45e13 Mon Sep 17 00:00:00 2001 From: Gaurav Saini <147703805+gauravsaini04@users.noreply.github.com> Date: Mon, 2 Sep 2024 10:31:22 +0000 Subject: [PATCH 3/5] small change of function addition in desktop-init.sh file --- src/desktop-lite/install.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/desktop-lite/install.sh b/src/desktop-lite/install.sh index c334b222c..bb0227e2f 100755 --- a/src/desktop-lite/install.sh +++ b/src/desktop-lite/install.sh @@ -296,7 +296,7 @@ EOF cat << EOF > /usr/local/share/desktop-init.sh #!/bin/bash -user_name="\${USERNAME}" +user_name="${USERNAME}" group_name="$(id -gn ${USERNAME})" LOG=/tmp/container-init.log @@ -329,10 +329,18 @@ keepRunningInBackground() (\$2 bash -c "while :; do echo [\\\$(date)] Process started.; \$3; echo [\\\$(date)] Process exited!; sleep 5; done 2>&1" | sudoIf tee -a /tmp/\$1.log > /dev/null & echo "\$!" | sudoIf tee /tmp/\$1.pid > /dev/null) } +check_packages() { + if ! dpkg -s "\$@" > /dev/null 2>&1; then + apt_get_update + apt-get -y install --no-install-recommends "\$@" + fi +} + # Use sudo to run as root when required sudoIf() { if [ "\$(id -u)" -ne 0 ]; then + check_packages sudo sudo "\$@" else "\$@" From 4388820dbca5a266f6440d3dbab49dbd441ef4a2 Mon Sep 17 00:00:00 2001 From: Gaurav Saini <147703805+gauravsaini04@users.noreply.github.com> Date: Thu, 5 Sep 2024 02:27:29 +0000 Subject: [PATCH 4/5] changes as requested (review pr) --- src/desktop-lite/devcontainer-feature.json | 2 +- src/desktop-lite/install.sh | 8 ----- test/desktop-lite/scenarios.json | 12 ++++++- ...st_vnc_resolution_as_container_env_var.sh} | 0 .../test_vnc_resolution_as_remote_env_var.sh | 33 +++++++++++++++++++ 5 files changed, 45 insertions(+), 10 deletions(-) rename test/desktop-lite/{test_vnc_resolution_as_env_var.sh => test_vnc_resolution_as_container_env_var.sh} (100%) 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 bb0227e2f..6e6fff265 100755 --- a/src/desktop-lite/install.sh +++ b/src/desktop-lite/install.sh @@ -329,18 +329,10 @@ keepRunningInBackground() (\$2 bash -c "while :; do echo [\\\$(date)] Process started.; \$3; echo [\\\$(date)] Process exited!; sleep 5; done 2>&1" | sudoIf tee -a /tmp/\$1.log > /dev/null & echo "\$!" | sudoIf tee /tmp/\$1.pid > /dev/null) } -check_packages() { - if ! dpkg -s "\$@" > /dev/null 2>&1; then - apt_get_update - apt-get -y install --no-install-recommends "\$@" - fi -} - # Use sudo to run as root when required sudoIf() { if [ "\$(id -u)" -ne 0 ]; then - check_packages sudo sudo "\$@" else "\$@" diff --git a/test/desktop-lite/scenarios.json b/test/desktop-lite/scenarios.json index 48ac1087b..ab920ddb9 100644 --- a/test/desktop-lite/scenarios.json +++ b/test/desktop-lite/scenarios.json @@ -5,7 +5,7 @@ "desktop-lite": {} } }, - "test_vnc_resolution_as_env_var": { + "test_vnc_resolution_as_container_env_var": { "image": "ubuntu:noble", "features": { "desktop-lite": {} @@ -14,6 +14,16 @@ "containerEnv": { "VNC_RESOLUTION": "1920x1080x32" }, + "forwardPorts": [ + 5901, + 6080 + ] + }, + "test_vnc_resolution_as_remote_env_var": { + "image": "ubuntu:noble", + "features": { + "desktop-lite": {} + }, "remoteEnv": { "VNC_RESOLUTION": "1920x1080x32" }, diff --git a/test/desktop-lite/test_vnc_resolution_as_env_var.sh b/test/desktop-lite/test_vnc_resolution_as_container_env_var.sh similarity index 100% rename from test/desktop-lite/test_vnc_resolution_as_env_var.sh rename to test/desktop-lite/test_vnc_resolution_as_container_env_var.sh 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 From bf0c2069bb37bd8f1162ed7dd8a4f8b3d0b1c242 Mon Sep 17 00:00:00 2001 From: Gaurav Saini <147703805+gauravsaini04@users.noreply.github.com> Date: Sat, 7 Sep 2024 00:20:46 +0000 Subject: [PATCH 5/5] changes as suggested --- ...test_vnc_resolution_as_container_env_var.sh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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 index 18409505c..cc3dd3261 100644 --- a/test/desktop-lite/test_vnc_resolution_as_container_env_var.sh +++ b/test/desktop-lite/test_vnc_resolution_as_container_env_var.sh @@ -5,12 +5,13 @@ 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}') - 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}" @@ -20,8 +21,21 @@ check_process_running() { 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 -check "xtigervnc resolution" bash -c 'ps -x -ww | grep Xtigervnc | awk "{for(i=1;i<=NF;i++) if (\$i ~ /-geometry/) {print \$(i+1); exit}}"' +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