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

Commit dda094f

Browse files
authored
Merge pull request #78 from coder/filebrowser-db
feat: add database_path specification to filebrowser
2 parents 9f110e6 + aaf56fe commit dda094f

File tree

4 files changed

+120
-3
lines changed

4 files changed

+120
-3
lines changed

filebrowser/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,13 @@ module "filebrowser" {
3131
folder = "/home/coder/project"
3232
}
3333
```
34+
35+
### Specify location of `filebrowser.db`
36+
37+
```hcl
38+
module "filebrowser" {
39+
source = "https://registry.coder.com/modules/filebrowser"
40+
agent_id = coder_agent.example.id
41+
database_path = ".config/filebrowser.db"
42+
}
43+
```

filebrowser/main.test.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { describe, expect, it } from "bun:test";
2+
import {
3+
executeScriptInContainer,
4+
runTerraformApply,
5+
runTerraformInit,
6+
testRequiredVariables,
7+
} from "../test";
8+
9+
describe("filebrowser", async () => {
10+
await runTerraformInit(import.meta.dir);
11+
12+
testRequiredVariables(import.meta.dir, {
13+
agent_id: "foo",
14+
});
15+
16+
it("fails with wrong database_path", async () => {
17+
const state = await runTerraformApply(import.meta.dir, {
18+
agent_id: "foo",
19+
database_path: "nofb",
20+
}).catch((e) => {
21+
if (!e.message.startsWith("\nError: Invalid value for variable")) {
22+
throw e;
23+
}
24+
});
25+
});
26+
27+
it("runs with default", async () => {
28+
const state = await runTerraformApply(import.meta.dir, {
29+
agent_id: "foo",
30+
});
31+
const output = await executeScriptInContainer(state, "alpine");
32+
expect(output.exitCode).toBe(0);
33+
expect(output.stdout).toEqual([
34+
"\u001b[0;1mInstalling filebrowser ",
35+
"",
36+
"🥳 Installation comlete! ",
37+
"",
38+
"👷 Starting filebrowser in background... ",
39+
"",
40+
"📂 Serving /root at http://localhost:13339 ",
41+
"",
42+
"Running 'filebrowser --noauth --root /root --port 13339' ",
43+
"",
44+
"📝 Logs at /tmp/filebrowser.log",
45+
]);
46+
});
47+
48+
it("runs with database_path var", async () => {
49+
const state = await runTerraformApply(import.meta.dir, {
50+
agent_id: "foo",
51+
database_path: ".config/filebrowser.db",
52+
});
53+
const output = await executeScriptInContainer(state, "alpine");
54+
expect(output.exitCode).toBe(0);
55+
expect(output.stdout).toEqual([
56+
"\u001b[0;1mInstalling filebrowser ",
57+
"",
58+
"🥳 Installation comlete! ",
59+
"",
60+
"👷 Starting filebrowser in background... ",
61+
"",
62+
"📂 Serving /root at http://localhost:13339 ",
63+
"",
64+
"Running 'filebrowser --noauth --root /root --port 13339 -d .config/filebrowser.db' ",
65+
"",
66+
"📝 Logs at /tmp/filebrowser.log",
67+
]);
68+
});
69+
70+
it("runs with folder var", async () => {
71+
const state = await runTerraformApply(import.meta.dir, {
72+
agent_id: "foo",
73+
folder: "/home/coder/project",
74+
});
75+
const output = await executeScriptInContainer(state, "alpine");
76+
expect(output.exitCode).toBe(0);
77+
expect(output.stdout).toEqual([
78+
"\u001B[0;1mInstalling filebrowser ",
79+
"",
80+
"🥳 Installation comlete! ",
81+
"",
82+
"👷 Starting filebrowser in background... ",
83+
"",
84+
"📂 Serving /home/coder/project at http://localhost:13339 ",
85+
"",
86+
"Running 'filebrowser --noauth --root /home/coder/project --port 13339' ",
87+
"",
88+
"📝 Logs at /tmp/filebrowser.log",
89+
]);
90+
});
91+
});

filebrowser/main.tf

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,22 @@ terraform {
99
}
1010
}
1111

12-
# Add required variables for your modules and remove any unneeded variables
1312
variable "agent_id" {
1413
type = string
1514
description = "The ID of a Coder agent."
1615
}
1716

17+
variable "database_path" {
18+
type = string
19+
description = "The path to the filebrowser database."
20+
default = "filebrowser.db"
21+
validation {
22+
# Ensures path leads to */filebrowser.db
23+
condition = can(regex(".*filebrowser\\.db$", var.database_path))
24+
error_message = "The database_path must end with 'filebrowser.db'."
25+
}
26+
}
27+
1828
variable "log_path" {
1929
type = string
2030
description = "The path to log filebrowser to."
@@ -42,6 +52,7 @@ resource "coder_script" "filebrowser" {
4252
PORT : var.port,
4353
FOLDER : var.folder,
4454
LOG_PATH : var.log_path,
55+
DB_PATH : var.database_path
4556
})
4657
run_on_start = true
4758
}

filebrowser/run.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ printf "👷 Starting filebrowser in background... \n\n"
1212
ROOT_DIR=${FOLDER}
1313
ROOT_DIR=$${ROOT_DIR/\~/$HOME}
1414

15+
DB_FLAG=""
16+
if [ "${DB_PATH}" != "filebrowser.db" ]; then
17+
DB_FLAG=" -d ${DB_PATH}"
18+
fi
19+
1520
printf "📂 Serving $${ROOT_DIR} at http://localhost:${PORT} \n\n"
1621

17-
printf "Running 'filebrowser --noauth --root $ROOT_DIR --port ${PORT}' \n\n"
22+
printf "Running 'filebrowser --noauth --root $ROOT_DIR --port ${PORT}$${DB_FLAG}' \n\n"
1823

19-
filebrowser --noauth --root $ROOT_DIR --port ${PORT} >${LOG_PATH} 2>&1 &
24+
filebrowser --noauth --root $ROOT_DIR --port ${PORT}$${DB_FLAG} >${LOG_PATH} 2>&1 &
2025

2126
printf "📝 Logs at ${LOG_PATH} \n\n"

0 commit comments

Comments
 (0)