diff --git a/filebrowser/README.md b/filebrowser/README.md index 2881376..50b503a 100644 --- a/filebrowser/README.md +++ b/filebrowser/README.md @@ -13,9 +13,10 @@ A file browser for your workspace. ```tf module "filebrowser" { - source = "registry.coder.com/modules/filebrowser/coder" - version = "1.0.8" - agent_id = coder_agent.example.id + source = "registry.coder.com/modules/filebrowser/coder" + version = "1.0.8" + agent_id = coder_agent.example.id + agent_name = "main" } ``` @@ -27,10 +28,11 @@ module "filebrowser" { ```tf module "filebrowser" { - source = "registry.coder.com/modules/filebrowser/coder" - version = "1.0.8" - agent_id = coder_agent.example.id - folder = "/home/coder/project" + source = "registry.coder.com/modules/filebrowser/coder" + version = "1.0.8" + agent_id = coder_agent.example.id + agent_name = "main" + folder = "/home/coder/project" } ``` @@ -41,6 +43,18 @@ module "filebrowser" { source = "registry.coder.com/modules/filebrowser/coder" version = "1.0.8" agent_id = coder_agent.example.id + agent_name = "main" database_path = ".config/filebrowser.db" } ``` + +### Serve from the same domain (no subdomain) + +```tf +module "filebrowser" { + source = "registry.coder.com/modules/filebrowser/coder" + agent_id = coder_agent.example.id + agent_name = "main" + subdomain = false +} +``` diff --git a/filebrowser/main.test.ts b/filebrowser/main.test.ts index 79dd99d..ff6d045 100644 --- a/filebrowser/main.test.ts +++ b/filebrowser/main.test.ts @@ -11,11 +11,13 @@ describe("filebrowser", async () => { testRequiredVariables(import.meta.dir, { agent_id: "foo", + agent_name: "main", }); it("fails with wrong database_path", async () => { const state = await runTerraformApply(import.meta.dir, { agent_id: "foo", + agent_name: "main", database_path: "nofb", }).catch((e) => { if (!e.message.startsWith("\nError: Invalid value for variable")) { @@ -27,6 +29,7 @@ describe("filebrowser", async () => { it("runs with default", async () => { const state = await runTerraformApply(import.meta.dir, { agent_id: "foo", + agent_name: "main", }); const output = await executeScriptInContainer(state, "alpine"); expect(output.exitCode).toBe(0); @@ -48,6 +51,7 @@ describe("filebrowser", async () => { it("runs with database_path var", async () => { const state = await runTerraformApply(import.meta.dir, { agent_id: "foo", + agent_name: "main", database_path: ".config/filebrowser.db", }); const output = await executeScriptInContainer(state, "alpine"); @@ -70,6 +74,7 @@ describe("filebrowser", async () => { it("runs with folder var", async () => { const state = await runTerraformApply(import.meta.dir, { agent_id: "foo", + agent_name: "main", folder: "/home/coder/project", }); const output = await executeScriptInContainer(state, "alpine"); @@ -88,4 +93,27 @@ describe("filebrowser", async () => { "📝 Logs at /tmp/filebrowser.log", ]); }); + + it("runs with subdomain=false", async () => { + const state = await runTerraformApply(import.meta.dir, { + agent_id: "foo", + agent_name: "main", + subdomain: false, + }); + const output = await executeScriptInContainer(state, "alpine"); + expect(output.exitCode).toBe(0); + expect(output.stdout).toEqual([ + "\u001B[0;1mInstalling filebrowser ", + "", + "🥳 Installation complete! ", + "", + "👷 Starting filebrowser in background... ", + "", + "📂 Serving /root at http://localhost:13339 ", + "", + "Running 'filebrowser --noauth --root /root --port 13339' ", + "", + "📝 Logs at /tmp/filebrowser.log", + ]); + }); }); diff --git a/filebrowser/main.tf b/filebrowser/main.tf index a07072b..e6b88c6 100644 --- a/filebrowser/main.tf +++ b/filebrowser/main.tf @@ -14,6 +14,15 @@ variable "agent_id" { description = "The ID of a Coder agent." } +data "coder_workspace" "me" {} + +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.)" +} + variable "database_path" { type = string description = "The path to the filebrowser database." @@ -58,6 +67,15 @@ variable "order" { default = null } +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 +} + resource "coder_script" "filebrowser" { agent_id = var.agent_id display_name = "File Browser" @@ -67,7 +85,9 @@ resource "coder_script" "filebrowser" { PORT : var.port, FOLDER : var.folder, LOG_PATH : var.log_path, - DB_PATH : var.database_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), }) run_on_start = true } @@ -78,7 +98,7 @@ resource "coder_app" "filebrowser" { display_name = "File Browser" url = "http://localhost:${var.port}" icon = "https://raw.githubusercontent.com/filebrowser/logo/master/icon_raw.svg" - subdomain = true + subdomain = var.subdomain share = var.share order = var.order } diff --git a/filebrowser/run.sh b/filebrowser/run.sh index 8744edb..22f13ed 100644 --- a/filebrowser/run.sh +++ b/filebrowser/run.sh @@ -17,6 +17,9 @@ if [ "${DB_PATH}" != "filebrowser.db" ]; then DB_FLAG=" -d ${DB_PATH}" 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 + printf "📂 Serving $${ROOT_DIR} at http://localhost:${PORT} \n\n" printf "Running 'filebrowser --noauth --root $ROOT_DIR --port ${PORT}$${DB_FLAG}' \n\n"