This repository was archived by the owner on May 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
Merged
kasm VNC #250
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
9b9dd76
wip
matifali f68b31b
add kasmVNC
matifali aabf35c
TODO
matifali dec64c7
fixup!
matifali bf90b16
update tags
matifali 92794a2
Delete .icons/kasm.png
matifali d44bd60
Update README.md
matifali 1ac4840
Update main.tf
matifali 805f692
merge `main`
matifali 0fa43a7
`bun fmt`
matifali 048cffb
bump version and fix typo
matifali 2318f31
update KasmVNC version to 1.0.15 in README.md files
matifali 6009778
rename version to kasm_version
matifali 3333d3a
improve compatibility and cleanup
matifali d6e6cb3
update README.md
matifali b308ea5
fixup!
matifali 41ef969
fixup!
matifali 6698cb8
Install libdatetime-perl
matifali c8cdc95
fixup!
matifali c8db45e
fixup!
matifali a6c449e
add healtcheck
matifali b697e72
Merge branch 'main' into kasmVNC
matifali d5b49c2
Merge branch 'main' into kasmVNC
matifali f00f8de
chore: Update KasmVNC to use XFCE desktop environment
matifali a76095f
Merge branch 'main' into kasmVNC
matifali a254fd3
remove options
matifali 71a2e6c
add wait for script
matifali 39bc745
fixup!
matifali c2698be
fixup!
matifali d61f14d
fixup!
matifali 12e4d35
`bun fmt`
matifali eda0e5d
Merge branch 'main' into kasmVNC
matifali de525a3
Merge branch 'main' into kasmVNC
matifali 6017b05
Refactor KasmVNC installation script logic
matifali 2ee02a3
fix: remove duplicate validation value
Parkreiner 59041b3
chore: get basic tests in place
Parkreiner 3ce7ef5
fix: update test text for more clarity
Parkreiner 382c76b
Merge branch 'main' into kasmVNC
matifali c10a2ba
Bump KasmVNC module version to 1.0.20
matifali cf3159c
Update README.md
matifali c6895b5
Update KasmVNC to version 1.3.2 and add support
matifali 4020ec0
Refine architecture mapping for specific distros
matifali f4cdb15
fix(kasmvnc): correct .deb file installation path
matifali 18570aa
Improve Debian package installation command
matifali a63c365
Fix RPM installation path in kasmvnc script
matifali 43a353c
Update README.md
matifali 05135af
Merge branch 'main' into kasmVNC
matifali 457621c
update version
matifali File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
display_name: KasmVNC | ||
description: A modern open source VNC server | ||
icon: ../.icons/kasmvnc.svg | ||
maintainer_github: coder | ||
verified: true | ||
tags: [helper, vnc, desktop] | ||
--- | ||
|
||
# KasmVNC | ||
|
||
Automatically install [KasmVNC](https://kasmweb.com/kasmvnc) in a workspace, and create an app to access it via the dashboard. | ||
|
||
```tf | ||
module "kasmvnc" { | ||
source = "registry.coder.com/modules/kasmvnc/coder" | ||
version = "1.0.21" | ||
agent_id = coder_agent.example.id | ||
desktop_environment = "xfce" | ||
} | ||
``` | ||
|
||
> **Note:** This module only works on workspaces with a pre-installed desktop environment. As an example base image you can use `codercom/enterprise-desktop` image. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { describe, expect, it } from "bun:test"; | ||
import { | ||
runTerraformApply, | ||
runTerraformInit, | ||
testRequiredVariables, | ||
} from "../test"; | ||
|
||
const allowedDesktopEnvs = ["xfce", "kde", "gnome", "lxde", "lxqt"] as const; | ||
type AllowedDesktopEnv = (typeof allowedDesktopEnvs)[number]; | ||
|
||
type TestVariables = Readonly<{ | ||
agent_id: string; | ||
desktop_environment: AllowedDesktopEnv; | ||
port?: string; | ||
kasm_version?: string; | ||
}>; | ||
|
||
describe("Kasm VNC", async () => { | ||
await runTerraformInit(import.meta.dir); | ||
testRequiredVariables<TestVariables>(import.meta.dir, { | ||
agent_id: "foo", | ||
desktop_environment: "gnome", | ||
}); | ||
|
||
it("Successfully installs for all expected Kasm desktop versions", async () => { | ||
for (const v of allowedDesktopEnvs) { | ||
const applyWithEnv = () => { | ||
runTerraformApply<TestVariables>(import.meta.dir, { | ||
agent_id: "foo", | ||
desktop_environment: v, | ||
}); | ||
}; | ||
|
||
expect(applyWithEnv).not.toThrow(); | ||
} | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
terraform { | ||
required_version = ">= 1.0" | ||
|
||
required_providers { | ||
coder = { | ||
source = "coder/coder" | ||
version = ">= 0.12" | ||
} | ||
} | ||
} | ||
|
||
variable "agent_id" { | ||
type = string | ||
description = "The ID of a Coder agent." | ||
} | ||
|
||
variable "port" { | ||
type = number | ||
description = "The port to run KasmVNC on." | ||
default = 6800 | ||
} | ||
|
||
variable "kasm_version" { | ||
type = string | ||
description = "Version of KasmVNC to install." | ||
default = "1.3.2" | ||
} | ||
|
||
variable "desktop_environment" { | ||
type = string | ||
description = "Specifies the desktop environment of the workspace. This should be pre-installed on the workspace." | ||
validation { | ||
condition = contains(["xfce", "kde", "gnome", "lxde", "lxqt"], var.desktop_environment) | ||
error_message = "Invalid desktop environment. Please specify a valid desktop environment." | ||
} | ||
} | ||
|
||
resource "coder_script" "kasm_vnc" { | ||
agent_id = var.agent_id | ||
display_name = "KasmVNC" | ||
icon = "/icon/kasmvnc.svg" | ||
script = templatefile("${path.module}/run.sh", { | ||
PORT : var.port, | ||
DESKTOP_ENVIRONMENT : var.desktop_environment, | ||
VERSION : var.kasm_version | ||
}) | ||
run_on_start = true | ||
} | ||
|
||
resource "coder_app" "kasm_vnc" { | ||
agent_id = var.agent_id | ||
slug = "kasm-vnc" | ||
display_name = "kasmVNC" | ||
url = "http://localhost:${var.port}" | ||
icon = "/icon/kasmvnc.svg" | ||
subdomain = true | ||
share = "owner" | ||
healthcheck { | ||
url = "http://localhost:${var.port}/app" | ||
interval = 5 | ||
threshold = 5 | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
#!/usr/bin/env bash | ||
matifali marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#!/bin/bash | ||
|
||
# Function to check if vncserver is already installed | ||
check_installed() { | ||
if command -v vncserver &> /dev/null; then | ||
echo "vncserver is already installed." | ||
return 0 # Don't exit, just indicate it's installed | ||
else | ||
return 1 # Indicates not installed | ||
fi | ||
} | ||
|
||
# Function to install kasmvncserver for debian-based distros | ||
install_deb() { | ||
local url=$1 | ||
wget $url -O /tmp/kasmvncserver.deb | ||
sudo apt-get install --yes --no-install-recommends --no-install-suggests /tmp/kasmvncserver.deb | ||
sudo adduser $USER ssl-cert | ||
rm /tmp/kasmvncserver.deb | ||
} | ||
|
||
# Function to install kasmvncserver for Oracle 8 | ||
install_rpm_oracle8() { | ||
local url=$1 | ||
wget $url -O /tmp/kasmvncserver.rpm | ||
sudo dnf config-manager --set-enabled ol8_codeready_builder | ||
sudo dnf install oracle-epel-release-el8 -y | ||
sudo dnf localinstall /tmp/kasmvncserver.rpm -y | ||
sudo usermod -aG kasmvnc-cert $USER | ||
rm /tmp/kasmvncserver.rpm | ||
} | ||
|
||
# Function to install kasmvncserver for CentOS 7 | ||
install_rpm_centos7() { | ||
local url=$1 | ||
wget $url -O /tmp/kasmvncserver.rpm | ||
sudo yum install epel-release -y | ||
sudo yum install /tmp/kasmvncserver.rpm -y | ||
sudo usermod -aG kasmvnc-cert $USER | ||
rm /tmp/kasmvncserver.rpm | ||
} | ||
|
||
# Function to install kasmvncserver for rpm-based distros | ||
install_rpm() { | ||
local url=$1 | ||
wget $url -O /tmp/kasmvncserver.rpm | ||
sudo rpm -i /tmp/kasmvncserver.rpm | ||
rm /tmp/kasmvncserver.rpm | ||
} | ||
|
||
# Function to install kasmvncserver for Alpine Linux | ||
install_alpine() { | ||
local url=$1 | ||
wget $url -O /tmp/kasmvncserver.tgz | ||
tar -xzf /tmp/kasmvncserver.tgz -C /usr/local/bin/ | ||
rm /tmp/kasmvncserver.tgz | ||
} | ||
|
||
# Detect system information | ||
distro=$(grep "^ID=" /etc/os-release | awk -F= '{print $2}') | ||
version=$(grep "^VERSION_ID=" /etc/os-release | awk -F= '{print $2}' | tr -d '"') | ||
arch=$(uname -m) | ||
|
||
echo "Detected Distribution: $distro" | ||
echo "Detected Version: $version" | ||
echo "Detected Architecture: $arch" | ||
|
||
# Map arch to package arch | ||
if [[ "$arch" == "x86_64" ]]; then | ||
if [[ "$distro" == "ubuntu" || "$distro" == "debian" || "$distro" == "kali" ]]; then | ||
arch="amd64" | ||
else | ||
arch="x86_64" | ||
fi | ||
elif [[ "$arch" == "aarch64" || "$arch" == "arm64" ]]; then | ||
if [[ "$distro" == "ubuntu" || "$distro" == "debian" || "$distro" == "kali" ]]; then | ||
arch="arm64" | ||
else | ||
arch="aarch64" | ||
fi | ||
else | ||
echo "Unsupported architecture: $arch" | ||
exit 1 | ||
fi | ||
|
||
# Check if vncserver is installed, and install if not | ||
if ! check_installed; then | ||
case $distro in | ||
ubuntu | debian | kali) | ||
case $version in | ||
"20.04") | ||
install_deb "https://github.com/kasmtech/KasmVNC/releases/download/v${VERSION}/kasmvncserver_focal_${VERSION}_$${arch}.deb" | ||
;; | ||
"22.04") | ||
install_deb "https://github.com/kasmtech/KasmVNC/releases/download/v${VERSION}/kasmvncserver_jammy_${VERSION}_$${arch}.deb" | ||
;; | ||
"24.04") | ||
install_deb "https://github.com/kasmtech/KasmVNC/releases/download/v${VERSION}/kasmvncserver_noble_${VERSION}_$${arch}.deb" | ||
;; | ||
*) | ||
echo "Unsupported Ubuntu/Debian/Kali version: $${version}" | ||
exit 1 | ||
;; | ||
esac | ||
;; | ||
oracle) | ||
if [[ "$version" == "8" ]]; then | ||
install_rpm_oracle8 "https://github.com/kasmtech/KasmVNC/releases/download/v${VERSION}/kasmvncserver_oracle_8_${VERSION}_$${arch}.rpm" | ||
else | ||
echo "Unsupported Oracle version: $${version}" | ||
exit 1 | ||
fi | ||
;; | ||
centos) | ||
if [[ "$version" == "7" ]]; then | ||
install_rpm_centos7 "https://github.com/kasmtech/KasmVNC/releases/download/v${VERSION}/kasmvncserver_centos_core_${VERSION}_$${arch}.rpm" | ||
else | ||
install_rpm "http 92AF s://github.com/kasmtech/KasmVNC/releases/download/v${VERSION}/kasmvncserver_centos_core_${VERSION}_$${arch}.rpm" | ||
fi | ||
;; | ||
alpine) | ||
if [[ "$version" == "3.17" || "$version" == "3.18" || "$version" == "3.19" || "$version" == "3.20" ]]; then | ||
install_alpine "https://github.com/kasmtech/KasmVNC/releases/download/v${VERSION}/kasmvnc.alpine_$${version}_$${arch}.tgz" | ||
else | ||
echo "Unsupported Alpine version: $${version}" | ||
exit 1 | ||
fi | ||
;; | ||
fedora | opensuse) | ||
install_rpm "https://github.com/kasmtech/KasmVNC/releases/download/v${VERSION}/kasmvncserver_$${distro}_$${version}_${VERSION}_$${arch}.rpm" | ||
;; | ||
*) | ||
echo "Unsupported distribution: $${distro}" | ||
exit 1 | ||
;; | ||
esac | ||
else | ||
echo "vncserver already installed. Skipping installation." | ||
fi | ||
|
||
# Coder port-forwarding from dashboard only supports HTTP | ||
sudo bash -c "cat > /etc/kasmvnc/kasmvnc.yaml <<EOF | ||
network: | ||
protocol: http | ||
websocket_port: ${PORT} | ||
ssl: | ||
require_ssl: false | ||
udp: | ||
public_ip: 127.0.0.1 | ||
EOF" | ||
|
||
# This password is not used since we start the server without auth. | ||
# The server is protected via the Coder session token / tunnel | ||
# and does not listen publicly | ||
echo -e "password\npassword\n" | vncpasswd -wo -u $USER | ||
|
||
# Start the server | ||
printf "🚀 Starting KasmVNC server...\n" | ||
sudo -u $USER bash -c "vncserver -select-de ${DESKTOP_ENVIRONMENT} -disableBasicAuth" > /tmp/kasmvncserver.log 2>&1 & |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.