feat(filebrowser): support subdomain = false (#286)
Co-authored-by: Muhammad Atif Ali <me@matifali.dev>
This commit is contained in:
@@ -16,6 +16,7 @@ module "filebrowser" {
|
|||||||
source = "registry.coder.com/modules/filebrowser/coder"
|
source = "registry.coder.com/modules/filebrowser/coder"
|
||||||
version = "1.0.8"
|
version = "1.0.8"
|
||||||
agent_id = coder_agent.example.id
|
agent_id = coder_agent.example.id
|
||||||
|
agent_name = "main"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -30,6 +31,7 @@ module "filebrowser" {
|
|||||||
source = "registry.coder.com/modules/filebrowser/coder"
|
source = "registry.coder.com/modules/filebrowser/coder"
|
||||||
version = "1.0.8"
|
version = "1.0.8"
|
||||||
agent_id = coder_agent.example.id
|
agent_id = coder_agent.example.id
|
||||||
|
agent_name = "main"
|
||||||
folder = "/home/coder/project"
|
folder = "/home/coder/project"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -41,6 +43,18 @@ module "filebrowser" {
|
|||||||
source = "registry.coder.com/modules/filebrowser/coder"
|
source = "registry.coder.com/modules/filebrowser/coder"
|
||||||
version = "1.0.8"
|
version = "1.0.8"
|
||||||
agent_id = coder_agent.example.id
|
agent_id = coder_agent.example.id
|
||||||
|
agent_name = "main"
|
||||||
database_path = ".config/filebrowser.db"
|
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
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|||||||
@@ -11,11 +11,13 @@ describe("filebrowser", async () => {
|
|||||||
|
|
||||||
testRequiredVariables(import.meta.dir, {
|
testRequiredVariables(import.meta.dir, {
|
||||||
agent_id: "foo",
|
agent_id: "foo",
|
||||||
|
agent_name: "main",
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fails with wrong database_path", async () => {
|
it("fails with wrong database_path", async () => {
|
||||||
const state = await runTerraformApply(import.meta.dir, {
|
const state = await runTerraformApply(import.meta.dir, {
|
||||||
agent_id: "foo",
|
agent_id: "foo",
|
||||||
|
agent_name: "main",
|
||||||
database_path: "nofb",
|
database_path: "nofb",
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
if (!e.message.startsWith("\nError: Invalid value for variable")) {
|
if (!e.message.startsWith("\nError: Invalid value for variable")) {
|
||||||
@@ -27,6 +29,7 @@ describe("filebrowser", async () => {
|
|||||||
it("runs with default", async () => {
|
it("runs with default", async () => {
|
||||||
const state = await runTerraformApply(import.meta.dir, {
|
const state = await runTerraformApply(import.meta.dir, {
|
||||||
agent_id: "foo",
|
agent_id: "foo",
|
||||||
|
agent_name: "main",
|
||||||
});
|
});
|
||||||
const output = await executeScriptInContainer(state, "alpine");
|
const output = await executeScriptInContainer(state, "alpine");
|
||||||
expect(output.exitCode).toBe(0);
|
expect(output.exitCode).toBe(0);
|
||||||
@@ -48,6 +51,7 @@ describe("filebrowser", async () => {
|
|||||||
it("runs with database_path var", async () => {
|
it("runs with database_path var", async () => {
|
||||||
const state = await runTerraformApply(import.meta.dir, {
|
const state = await runTerraformApply(import.meta.dir, {
|
||||||
agent_id: "foo",
|
agent_id: "foo",
|
||||||
|
agent_name: "main",
|
||||||
database_path: ".config/filebrowser.db",
|
database_path: ".config/filebrowser.db",
|
||||||
});
|
});
|
||||||
const output = await executeScriptInContainer(state, "alpine");
|
const output = await executeScriptInContainer(state, "alpine");
|
||||||
@@ -70,6 +74,7 @@ describe("filebrowser", async () => {
|
|||||||
it("runs with folder var", async () => {
|
it("runs with folder var", async () => {
|
||||||
const state = await runTerraformApply(import.meta.dir, {
|
const state = await runTerraformApply(import.meta.dir, {
|
||||||
agent_id: "foo",
|
agent_id: "foo",
|
||||||
|
agent_name: "main",
|
||||||
folder: "/home/coder/project",
|
folder: "/home/coder/project",
|
||||||
});
|
});
|
||||||
const output = await executeScriptInContainer(state, "alpine");
|
const output = await executeScriptInContainer(state, "alpine");
|
||||||
@@ -88,4 +93,27 @@ describe("filebrowser", async () => {
|
|||||||
"📝 Logs at /tmp/filebrowser.log",
|
"📝 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",
|
||||||
|
]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -14,6 +14,15 @@ variable "agent_id" {
|
|||||||
description = "The ID of a Coder agent."
|
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" {
|
variable "database_path" {
|
||||||
type = string
|
type = string
|
||||||
description = "The path to the filebrowser database."
|
description = "The path to the filebrowser database."
|
||||||
@@ -58,6 +67,15 @@ variable "order" {
|
|||||||
default = null
|
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" {
|
resource "coder_script" "filebrowser" {
|
||||||
agent_id = var.agent_id
|
agent_id = var.agent_id
|
||||||
display_name = "File Browser"
|
display_name = "File Browser"
|
||||||
@@ -67,7 +85,9 @@ resource "coder_script" "filebrowser" {
|
|||||||
PORT : var.port,
|
PORT : var.port,
|
||||||
FOLDER : var.folder,
|
FOLDER : var.folder,
|
||||||
LOG_PATH : var.log_path,
|
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
|
run_on_start = true
|
||||||
}
|
}
|
||||||
@@ -78,7 +98,7 @@ resource "coder_app" "filebrowser" {
|
|||||||
display_name = "File Browser"
|
display_name = "File Browser"
|
||||||
url = "http://localhost:${var.port}"
|
url = "http://localhost:${var.port}"
|
||||||
icon = "https://raw.githubusercontent.com/filebrowser/logo/master/icon_raw.svg"
|
icon = "https://raw.githubusercontent.com/filebrowser/logo/master/icon_raw.svg"
|
||||||
subdomain = true
|
subdomain = var.subdomain
|
||||||
share = var.share
|
share = var.share
|
||||||
order = var.order
|
order = var.order
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ if [ "${DB_PATH}" != "filebrowser.db" ]; then
|
|||||||
DB_FLAG=" -d ${DB_PATH}"
|
DB_FLAG=" -d ${DB_PATH}"
|
||||||
fi
|
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 "📂 Serving $${ROOT_DIR} at http://localhost:${PORT} \n\n"
|
||||||
|
|
||||||
printf "Running 'filebrowser --noauth --root $ROOT_DIR --port ${PORT}$${DB_FLAG}' \n\n"
|
printf "Running 'filebrowser --noauth --root $ROOT_DIR --port ${PORT}$${DB_FLAG}' \n\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user