Merge pull request #78 from coder/filebrowser-db
feat: add database_path specification to filebrowser
This commit is contained in:
@@ -31,3 +31,13 @@ module "filebrowser" {
|
|||||||
folder = "/home/coder/project"
|
folder = "/home/coder/project"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Specify location of `filebrowser.db`
|
||||||
|
|
||||||
|
```hcl
|
||||||
|
module "filebrowser" {
|
||||||
|
source = "https://registry.coder.com/modules/filebrowser"
|
||||||
|
agent_id = coder_agent.example.id
|
||||||
|
database_path = ".config/filebrowser.db"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|||||||
91
filebrowser/main.test.ts
Normal file
91
filebrowser/main.test.ts
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
import { describe, expect, it } from "bun:test";
|
||||||
|
import {
|
||||||
|
executeScriptInContainer,
|
||||||
|
runTerraformApply,
|
||||||
|
runTerraformInit,
|
||||||
|
testRequiredVariables,
|
||||||
|
} from "../test";
|
||||||
|
|
||||||
|
describe("filebrowser", async () => {
|
||||||
|
await runTerraformInit(import.meta.dir);
|
||||||
|
|
||||||
|
testRequiredVariables(import.meta.dir, {
|
||||||
|
agent_id: "foo",
|
||||||
|
});
|
||||||
|
|
||||||
|
it("fails with wrong database_path", async () => {
|
||||||
|
const state = await runTerraformApply(import.meta.dir, {
|
||||||
|
agent_id: "foo",
|
||||||
|
database_path: "nofb",
|
||||||
|
}).catch((e) => {
|
||||||
|
if (!e.message.startsWith("\nError: Invalid value for variable")) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("runs with default", async () => {
|
||||||
|
const state = await runTerraformApply(import.meta.dir, {
|
||||||
|
agent_id: "foo",
|
||||||
|
});
|
||||||
|
const output = await executeScriptInContainer(state, "alpine");
|
||||||
|
expect(output.exitCode).toBe(0);
|
||||||
|
expect(output.stdout).toEqual([
|
||||||
|
"\u001b[0;1mInstalling filebrowser ",
|
||||||
|
"",
|
||||||
|
"🥳 Installation comlete! ",
|
||||||
|
"",
|
||||||
|
"👷 Starting filebrowser in background... ",
|
||||||
|
"",
|
||||||
|
"📂 Serving /root at http://localhost:13339 ",
|
||||||
|
"",
|
||||||
|
"Running 'filebrowser --noauth --root /root --port 13339' ",
|
||||||
|
"",
|
||||||
|
"📝 Logs at /tmp/filebrowser.log",
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("runs with database_path var", async () => {
|
||||||
|
const state = await runTerraformApply(import.meta.dir, {
|
||||||
|
agent_id: "foo",
|
||||||
|
database_path: ".config/filebrowser.db",
|
||||||
|
});
|
||||||
|
const output = await executeScriptInContainer(state, "alpine");
|
||||||
|
expect(output.exitCode).toBe(0);
|
||||||
|
expect(output.stdout).toEqual([
|
||||||
|
"\u001b[0;1mInstalling filebrowser ",
|
||||||
|
"",
|
||||||
|
"🥳 Installation comlete! ",
|
||||||
|
"",
|
||||||
|
"👷 Starting filebrowser in background... ",
|
||||||
|
"",
|
||||||
|
"📂 Serving /root at http://localhost:13339 ",
|
||||||
|
"",
|
||||||
|
"Running 'filebrowser --noauth --root /root --port 13339 -d .config/filebrowser.db' ",
|
||||||
|
"",
|
||||||
|
"📝 Logs at /tmp/filebrowser.log",
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("runs with folder var", async () => {
|
||||||
|
const state = await runTerraformApply(import.meta.dir, {
|
||||||
|
agent_id: "foo",
|
||||||
|
folder: "/home/coder/project",
|
||||||
|
});
|
||||||
|
const output = await executeScriptInContainer(state, "alpine");
|
||||||
|
expect(output.exitCode).toBe(0);
|
||||||
|
expect(output.stdout).toEqual([
|
||||||
|
"\u001B[0;1mInstalling filebrowser ",
|
||||||
|
"",
|
||||||
|
"🥳 Installation comlete! ",
|
||||||
|
"",
|
||||||
|
"👷 Starting filebrowser in background... ",
|
||||||
|
"",
|
||||||
|
"📂 Serving /home/coder/project at http://localhost:13339 ",
|
||||||
|
"",
|
||||||
|
"Running 'filebrowser --noauth --root /home/coder/project --port 13339' ",
|
||||||
|
"",
|
||||||
|
"📝 Logs at /tmp/filebrowser.log",
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -9,12 +9,22 @@ terraform {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add required variables for your modules and remove any unneeded variables
|
|
||||||
variable "agent_id" {
|
variable "agent_id" {
|
||||||
type = string
|
type = string
|
||||||
description = "The ID of a Coder agent."
|
description = "The ID of a Coder agent."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variable "database_path" {
|
||||||
|
type = string
|
||||||
|
description = "The path to the filebrowser database."
|
||||||
|
default = "filebrowser.db"
|
||||||
|
validation {
|
||||||
|
# Ensures path leads to */filebrowser.db
|
||||||
|
condition = can(regex(".*filebrowser\\.db$", var.database_path))
|
||||||
|
error_message = "The database_path must end with 'filebrowser.db'."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
variable "log_path" {
|
variable "log_path" {
|
||||||
type = string
|
type = string
|
||||||
description = "The path to log filebrowser to."
|
description = "The path to log filebrowser to."
|
||||||
@@ -42,6 +52,7 @@ 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
|
||||||
})
|
})
|
||||||
run_on_start = true
|
run_on_start = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,10 +12,15 @@ printf "👷 Starting filebrowser in background... \n\n"
|
|||||||
ROOT_DIR=${FOLDER}
|
ROOT_DIR=${FOLDER}
|
||||||
ROOT_DIR=$${ROOT_DIR/\~/$HOME}
|
ROOT_DIR=$${ROOT_DIR/\~/$HOME}
|
||||||
|
|
||||||
|
DB_FLAG=""
|
||||||
|
if [ "${DB_PATH}" != "filebrowser.db" ]; then
|
||||||
|
DB_FLAG=" -d ${DB_PATH}"
|
||||||
|
fi
|
||||||
|
|
||||||
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}' \n\n"
|
printf "Running 'filebrowser --noauth --root $ROOT_DIR --port ${PORT}$${DB_FLAG}' \n\n"
|
||||||
|
|
||||||
filebrowser --noauth --root $ROOT_DIR --port ${PORT} >${LOG_PATH} 2>&1 &
|
filebrowser --noauth --root $ROOT_DIR --port ${PORT}$${DB_FLAG} >${LOG_PATH} 2>&1 &
|
||||||
|
|
||||||
printf "📝 Logs at ${LOG_PATH} \n\n"
|
printf "📝 Logs at ${LOG_PATH} \n\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user