Skip to content

feat(filebrowser): support subdomain = false #286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 21 additions & 7 deletions filebrowser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
```

Expand All @@ -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"
}
```

Expand All @@ -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
}
```
28 changes: 28 additions & 0 deletions filebrowser/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand All @@ -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);
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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",
]);
});
});
24 changes: 22 additions & 2 deletions filebrowser/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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"
Expand All @@ -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
}
Expand All @@ -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
}
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