diff --git a/kasmvnc/README.md b/kasmvnc/README.md index 1803268..1b16dad 100644 --- a/kasmvnc/README.md +++ b/kasmvnc/README.md @@ -4,7 +4,7 @@ description: A modern open source VNC server icon: ../.icons/kasmvnc.svg maintainer_github: coder verified: true -tags: [helper, ide] +tags: [helper, ide, VNC] --- # KasmVNC @@ -13,4 +13,27 @@ Automatically install [KasmVNC](https://kasmweb.com/kasmvnc) in a workspace, and ## Examples -TODO \ No newline at end of file +1. Add latest version of KasmVNC with [`lxde`](https://www.lxde.org/) desktop environment: + + ```hcl + module "kasmvnc" { + source = "https://registry.coder.com/modules/kasmvnc" + agent_id = coder_agent.example.id + } + + ``` + +2. Add specific version of KasmVNC with [`mate`](https://mate-desktop.org/) desktop environment and custom port: + + ```hcl + module "kasmvnc" { + source = "https://registry.coder.com/modules/kasmvnc" + agent_id = coder_agent.example.id + version = "1.0.0" + desktop_environment = "mate" + port = 6080 + } + + ``` + +![Screenshot of KasmVNC]() //TODO diff --git a/kasmvnc/main.tf b/kasmvnc/main.tf new file mode 100644 index 0000000..6fd0ba4 --- /dev/null +++ b/kasmvnc/main.tf @@ -0,0 +1,55 @@ +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 = 8443 +} + +variable "desktop_environment" { + type = string + description = "The desktop environment to for KasmVNC (xfce, lxde, mate, etc)." + default = "lxde" +} + +variable "version" { + type = string + description = "Version of KasmVNC to install." + default = "1.2.0" +} + +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.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 = false + share = "owner" +} diff --git a/kasmvnc/run.sh b/kasmvnc/run.sh new file mode 100644 index 0000000..7a59580 --- /dev/null +++ b/kasmvnc/run.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +# Check if desktop enivronment is installed +if ! dpkg -s ${DESKTOP_ENVIRONMENT} &>/dev/null; then + sudo apt-get update + DEBIAN_FRONTEND=noninteractive sudo apt-get install -y ${DESKTOP_ENVIRONMENT} +else + echo "${DESKTOP_ENVIRONMENT} is already installed." +fi + +# Check if vncserver is installed +if ! dpkg -s kasmvncserver &>/dev/null; then + cd /tmp + wget https://github.com/kasmtech/KasmVNC/releases/download/v${VERSION}/kasmvncserver_focal_${VERSION}_amd64.deb + sudo apt install -y ./kasmvncserver_focal_${VERSION}_amd64.deb + printf "🥳 KasmVNC v${VERSION} has been successfully installed!\n\n" +else + echo "KasmVNC is already installed." +fi + +sudo addgroup $USER ssl-cert + +# Coder port-forwarding from dashboard only supports HTTP +sudo bash -c 'cat > /etc/kasmvnc/kasmvnc.yaml <