Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

feat(filebrowser): support subdomain = false #286

Merged
merged 21 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions filebrowser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,14 @@ module "filebrowser" {
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.main.id
subdomain = false
agent_name = "main"
}
```
22 changes: 22 additions & 0 deletions filebrowser/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,26 @@ describe("filebrowser", async () => {
"📝 Logs at /tmp/filebrowser.log",
]);
});

it("runs with subdomain=false", async () => {
const state = await runTerraformApply(import.meta.dir, {
agent_id: "foo",
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",
]);
});
});
25 changes: 23 additions & 2 deletions filebrowser/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ variable "agent_id" {
description = "The ID of a Coder agent."
}

data "coder_workspace" "me" {}

data "coder_workspace_owner" "me" {}

variable "agent_name" {
type = string
default = "main"
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."
Expand Down Expand Up @@ -58,6 +68,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"
Expand All @@ -67,7 +86,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
}
Expand All @@ -78,7 +99,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
}
3 changes: 3 additions & 0 deletions filebrowser/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading