Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f5ab7995d1 | ||
|
|
528a8a9fea | ||
|
|
87854707bc | ||
|
|
b53554b4e4 | ||
|
|
ce5a5b383a | ||
|
|
1b147ae90d | ||
|
|
7992d9d265 | ||
|
|
20d97a25dd | ||
|
|
8e0dfcd534 | ||
|
|
9752bf89a6 | ||
|
|
48c81c9ff4 | ||
|
|
acd5edffe7 | ||
|
|
4dcab99cb0 | ||
|
|
50a946df0f | ||
|
|
8a0ac3435c | ||
|
|
438c904567 |
2
.github/workflows/ci.yaml
vendored
2
.github/workflows/ci.yaml
vendored
@@ -17,6 +17,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: coder/coder/.github/actions/setup-tf@main
|
||||
- uses: oven-sh/setup-bun@v2
|
||||
with:
|
||||
bun-version: latest
|
||||
@@ -29,6 +30,7 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # Needed to get tags
|
||||
- uses: coder/coder/.github/actions/setup-tf@main
|
||||
- uses: oven-sh/setup-bun@v2
|
||||
with:
|
||||
bun-version: latest
|
||||
|
||||
@@ -47,6 +47,7 @@ You can test a module locally by updating the source as follows
|
||||
```tf
|
||||
module "example" {
|
||||
source = "git::https://github.com/<USERNAME>/<REPO>.git//<MODULE-NAME>?ref=<BRANCH-NAME>"
|
||||
# You may need to remove the 'version' field, it is incompatible with some sources.
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import {
|
||||
executeScriptInContainer,
|
||||
runTerraformApply,
|
||||
runTerraformInit,
|
||||
testRequiredVariables,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import {
|
||||
executeScriptInContainer,
|
||||
runTerraformApply,
|
||||
runTerraformInit,
|
||||
testRequiredVariables,
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import {
|
||||
executeScriptInContainer,
|
||||
runTerraformApply,
|
||||
runTerraformInit,
|
||||
testRequiredVariables,
|
||||
} from "../test";
|
||||
import { describe } from "bun:test";
|
||||
import { runTerraformInit, testRequiredVariables } from "../test";
|
||||
|
||||
describe("coder-login", async () => {
|
||||
await runTerraformInit(import.meta.dir);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import {
|
||||
executeScriptInContainer,
|
||||
runTerraformApply,
|
||||
runTerraformInit,
|
||||
testRequiredVariables,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import {
|
||||
executeScriptInContainer,
|
||||
runTerraformApply,
|
||||
runTerraformInit,
|
||||
testRequiredVariables,
|
||||
|
||||
@@ -14,7 +14,7 @@ A file browser for your workspace.
|
||||
```tf
|
||||
module "filebrowser" {
|
||||
source = "registry.coder.com/modules/filebrowser/coder"
|
||||
version = "1.0.19"
|
||||
version = "1.0.23"
|
||||
agent_id = coder_agent.example.id
|
||||
}
|
||||
```
|
||||
@@ -28,7 +28,7 @@ module "filebrowser" {
|
||||
```tf
|
||||
module "filebrowser" {
|
||||
source = "registry.coder.com/modules/filebrowser/coder"
|
||||
version = "1.0.19"
|
||||
version = "1.0.23"
|
||||
agent_id = coder_agent.example.id
|
||||
folder = "/home/coder/project"
|
||||
}
|
||||
@@ -39,7 +39,7 @@ module "filebrowser" {
|
||||
```tf
|
||||
module "filebrowser" {
|
||||
source = "registry.coder.com/modules/filebrowser/coder"
|
||||
version = "1.0.19"
|
||||
version = "1.0.23"
|
||||
agent_id = coder_agent.example.id
|
||||
database_path = ".config/filebrowser.db"
|
||||
}
|
||||
|
||||
@@ -20,13 +20,8 @@ data "coder_workspace_owner" "me" {}
|
||||
|
||||
variable "agent_name" {
|
||||
type = string
|
||||
description = "The name of the main deployment. (Used to build the subpath for coder_app.)"
|
||||
default = ""
|
||||
validation {
|
||||
# If subdomain is false, then agent_name must be set.
|
||||
condition = var.subdomain || var.agent_name != ""
|
||||
error_message = "The agent_name must be set."
|
||||
}
|
||||
description = "The name of the coder_agent resource. (Only required if subdomain is false and the template uses multiple agents.)"
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "database_path" {
|
||||
@@ -73,6 +68,12 @@ variable "order" {
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "slug" {
|
||||
type = string
|
||||
description = "The slug of the coder_app resource."
|
||||
default = "filebrowser"
|
||||
}
|
||||
|
||||
variable "subdomain" {
|
||||
type = bool
|
||||
description = <<-EOT
|
||||
@@ -85,7 +86,7 @@ variable "subdomain" {
|
||||
resource "coder_script" "filebrowser" {
|
||||
agent_id = var.agent_id
|
||||
display_name = "File Browser"
|
||||
icon = "https://raw.githubusercontent.com/filebrowser/logo/master/icon_raw.svg"
|
||||
icon = "/icon/filebrowser.svg"
|
||||
script = templatefile("${path.module}/run.sh", {
|
||||
LOG_PATH : var.log_path,
|
||||
PORT : var.port,
|
||||
@@ -93,18 +94,30 @@ resource "coder_script" "filebrowser" {
|
||||
LOG_PATH : var.log_path,
|
||||
DB_PATH : var.database_path,
|
||||
SUBDOMAIN : var.subdomain,
|
||||
SERVER_BASE_PATH : var.subdomain ? "" : format("/@%s/%s.%s/apps/filebrowser", data.coder_workspace_owner.me.name, data.coder_workspace.me.name, var.agent_name),
|
||||
SERVER_BASE_PATH : local.server_base_path
|
||||
})
|
||||
run_on_start = true
|
||||
}
|
||||
|
||||
resource "coder_app" "filebrowser" {
|
||||
agent_id = var.agent_id
|
||||
slug = "filebrowser"
|
||||
slug = var.slug
|
||||
display_name = "File Browser"
|
||||
url = "http://localhost:${var.port}"
|
||||
icon = "https://raw.githubusercontent.com/filebrowser/logo/master/icon_raw.svg"
|
||||
url = local.url
|
||||
icon = "/icon/filebrowser.svg"
|
||||
subdomain = var.subdomain
|
||||
share = var.share
|
||||
order = var.order
|
||||
|
||||
healthcheck {
|
||||
url = local.healthcheck_url
|
||||
interval = 5
|
||||
threshold = 6
|
||||
}
|
||||
}
|
||||
|
||||
locals {
|
||||
server_base_path = var.subdomain ? "" : format("/@%s/%s%s/apps/%s", data.coder_workspace_owner.me.name, data.coder_workspace.me.name, var.agent_name != null ? ".${var.agent_name}" : "", var.slug)
|
||||
url = "http://localhost:${var.port}${local.server_base_path}"
|
||||
healthcheck_url = "http://localhost:${var.port}${local.server_base_path}/health"
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
BOLD='\033[0;1m'
|
||||
|
||||
printf "$${BOLD}Installing filebrowser \n\n"
|
||||
|
||||
curl -fsSL https://raw.githubusercontent.com/filebrowser/get/master/get.sh | bash
|
||||
# Check if filebrowser is installed
|
||||
if ! command -v filebrowser &> /dev/null; then
|
||||
curl -fsSL https://raw.githubusercontent.com/filebrowser/get/master/get.sh | bash
|
||||
fi
|
||||
|
||||
printf "🥳 Installation complete! \n\n"
|
||||
|
||||
@@ -18,7 +22,7 @@ if [ "${DB_PATH}" != "filebrowser.db" ]; then
|
||||
fi
|
||||
|
||||
# set baseurl to be able to run if sudomain=false; if subdomain=true the SERVER_BASE_PATH value will be ""
|
||||
filebrowser config set --baseurl "${SERVER_BASE_PATH}" > ${LOG_PATH} 2>&1
|
||||
filebrowser config set --baseurl "${SERVER_BASE_PATH}"$${DB_FLAG} > ${LOG_PATH} 2>&1
|
||||
|
||||
printf "📂 Serving $${ROOT_DIR} at http://localhost:${PORT} \n\n"
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { type Server, serve } from "bun";
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import {
|
||||
createJSONResponse,
|
||||
@@ -9,7 +10,6 @@ import {
|
||||
testRequiredVariables,
|
||||
writeCoder,
|
||||
} from "../test";
|
||||
import { Server, serve } from "bun";
|
||||
|
||||
describe("github-upload-public-key", async () => {
|
||||
await runTerraformInit(import.meta.dir);
|
||||
@@ -21,10 +21,12 @@ describe("github-upload-public-key", async () => {
|
||||
it("creates new key if one does not exist", async () => {
|
||||
const { instance, id, server } = await setupContainer();
|
||||
await writeCoder(id, "echo foo");
|
||||
let exec = await execContainer(id, [
|
||||
|
||||
const url = server.url.toString().slice(0, -1);
|
||||
const exec = await execContainer(id, [
|
||||
"env",
|
||||
"CODER_ACCESS_URL=" + server.url.toString().slice(0, -1),
|
||||
"GITHUB_API_URL=" + server.url.toString().slice(0, -1),
|
||||
`CODER_ACCESS_URL=${url}`,
|
||||
`GITHUB_API_URL=${url}`,
|
||||
"CODER_OWNER_SESSION_TOKEN=foo",
|
||||
"CODER_EXTERNAL_AUTH_ID=github",
|
||||
"bash",
|
||||
@@ -42,10 +44,12 @@ describe("github-upload-public-key", async () => {
|
||||
const { instance, id, server } = await setupContainer();
|
||||
// use keyword to make server return a existing key
|
||||
await writeCoder(id, "echo findkey");
|
||||
let exec = await execContainer(id, [
|
||||
|
||||
const url = server.url.toString().slice(0, -1);
|
||||
const exec = await execContainer(id, [
|
||||
"env",
|
||||
"CODER_ACCESS_URL=" + server.url.toString().slice(0, -1),
|
||||
"GITHUB_API_URL=" + server.url.toString().slice(0, -1),
|
||||
`CODER_ACCESS_URL=${url}`,
|
||||
`GITHUB_API_URL=${url}`,
|
||||
"CODER_OWNER_SESSION_TOKEN=foo",
|
||||
"CODER_EXTERNAL_AUTH_ID=github",
|
||||
"bash",
|
||||
@@ -95,7 +99,7 @@ const setupServer = async (): Promise<Server> => {
|
||||
}
|
||||
|
||||
// case: key already exists
|
||||
if (req.headers.get("Authorization") == "Bearer findkey") {
|
||||
if (req.headers.get("Authorization") === "Bearer findkey") {
|
||||
return createJSONResponse([
|
||||
{
|
||||
key: "foo",
|
||||
|
||||
@@ -14,7 +14,7 @@ This module adds a JetBrains Gateway Button to open any workspace with a single
|
||||
```tf
|
||||
module "jetbrains_gateway" {
|
||||
source = "registry.coder.com/modules/jetbrains-gateway/coder"
|
||||
version = "1.0.13"
|
||||
version = "1.0.23"
|
||||
agent_id = coder_agent.example.id
|
||||
agent_name = "example"
|
||||
folder = "/home/coder/example"
|
||||
@@ -32,7 +32,7 @@ module "jetbrains_gateway" {
|
||||
```tf
|
||||
module "jetbrains_gateway" {
|
||||
source = "registry.coder.com/modules/jetbrains-gateway/coder"
|
||||
version = "1.0.13"
|
||||
version = "1.0.23"
|
||||
agent_id = coder_agent.example.id
|
||||
agent_name = "example"
|
||||
folder = "/home/coder/example"
|
||||
@@ -46,7 +46,7 @@ module "jetbrains_gateway" {
|
||||
```tf
|
||||
module "jetbrains_gateway" {
|
||||
source = "registry.coder.com/modules/jetbrains-gateway/coder"
|
||||
version = "1.0.13"
|
||||
version = "1.0.23"
|
||||
agent_id = coder_agent.example.id
|
||||
agent_name = "example"
|
||||
folder = "/home/coder/example"
|
||||
@@ -61,7 +61,7 @@ module "jetbrains_gateway" {
|
||||
```tf
|
||||
module "jetbrains_gateway" {
|
||||
source = "registry.coder.com/modules/jetbrains-gateway/coder"
|
||||
version = "1.0.13"
|
||||
version = "1.0.23"
|
||||
agent_id = coder_agent.example.id
|
||||
agent_name = "example"
|
||||
folder = "/home/coder/example"
|
||||
@@ -72,6 +72,24 @@ module "jetbrains_gateway" {
|
||||
}
|
||||
```
|
||||
|
||||
### Custom base link
|
||||
|
||||
Due to the highest priority of the `ide_download_link` parameter in the `(jetbrains-gateway://...` within IDEA, the pre-configured download address will be overridden when using [IDEA's offline mode](https://www.jetbrains.com/help/idea/fully-offline-mode.html). Therefore, it is necessary to configure the `download_base_link` parameter for the `jetbrains_gateway` module to change the value of `ide_download_link`.
|
||||
|
||||
```tf
|
||||
module "jetbrains_gateway" {
|
||||
source = "registry.coder.com/modules/jetbrains-gateway/coder"
|
||||
version = "1.0.23"
|
||||
agent_id = coder_agent.example.id
|
||||
agent_name = "example"
|
||||
folder = "/home/coder/example"
|
||||
jetbrains_ides = ["GO", "WS"]
|
||||
releases_base_link = "https://releases.internal.site/"
|
||||
download_base_link = "https://download.internal.site/"
|
||||
default = "GO"
|
||||
}
|
||||
```
|
||||
|
||||
## Supported IDEs
|
||||
|
||||
This module and JetBrains Gateway support the following JetBrains IDEs:
|
||||
|
||||
@@ -14,6 +14,26 @@ describe("jetbrains-gateway", async () => {
|
||||
folder: "/home/foo",
|
||||
});
|
||||
|
||||
it("should create a link with the default values", async () => {
|
||||
const state = await runTerraformApply(import.meta.dir, {
|
||||
// These are all required.
|
||||
agent_id: "foo",
|
||||
agent_name: "foo",
|
||||
folder: "/home/coder",
|
||||
});
|
||||
expect(state.outputs.url.value).toBe(
|
||||
"jetbrains-gateway://connect#type=coder&workspace=default&owner=default&agent=foo&folder=/home/coder&url=https://mydeployment.coder.com&token=$SESSION_TOKEN&ide_product_code=IU&ide_build_number=241.14494.240&ide_download_link=https://download.jetbrains.com/idea/ideaIU-2024.1.tar.gz",
|
||||
);
|
||||
|
||||
const coder_app = state.resources.find(
|
||||
(res) => res.type === "coder_app" && res.name === "gateway",
|
||||
);
|
||||
|
||||
expect(coder_app).not.toBeNull();
|
||||
expect(coder_app?.instances.length).toBe(1);
|
||||
expect(coder_app?.instances[0].attributes.order).toBeNull();
|
||||
});
|
||||
|
||||
it("default to first ide", async () => {
|
||||
const state = await runTerraformApply(import.meta.dir, {
|
||||
agent_id: "foo",
|
||||
|
||||
@@ -18,6 +18,12 @@ variable "agent_id" {
|
||||
description = "The ID of a Coder agent."
|
||||
}
|
||||
|
||||
variable "slug" {
|
||||
type = string
|
||||
description = "The slug for the coder_app. Allows resuing the module with the same template."
|
||||
default = "gateway"
|
||||
}
|
||||
|
||||
variable "agent_name" {
|
||||
type = string
|
||||
description = "Agent name."
|
||||
@@ -140,9 +146,29 @@ variable "jetbrains_ides" {
|
||||
}
|
||||
}
|
||||
|
||||
variable "releases_base_link" {
|
||||
type = string
|
||||
description = ""
|
||||
default = "https://data.services.jetbrains.com"
|
||||
validation {
|
||||
condition = can(regex("^https?://.+$", var.releases_base_link))
|
||||
error_message = "The releases_base_link must be a valid HTTP/S address."
|
||||
}
|
||||
}
|
||||
|
||||
variable "download_base_link" {
|
||||
type = string
|
||||
description = ""
|
||||
default = "https://download.jetbrains.com"
|
||||
validation {
|
||||
condition = can(regex("^https?://.+$", var.download_base_link))
|
||||
error_message = "The download_base_link must be a valid HTTP/S address."
|
||||
}
|
||||
}
|
||||
|
||||
data "http" "jetbrains_ide_versions" {
|
||||
for_each = var.latest ? toset(var.jetbrains_ides) : toset([])
|
||||
url = "https://data.services.jetbrains.com/products/releases?code=${each.key}&latest=true&type=${var.channel}"
|
||||
url = "${var.releases_base_link}/products/releases?code=${each.key}&latest=true&type=${var.channel}"
|
||||
}
|
||||
|
||||
locals {
|
||||
@@ -152,7 +178,7 @@ locals {
|
||||
name = "GoLand",
|
||||
identifier = "GO",
|
||||
build_number = var.jetbrains_ide_versions["GO"].build_number,
|
||||
download_link = "https://download.jetbrains.com/go/goland-${var.jetbrains_ide_versions["GO"].version}.tar.gz"
|
||||
download_link = "${var.download_base_link}/go/goland-${var.jetbrains_ide_versions["GO"].version}.tar.gz"
|
||||
version = var.jetbrains_ide_versions["GO"].version
|
||||
},
|
||||
"WS" = {
|
||||
@@ -160,7 +186,7 @@ locals {
|
||||
name = "WebStorm",
|
||||
identifier = "WS",
|
||||
build_number = var.jetbrains_ide_versions["WS"].build_number,
|
||||
download_link = "https://download.jetbrains.com/webstorm/WebStorm-${var.jetbrains_ide_versions["WS"].version}.tar.gz"
|
||||
download_link = "${var.download_base_link}/webstorm/WebStorm-${var.jetbrains_ide_versions["WS"].version}.tar.gz"
|
||||
version = var.jetbrains_ide_versions["WS"].version
|
||||
},
|
||||
"IU" = {
|
||||
@@ -168,7 +194,7 @@ locals {
|
||||
name = "IntelliJ IDEA Ultimate",
|
||||
identifier = "IU",
|
||||
build_number = var.jetbrains_ide_versions["IU"].build_number,
|
||||
download_link = "https://download.jetbrains.com/idea/ideaIU-${var.jetbrains_ide_versions["IU"].version}.tar.gz"
|
||||
download_link = "${var.download_base_link}/idea/ideaIU-${var.jetbrains_ide_versions["IU"].version}.tar.gz"
|
||||
version = var.jetbrains_ide_versions["IU"].version
|
||||
},
|
||||
"PY" = {
|
||||
@@ -176,7 +202,7 @@ locals {
|
||||
name = "PyCharm Professional",
|
||||
identifier = "PY",
|
||||
build_number = var.jetbrains_ide_versions["PY"].build_number,
|
||||
download_link = "https://download.jetbrains.com/python/pycharm-professional-${var.jetbrains_ide_versions["PY"].version}.tar.gz"
|
||||
download_link = "${var.download_base_link}/python/pycharm-professional-${var.jetbrains_ide_versions["PY"].version}.tar.gz"
|
||||
version = var.jetbrains_ide_versions["PY"].version
|
||||
},
|
||||
"CL" = {
|
||||
@@ -184,7 +210,7 @@ locals {
|
||||
name = "CLion",
|
||||
identifier = "CL",
|
||||
build_number = var.jetbrains_ide_versions["CL"].build_number,
|
||||
download_link = "https://download.jetbrains.com/cpp/CLion-${var.jetbrains_ide_versions["CL"].version}.tar.gz"
|
||||
download_link = "${var.download_base_link}/cpp/CLion-${var.jetbrains_ide_versions["CL"].version}.tar.gz"
|
||||
version = var.jetbrains_ide_versions["CL"].version
|
||||
},
|
||||
"PS" = {
|
||||
@@ -192,7 +218,7 @@ locals {
|
||||
name = "PhpStorm",
|
||||
identifier = "PS",
|
||||
build_number = var.jetbrains_ide_versions["PS"].build_number,
|
||||
download_link = "https://download.jetbrains.com/webide/PhpStorm-${var.jetbrains_ide_versions["PS"].version}.tar.gz"
|
||||
download_link = "${var.download_base_link}/webide/PhpStorm-${var.jetbrains_ide_versions["PS"].version}.tar.gz"
|
||||
version = var.jetbrains_ide_versions["PS"].version
|
||||
},
|
||||
"RM" = {
|
||||
@@ -200,7 +226,7 @@ locals {
|
||||
name = "RubyMine",
|
||||
identifier = "RM",
|
||||
build_number = var.jetbrains_ide_versions["RM"].build_number,
|
||||
download_link = "https://download.jetbrains.com/ruby/RubyMine-${var.jetbrains_ide_versions["RM"].version}.tar.gz"
|
||||
download_link = "${var.download_base_link}/ruby/RubyMine-${var.jetbrains_ide_versions["RM"].version}.tar.gz"
|
||||
version = var.jetbrains_ide_versions["RM"].version
|
||||
}
|
||||
"RD" = {
|
||||
@@ -208,7 +234,7 @@ locals {
|
||||
name = "Rider",
|
||||
identifier = "RD",
|
||||
build_number = var.jetbrains_ide_versions["RD"].build_number,
|
||||
download_link = "https://download.jetbrains.com/rider/JetBrains.Rider-${var.jetbrains_ide_versions["RD"].version}.tar.gz"
|
||||
download_link = "${var.download_base_link}/rider/JetBrains.Rider-${var.jetbrains_ide_versions["RD"].version}.tar.gz"
|
||||
version = var.jetbrains_ide_versions["RD"].version
|
||||
}
|
||||
}
|
||||
@@ -243,10 +269,11 @@ data "coder_parameter" "jetbrains_ide" {
|
||||
}
|
||||
|
||||
data "coder_workspace" "me" {}
|
||||
data "coder_workspace_owner" "me" {}
|
||||
|
||||
resource "coder_app" "gateway" {
|
||||
agent_id = var.agent_id
|
||||
slug = "gateway"
|
||||
slug = var.slug
|
||||
display_name = local.display_name
|
||||
icon = local.icon
|
||||
external = true
|
||||
@@ -254,6 +281,8 @@ resource "coder_app" "gateway" {
|
||||
url = join("", [
|
||||
"jetbrains-gateway://connect#type=coder&workspace=",
|
||||
data.coder_workspace.me.name,
|
||||
"&owner=",
|
||||
data.coder_workspace_owner.me.name,
|
||||
"&agent=",
|
||||
var.agent_name,
|
||||
"&folder=",
|
||||
|
||||
@@ -116,7 +116,7 @@ EOF`;
|
||||
const proxies = ["foo", "bar", "baz"]
|
||||
.map((r) => `https://${user}:@${fakeFrogApi}/go/${r}`)
|
||||
.join(",");
|
||||
expect(proxyEnv["value"]).toEqual(proxies);
|
||||
expect(proxyEnv.value).toEqual(proxies);
|
||||
|
||||
const coderScript = findResourceInstance(state, "coder_script");
|
||||
expect(coderScript.script).toContain(
|
||||
|
||||
@@ -151,7 +151,7 @@ EOF`;
|
||||
const proxies = ["foo", "bar", "baz"]
|
||||
.map((r) => `https://${user}:${token}@${fakeFrogApi}/go/${r}`)
|
||||
.join(",");
|
||||
expect(proxyEnv["value"]).toEqual(proxies);
|
||||
expect(proxyEnv.value).toEqual(proxies);
|
||||
|
||||
const coderScript = findResourceInstance(state, "coder_script");
|
||||
expect(coderScript.script).toContain(
|
||||
|
||||
@@ -16,7 +16,7 @@ A module that adds JupyterLab in your Coder template.
|
||||
```tf
|
||||
module "jupyterlab" {
|
||||
source = "registry.coder.com/modules/jupyterlab/coder"
|
||||
version = "1.0.19"
|
||||
version = "1.0.23"
|
||||
agent_id = coder_agent.example.id
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import {
|
||||
execContainer,
|
||||
executeScriptInContainer,
|
||||
findResourceInstance,
|
||||
runContainer,
|
||||
runTerraformApply,
|
||||
runTerraformInit,
|
||||
testRequiredVariables,
|
||||
findResourceInstance,
|
||||
runContainer,
|
||||
TerraformState,
|
||||
execContainer,
|
||||
type TerraformState,
|
||||
} from "../test";
|
||||
|
||||
// executes the coder script after installing pip
|
||||
const executeScriptInContainerWithPip = async (
|
||||
state: TerraformState,
|
||||
image: string,
|
||||
shell: string = "sh",
|
||||
shell = "sh",
|
||||
): Promise<{
|
||||
exitCode: number;
|
||||
stdout: string[];
|
||||
|
||||
@@ -9,6 +9,9 @@ terraform {
|
||||
}
|
||||
}
|
||||
|
||||
data "coder_workspace" "me" {}
|
||||
data "coder_workspace_owner" "me" {}
|
||||
|
||||
# Add required variables for your modules and remove any unneeded variables
|
||||
variable "agent_id" {
|
||||
type = string
|
||||
@@ -36,6 +39,12 @@ variable "share" {
|
||||
}
|
||||
}
|
||||
|
||||
variable "subdomain" {
|
||||
type = bool
|
||||
description = "Determines whether JupyterLab will be accessed via its own subdomain or whether it will be accessed via a path on Coder."
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "order" {
|
||||
type = number
|
||||
description = "The order determines the position of app in the UI presentation. The lowest order is shown first and apps with equal order are sorted by name (ascending order)."
|
||||
@@ -49,17 +58,18 @@ resource "coder_script" "jupyterlab" {
|
||||
script = templatefile("${path.module}/run.sh", {
|
||||
LOG_PATH : var.log_path,
|
||||
PORT : var.port
|
||||
BASE_URL : var.subdomain ? "" : "/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}/apps/jupyterlab"
|
||||
})
|
||||
run_on_start = true
|
||||
}
|
||||
|
||||
resource "coder_app" "jupyterlab" {
|
||||
agent_id = var.agent_id
|
||||
slug = "jupyterlab"
|
||||
slug = "jupyterlab" # sync with the usage in URL
|
||||
display_name = "JupyterLab"
|
||||
url = "http://localhost:${var.port}"
|
||||
url = var.subdomain ? "http://localhost:${var.port}" : "http://localhost:${var.port}/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}/apps/jupyterlab"
|
||||
icon = "/icon/jupyter.svg"
|
||||
subdomain = true
|
||||
subdomain = var.subdomain
|
||||
share = var.share
|
||||
order = var.order
|
||||
}
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
if [ -n "${BASE_URL}" ]; then
|
||||
BASE_URL_FLAG="--ServerApp.base_url=${BASE_URL}"
|
||||
fi
|
||||
|
||||
BOLD='\033[0;1m'
|
||||
|
||||
printf "$${BOLD}Installing jupyterlab!\n"
|
||||
|
||||
# check if jupyterlab is installed
|
||||
if ! command -v jupyterlab > /dev/null 2>&1; then
|
||||
if ! command -v jupyter-lab > /dev/null 2>&1; then
|
||||
# install jupyterlab
|
||||
# check if pipx is installed
|
||||
if ! command -v pipx > /dev/null 2>&1; then
|
||||
@@ -15,11 +19,17 @@ if ! command -v jupyterlab > /dev/null 2>&1; then
|
||||
fi
|
||||
# install jupyterlab
|
||||
pipx install -q jupyterlab
|
||||
echo "🥳 jupyterlab has been installed\n\n"
|
||||
printf "%s\n\n" "🥳 jupyterlab has been installed"
|
||||
else
|
||||
echo "🥳 jupyterlab is already installed\n\n"
|
||||
printf "%s\n\n" "🥳 jupyterlab is already installed"
|
||||
fi
|
||||
|
||||
echo "👷 Starting jupyterlab in background..."
|
||||
echo "check logs at ${LOG_PATH}"
|
||||
$HOME/.local/bin/jupyter-lab --ServerApp.ip='0.0.0.0' --ServerApp.port=${PORT} --no-browser --ServerApp.token='' --ServerApp.password='' > ${LOG_PATH} 2>&1 &
|
||||
printf "👷 Starting jupyterlab in background..."
|
||||
printf "check logs at ${LOG_PATH}"
|
||||
$HOME/.local/bin/jupyter-lab --no-browser \
|
||||
"$BASE_URL_FLAG" \
|
||||
--ServerApp.ip='*' \
|
||||
--ServerApp.port="${PORT}" \
|
||||
--ServerApp.token='' \
|
||||
--ServerApp.password='' \
|
||||
> "${LOG_PATH}" 2>&1 &
|
||||
|
||||
23
kasmvnc/README.md
Normal file
23
kasmvnc/README.md
Normal file
@@ -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.23"
|
||||
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.
|
||||
37
kasmvnc/main.test.ts
Normal file
37
kasmvnc/main.test.ts
Normal file
@@ -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();
|
||||
}
|
||||
});
|
||||
});
|
||||
63
kasmvnc/main.tf
Normal file
63
kasmvnc/main.tf
Normal file
@@ -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,
|
||||
KASM_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
|
||||
}
|
||||
}
|
||||
235
kasmvnc/run.sh
Normal file
235
kasmvnc/run.sh
Normal file
@@ -0,0 +1,235 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Exit on error, undefined variables, and pipe failures
|
||||
set -euo pipefail
|
||||
|
||||
# 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 download a file using wget, curl, or busybox as a fallback
|
||||
download_file() {
|
||||
local url="$1"
|
||||
local output="$2"
|
||||
local download_tool
|
||||
|
||||
if command -v curl &> /dev/null; then
|
||||
# shellcheck disable=SC2034
|
||||
download_tool=(curl -fsSL)
|
||||
elif command -v wget &> /dev/null; then
|
||||
# shellcheck disable=SC2034
|
||||
download_tool=(wget -q -O-)
|
||||
elif command -v busybox &> /dev/null; then
|
||||
# shellcheck disable=SC2034
|
||||
download_tool=(busybox wget -O-)
|
||||
else
|
||||
echo "ERROR: No download tool available (curl, wget, or busybox required)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2288
|
||||
"$${download_tool[@]}" "$url" > "$output" || {
|
||||
echo "ERROR: Failed to download $url"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
# Function to install kasmvncserver for debian-based distros
|
||||
install_deb() {
|
||||
local url=$1
|
||||
local kasmdeb="/tmp/kasmvncserver.deb"
|
||||
|
||||
download_file "$url" "$kasmdeb"
|
||||
|
||||
CACHE_DIR="/var/lib/apt/lists/partial"
|
||||
# Check if the directory exists and was modified in the last 60 minutes
|
||||
if [[ ! -d "$CACHE_DIR" ]] || ! find "$CACHE_DIR" -mmin -60 -print -quit &> /dev/null; then
|
||||
echo "Stale package cache, updating..."
|
||||
# Update package cache with a 300-second timeout for dpkg lock
|
||||
sudo apt-get -o DPkg::Lock::Timeout=300 -qq update
|
||||
fi
|
||||
|
||||
DEBIAN_FRONTEND=noninteractive sudo apt-get -o DPkg::Lock::Timeout=300 install --yes -qq --no-install-recommends --no-install-suggests "$kasmdeb"
|
||||
rm "$kasmdeb"
|
||||
}
|
||||
|
||||
# Function to install kasmvncserver for rpm-based distros
|
||||
install_rpm() {
|
||||
local url=$1
|
||||
local kasmrpm="/tmp/kasmvncserver.rpm"
|
||||
local package_manager
|
||||
|
||||
if command -v dnf &> /dev/null; then
|
||||
# shellcheck disable=SC2034
|
||||
package_manager=(dnf localinstall -y)
|
||||
elif command -v zypper &> /dev/null; then
|
||||
# shellcheck disable=SC2034
|
||||
package_manager=(zypper install -y)
|
||||
elif command -v yum &> /dev/null; then
|
||||
# shellcheck disable=SC2034
|
||||
package_manager=(yum localinstall -y)
|
||||
elif command -v rpm &> /dev/null; then
|
||||
# Do we need to manually handle missing dependencies?
|
||||
# shellcheck disable=SC2034
|
||||
package_manager=(rpm -i)
|
||||
else
|
||||
echo "ERROR: No supported package manager available (dnf, zypper, yum, or rpm required)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
download_file "$url" "$kasmrpm"
|
||||
|
||||
# shellcheck disable=SC2288
|
||||
sudo "$${package_manager[@]}" "$kasmrpm" || {
|
||||
echo "ERROR: Failed to install $kasmrpm"
|
||||
exit 1
|
||||
}
|
||||
|
||||
rm "$kasmrpm"
|
||||
}
|
||||
|
||||
# Function to install kasmvncserver for Alpine Linux
|
||||
install_alpine() {
|
||||
local url=$1
|
||||
local kasmtgz="/tmp/kasmvncserver.tgz"
|
||||
|
||||
download_file "$url" "$kasmtgz"
|
||||
|
||||
tar -xzf "$kasmtgz" -C /usr/local/bin/
|
||||
rm "$kasmtgz"
|
||||
}
|
||||
|
||||
# Detect system information
|
||||
if [[ ! -f /etc/os-release ]]; then
|
||||
echo "ERROR: Cannot detect OS: /etc/os-release not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
source /etc/os-release
|
||||
distro="$ID"
|
||||
distro_version="$VERSION_ID"
|
||||
codename="$VERSION_CODENAME"
|
||||
arch="$(uname -m)"
|
||||
if [[ "$ID" == "ol" ]]; then
|
||||
distro="oracle"
|
||||
distro_version="$${distro_version%%.*}"
|
||||
elif [[ "$ID" == "fedora" ]]; then
|
||||
distro_version="$(grep -oP '\(\K[\w ]+' /etc/fedora-release | tr '[:upper:]' '[:lower:]' | tr -d ' ')"
|
||||
fi
|
||||
|
||||
echo "Detected Distribution: $distro"
|
||||
echo "Detected Version: $distro_version"
|
||||
echo "Detected Codename: $codename"
|
||||
echo "Detected Architecture: $arch"
|
||||
|
||||
# Map arch to package arch
|
||||
case "$arch" in
|
||||
x86_64)
|
||||
if [[ "$distro" =~ ^(ubuntu|debian|kali)$ ]]; then
|
||||
arch="amd64"
|
||||
fi
|
||||
;;
|
||||
aarch64)
|
||||
if [[ "$distro" =~ ^(ubuntu|debian|kali)$ ]]; then
|
||||
arch="arm64"
|
||||
fi
|
||||
;;
|
||||
arm64)
|
||||
: # This is effectively a noop
|
||||
;;
|
||||
*)
|
||||
echo "ERROR: Unsupported architecture: $arch"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Check if vncserver is installed, and install if not
|
||||
if ! check_installed; then
|
||||
# Check for NOPASSWD sudo (required)
|
||||
if ! command -v sudo &> /dev/null || ! sudo -n true 2> /dev/null; then
|
||||
echo "ERROR: sudo NOPASSWD access required!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
base_url="https://github.com/kasmtech/KasmVNC/releases/download/v${KASM_VERSION}"
|
||||
|
||||
echo "Installing KASM version: ${KASM_VERSION}"
|
||||
case $distro in
|
||||
ubuntu | debian | kali)
|
||||
bin_name="kasmvncserver_$${codename}_${KASM_VERSION}_$${arch}.deb"
|
||||
install_deb "$base_url/$bin_name"
|
||||
;;
|
||||
oracle | fedora | opensuse)
|
||||
bin_name="kasmvncserver_$${distro}_$${distro_version}_${KASM_VERSION}_$${arch}.rpm"
|
||||
install_rpm "$base_url/$bin_name"
|
||||
;;
|
||||
alpine)
|
||||
bin_name="kasmvnc.alpine_$${distro_version//./}_$${arch}.tgz"
|
||||
install_alpine "$base_url/$bin_name"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported distribution: $distro"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
else
|
||||
echo "vncserver already installed. Skipping installation."
|
||||
fi
|
||||
|
||||
if command -v sudo &> /dev/null && sudo -n true 2> /dev/null; then
|
||||
kasm_config_file="/etc/kasmvnc/kasmvnc.yaml"
|
||||
SUDO=sudo
|
||||
else
|
||||
kasm_config_file="$HOME/.vnc/kasmvnc.yaml"
|
||||
SUDO=
|
||||
|
||||
echo "WARNING: Sudo access not available, using user config dir!"
|
||||
|
||||
if [[ -f "$kasm_config_file" ]]; then
|
||||
echo "WARNING: Custom user KasmVNC config exists, not overwriting!"
|
||||
echo "WARNING: Ensure that you manually configure the appropriate settings."
|
||||
kasm_config_file="/dev/stderr"
|
||||
else
|
||||
echo "WARNING: This may prevent custom user KasmVNC settings from applying!"
|
||||
mkdir -p "$HOME/.vnc"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Writing KasmVNC config to $kasm_config_file"
|
||||
$SUDO tee "$kasm_config_file" > /dev/null << EOF
|
||||
network:
|
||||
protocol: http
|
||||
websocket_port: ${PORT}
|
||||
ssl:
|
||||
require_ssl: false
|
||||
pem_certificate:
|
||||
pem_key:
|
||||
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"
|
||||
vncserver -select-de "${DESKTOP_ENVIRONMENT}" -disableBasicAuth > /tmp/kasmvncserver.log 2>&1 &
|
||||
pid=$!
|
||||
|
||||
# Wait for server to start
|
||||
sleep 5
|
||||
grep -v '^[[:space:]]*$' /tmp/kasmvncserver.log | tail -n 10
|
||||
if ps -p $pid | grep -q "^$pid"; then
|
||||
echo "ERROR: Failed to start KasmVNC server. Check full logs at /tmp/kasmvncserver.log"
|
||||
exit 1
|
||||
fi
|
||||
printf "🚀 KasmVNC server started successfully!\n"
|
||||
@@ -1,4 +1,4 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { describe } from "bun:test";
|
||||
import { runTerraformInit, testRequiredVariables } from "../test";
|
||||
|
||||
describe("nodejs", async () => {
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
import { readableStreamToText, spawn } from "bun";
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import {
|
||||
executeScriptInContainer,
|
||||
runTerraformApply,
|
||||
runTerraformInit,
|
||||
testRequiredVariables,
|
||||
runContainer,
|
||||
execContainer,
|
||||
findResourceInstance,
|
||||
} from "../test";
|
||||
|
||||
describe("personalize", async () => {
|
||||
|
||||
@@ -72,7 +72,7 @@ executed`,
|
||||
it("formats execution with milliseconds", async () => {
|
||||
await assertSlackMessage({
|
||||
command: "echo test",
|
||||
format: `$COMMAND took $DURATION`,
|
||||
format: "$COMMAND took $DURATION",
|
||||
durationMS: 150,
|
||||
output: "echo test took 150ms",
|
||||
});
|
||||
@@ -81,7 +81,7 @@ executed`,
|
||||
it("formats execution with seconds", async () => {
|
||||
await assertSlackMessage({
|
||||
command: "echo test",
|
||||
format: `$COMMAND took $DURATION`,
|
||||
format: "$COMMAND took $DURATION",
|
||||
durationMS: 15000,
|
||||
output: "echo test took 15.0s",
|
||||
});
|
||||
@@ -90,7 +90,7 @@ executed`,
|
||||
it("formats execution with minutes", async () => {
|
||||
await assertSlackMessage({
|
||||
command: "echo test",
|
||||
format: `$COMMAND took $DURATION`,
|
||||
format: "$COMMAND took $DURATION",
|
||||
durationMS: 120000,
|
||||
output: "echo test took 2m 0.0s",
|
||||
});
|
||||
@@ -99,7 +99,7 @@ executed`,
|
||||
it("formats execution with hours", async () => {
|
||||
await assertSlackMessage({
|
||||
command: "echo test",
|
||||
format: `$COMMAND took $DURATION`,
|
||||
format: "$COMMAND took $DURATION",
|
||||
durationMS: 60000 * 60,
|
||||
output: "echo test took 1hr 0m 0.0s",
|
||||
});
|
||||
|
||||
30
test.ts
30
test.ts
@@ -1,6 +1,6 @@
|
||||
import { readableStreamToText, spawn } from "bun";
|
||||
import { afterEach, expect, it } from "bun:test";
|
||||
import { readFile, unlink } from "fs/promises";
|
||||
import { expect, it } from "bun:test";
|
||||
import { readFile, unlink } from "node:fs/promises";
|
||||
|
||||
export const runContainer = async (
|
||||
image: string,
|
||||
@@ -21,7 +21,8 @@ export const runContainer = async (
|
||||
"-c",
|
||||
init,
|
||||
]);
|
||||
let containerID = await readableStreamToText(proc.stdout);
|
||||
|
||||
const containerID = await readableStreamToText(proc.stdout);
|
||||
const exitCode = await proc.exited;
|
||||
if (exitCode !== 0) {
|
||||
throw new Error(containerID);
|
||||
@@ -36,7 +37,7 @@ export const runContainer = async (
|
||||
export const executeScriptInContainer = async (
|
||||
state: TerraformState,
|
||||
image: string,
|
||||
shell: string = "sh",
|
||||
shell = "sh",
|
||||
): Promise<{
|
||||
exitCode: number;
|
||||
stdout: string[];
|
||||
@@ -116,6 +117,9 @@ export interface CoderScriptAttributes {
|
||||
url: string;
|
||||
}
|
||||
|
||||
export type ResourceInstance<T extends string = string> =
|
||||
T extends "coder_script" ? CoderScriptAttributes : Record<string, string>;
|
||||
|
||||
/**
|
||||
* finds the first instance of the given resource type in the given state. If
|
||||
* name is specified, it will only find the instance with the given name.
|
||||
@@ -124,10 +128,7 @@ export const findResourceInstance = <T extends string>(
|
||||
state: TerraformState,
|
||||
type: T,
|
||||
name?: string,
|
||||
// if type is "coder_script" return CoderScriptAttributes
|
||||
): T extends "coder_script"
|
||||
? CoderScriptAttributes
|
||||
: Record<string, string> => {
|
||||
): ResourceInstance<T> => {
|
||||
const resource = state.resources.find(
|
||||
(resource) =>
|
||||
resource.type === type && (name ? resource.name === name : true),
|
||||
@@ -140,7 +141,8 @@ export const findResourceInstance = <T extends string>(
|
||||
`Resource ${type} has ${resource.instances.length} instances`,
|
||||
);
|
||||
}
|
||||
return resource.instances[0].attributes as any;
|
||||
|
||||
return resource.instances[0].attributes as ResourceInstance<T>;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -157,15 +159,15 @@ export const testRequiredVariables = <TVars extends TerraformVariables>(
|
||||
});
|
||||
|
||||
const varNames = Object.keys(vars);
|
||||
varNames.forEach((varName) => {
|
||||
for (const varName of varNames) {
|
||||
// Ensures that every variable provided is required!
|
||||
it("missing variable " + varName, async () => {
|
||||
it(`missing variable: ${varName}`, async () => {
|
||||
const localVars: TerraformVariables = {};
|
||||
varNames.forEach((otherVarName) => {
|
||||
for (const otherVarName of varNames) {
|
||||
if (otherVarName !== varName) {
|
||||
localVars[otherVarName] = vars[otherVarName];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
await runTerraformApply(dir, localVars);
|
||||
@@ -181,7 +183,7 @@ export const testRequiredVariables = <TVars extends TerraformVariables>(
|
||||
}
|
||||
throw new Error(`${varName} is not a required variable!`);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"module": "nodenext",
|
||||
// If we were just compiling for the tests, we could safely target ESNext at
|
||||
// all times, but just because we've been starting to add more runtime logic
|
||||
// files to some of the modules, erring on the side of caution by having a
|
||||
// older compilation target
|
||||
"target": "ES6",
|
||||
"module": "ESNext",
|
||||
"strict": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"moduleResolution": "nodenext",
|
||||
"moduleResolution": "node",
|
||||
"types": ["bun-types"]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ This module lets you authenticate with [Hashicorp Vault](https://www.vaultprojec
|
||||
```tf
|
||||
module "vault" {
|
||||
source = "registry.coder.com/modules/vault-jwt/coder"
|
||||
version = "1.0.19"
|
||||
version = "1.0.20"
|
||||
agent_id = coder_agent.example.id
|
||||
vault_addr = "https://vault.example.com"
|
||||
vault_jwt_role = "coder" # The Vault role to use for authentication
|
||||
@@ -41,7 +41,7 @@ curl -H "X-Vault-Token: ${VAULT_TOKEN}" -X GET "${VAULT_ADDR}/v1/coder/secrets/d
|
||||
```tf
|
||||
module "vault" {
|
||||
source = "registry.coder.com/modules/vault-jwt/coder"
|
||||
version = "1.0.19"
|
||||
version = "1.0.20"
|
||||
agent_id = coder_agent.example.id
|
||||
vault_addr = "https://vault.example.com"
|
||||
vault_jwt_auth_path = "oidc"
|
||||
@@ -56,7 +56,7 @@ data "coder_workspace_owner" "me" {}
|
||||
|
||||
module "vault" {
|
||||
source = "registry.coder.com/modules/vault-jwt/coder"
|
||||
version = "1.0.19"
|
||||
version = "1.0.20"
|
||||
agent_id = coder_agent.example.id
|
||||
vault_addr = "https://vault.example.com"
|
||||
vault_jwt_role = data.coder_workspace_owner.me.groups[0]
|
||||
@@ -68,7 +68,7 @@ module "vault" {
|
||||
```tf
|
||||
module "vault" {
|
||||
source = "registry.coder.com/modules/vault-jwt/coder"
|
||||
version = "1.0.19"
|
||||
version = "1.0.20"
|
||||
agent_id = coder_agent.example.id
|
||||
vault_addr = "https://vault.example.com"
|
||||
vault_jwt_role = "coder" # The Vault role to use for authentication
|
||||
|
||||
@@ -51,7 +51,7 @@ install() {
|
||||
printf "Failed to determine the latest Vault version.\n"
|
||||
return 1
|
||||
fi
|
||||
VAULT_CLI_VERSION=$${VAULT_CLI_VERSION}
|
||||
VAULT_CLI_VERSION=$${LATEST_VERSION}
|
||||
fi
|
||||
|
||||
# Check if the vault CLI is installed and has the correct version
|
||||
|
||||
@@ -22,7 +22,7 @@ describe("vscode-desktop", async () => {
|
||||
);
|
||||
|
||||
const coder_app = state.resources.find(
|
||||
(res) => res.type == "coder_app" && res.name == "vscode",
|
||||
(res) => res.type === "coder_app" && res.name === "vscode",
|
||||
);
|
||||
|
||||
expect(coder_app).not.toBeNull();
|
||||
@@ -79,7 +79,7 @@ describe("vscode-desktop", async () => {
|
||||
});
|
||||
|
||||
const coder_app = state.resources.find(
|
||||
(res) => res.type == "coder_app" && res.name == "vscode",
|
||||
(res) => res.type === "coder_app" && res.name === "vscode",
|
||||
);
|
||||
|
||||
expect(coder_app).not.toBeNull();
|
||||
|
||||
@@ -14,7 +14,7 @@ Automatically install [Visual Studio Code Server](https://code.visualstudio.com/
|
||||
```tf
|
||||
module "vscode-web" {
|
||||
source = "registry.coder.com/modules/vscode-web/coder"
|
||||
version = "1.0.14"
|
||||
version = "1.0.22"
|
||||
agent_id = coder_agent.example.id
|
||||
accept_license = true
|
||||
}
|
||||
@@ -29,7 +29,7 @@ module "vscode-web" {
|
||||
```tf
|
||||
module "vscode-web" {
|
||||
source = "registry.coder.com/modules/vscode-web/coder"
|
||||
version = "1.0.14"
|
||||
version = "1.0.22"
|
||||
agent_id = coder_agent.example.id
|
||||
install_prefix = "/home/coder/.vscode-web"
|
||||
folder = "/home/coder"
|
||||
@@ -42,7 +42,7 @@ module "vscode-web" {
|
||||
```tf
|
||||
module "vscode-web" {
|
||||
source = "registry.coder.com/modules/vscode-web/coder"
|
||||
version = "1.0.14"
|
||||
version = "1.0.22"
|
||||
agent_id = coder_agent.example.id
|
||||
extensions = ["github.copilot", "ms-python.python", "ms-toolsai.jupyter"]
|
||||
accept_license = true
|
||||
@@ -56,7 +56,7 @@ Configure VS Code's [settings.json](https://code.visualstudio.com/docs/getstarte
|
||||
```tf
|
||||
module "vscode-web" {
|
||||
source = "registry.coder.com/modules/vscode-web/coder"
|
||||
version = "1.0.14"
|
||||
version = "1.0.22"
|
||||
agent_id = coder_agent.example.id
|
||||
extensions = ["dracula-theme.theme-dracula"]
|
||||
settings = {
|
||||
|
||||
@@ -121,6 +121,18 @@ variable "auto_install_extensions" {
|
||||
default = false
|
||||
}
|
||||
|
||||
variable "subdomain" {
|
||||
type = bool
|
||||
description = <<-EOT
|
||||
Determines whether the app will be accessed via it's own subdomain or whether it will be accessed via a path on Coder.
|
||||
If wildcards have not been setup by the administrator then apps with "subdomain" set to true will not be accessible.
|
||||
EOT
|
||||
default = true
|
||||
}
|
||||
|
||||
data "coder_workspace_owner" "me" {}
|
||||
data "coder_workspace" "me" {}
|
||||
|
||||
resource "coder_script" "vscode-web" {
|
||||
agent_id = var.agent_id
|
||||
display_name = "VS Code Web"
|
||||
@@ -138,6 +150,7 @@ resource "coder_script" "vscode-web" {
|
||||
EXTENSIONS_DIR : var.extensions_dir,
|
||||
FOLDER : var.folder,
|
||||
AUTO_INSTALL_EXTENSIONS : var.auto_install_extensions,
|
||||
SERVER_BASE_PATH : local.server_base_path,
|
||||
})
|
||||
run_on_start = true
|
||||
|
||||
@@ -158,15 +171,21 @@ resource "coder_app" "vscode-web" {
|
||||
agent_id = var.agent_id
|
||||
slug = var.slug
|
||||
display_name = var.display_name
|
||||
url = var.folder == "" ? "http://localhost:${var.port}" : "http://localhost:${var.port}?folder=${var.folder}"
|
||||
url = local.url
|
||||
icon = "/icon/code.svg"
|
||||
subdomain = true
|
||||
subdomain = var.subdomain
|
||||
share = var.share
|
||||
order = var.order
|
||||
|
||||
healthcheck {
|
||||
url = "http://localhost:${var.port}/healthz"
|
||||
url = local.healthcheck_url
|
||||
interval = 5
|
||||
threshold = 6
|
||||
}
|
||||
}
|
||||
|
||||
locals {
|
||||
server_base_path = var.subdomain ? "" : format("/@%s/%s/apps/%s/", data.coder_workspace_owner.me.name, data.coder_workspace.me.name, var.slug)
|
||||
url = var.folder == "" ? "http://localhost:${var.port}${local.server_base_path}" : "http://localhost:${var.port}${local.server_base_path}?folder=${var.folder}"
|
||||
healthcheck_url = var.subdomain ? "http://localhost:${var.port}/healthz" : "http://localhost:${var.port}${local.server_base_path}/healthz"
|
||||
}
|
||||
|
||||
@@ -10,10 +10,16 @@ if [ -n "${EXTENSIONS_DIR}" ]; then
|
||||
EXTENSION_ARG="--extensions-dir=${EXTENSIONS_DIR}"
|
||||
fi
|
||||
|
||||
# Set extension directory
|
||||
SERVER_BASE_PATH_ARG=""
|
||||
if [ -n "${SERVER_BASE_PATH}" ]; then
|
||||
SERVER_BASE_PATH_ARG="--server-base-path=${SERVER_BASE_PATH}"
|
||||
fi
|
||||
|
||||
run_vscode_web() {
|
||||
echo "👷 Running $VSCODE_WEB serve-local $EXTENSION_ARG --port ${PORT} --host 127.0.0.1 --accept-server-license-terms --without-connection-token --telemetry-level ${TELEMETRY_LEVEL} in the background..."
|
||||
echo "👷 Running $VSCODE_WEB serve-local $EXTENSION_ARG $SERVER_BASE_PATH_ARG --port ${PORT} --host 127.0.0.1 --accept-server-license-terms --without-connection-token --telemetry-level ${TELEMETRY_LEVEL} in the background..."
|
||||
echo "Check logs at ${LOG_PATH}!"
|
||||
"$VSCODE_WEB" serve-local "$EXTENSION_ARG" --port "${PORT}" --host 127.0.0.1 --accept-server-license-terms --without-connection-token --telemetry-level "${TELEMETRY_LEVEL}" > "${LOG_PATH}" 2>&1 &
|
||||
"$VSCODE_WEB" serve-local "$EXTENSION_ARG" "$SERVER_BASE_PATH_ARG" --port "${PORT}" --host 127.0.0.1 --accept-server-license-terms --without-connection-token --telemetry-level "${TELEMETRY_LEVEL}" > "${LOG_PATH}" 2>&1 &
|
||||
}
|
||||
|
||||
# Check if the settings file exists...
|
||||
@@ -72,27 +78,25 @@ for extension in "$${EXTENSIONLIST[@]}"; do
|
||||
output=$($VSCODE_WEB "$EXTENSION_ARG" --install-extension "$extension" --force)
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to install extension: $extension: $output"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "${AUTO_INSTALL_EXTENSIONS}" = true ]; then
|
||||
if ! command -v jq > /dev/null; then
|
||||
echo "jq is required to install extensions from a workspace file."
|
||||
exit 0
|
||||
fi
|
||||
else
|
||||
WORKSPACE_DIR="$HOME"
|
||||
if [ -n "${FOLDER}" ]; then
|
||||
WORKSPACE_DIR="${FOLDER}"
|
||||
fi
|
||||
|
||||
WORKSPACE_DIR="$HOME"
|
||||
if [ -n "${FOLDER}" ]; then
|
||||
WORKSPACE_DIR="${FOLDER}"
|
||||
fi
|
||||
|
||||
if [ -f "$WORKSPACE_DIR/.vscode/extensions.json" ]; then
|
||||
printf "🧩 Installing extensions from %s/.vscode/extensions.json...\n" "$WORKSPACE_DIR"
|
||||
extensions=$(jq -r '.recommendations[]' "$WORKSPACE_DIR"/.vscode/extensions.json)
|
||||
for extension in $extensions; do
|
||||
$VSCODE_WEB "$EXTENSION_ARG" --install-extension "$extension" --force
|
||||
done
|
||||
if [ -f "$WORKSPACE_DIR/.vscode/extensions.json" ]; then
|
||||
printf "🧩 Installing extensions from %s/.vscode/extensions.json...\n" "$WORKSPACE_DIR"
|
||||
extensions=$(jq -r '.recommendations[]' "$WORKSPACE_DIR"/.vscode/extensions.json)
|
||||
for extension in $extensions; do
|
||||
$VSCODE_WEB "$EXTENSION_ARG" --install-extension "$extension" --force
|
||||
done
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import {
|
||||
TerraformState,
|
||||
type TerraformState,
|
||||
runTerraformApply,
|
||||
runTerraformInit,
|
||||
testRequiredVariables,
|
||||
|
||||
Reference in New Issue
Block a user