-
Notifications
You must be signed in to change notification settings - Fork 51
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
fix(filebrowser): configure before running #400
base: main
Are you sure you want to change the base?
Conversation
Hi @evilhamsterman, Could you take care of the tests that are failing? Thanks :) |
it's working correctly, thank you |
So looking at the failing tests they fail even with the older versions of the script. I have tested all those options myself and they all work. What is the expected scripting environment, the script was using Also it seems something's wrong with how it checks Stdout. Even if I change the container to something like debian:bookworm which has bash and make the script do nothing but 28 | const state = await runTerraformApply(import.meta.dir, {
29 | agent_id: "foo",
30 | });
31 | const output = await executeScriptInContainer(state, "debian:bookworm-slim");
32 | expect(output.exitCode).toBe(0);
33 | expect(output.stdout).toEqual([
^
error: expect(received).toEqual(expected)
[
+ ""
- "👷 Starting filebrowser in background... ",
- "",
- "📂 Serving /root at http://localhost:13339 ",
- "",
- "Running 'filebrowser -d filebrowser.db' ",
- "",
- "📝 Logs at /tmp/filebrowser.log"
]
- Expected - 7
+ Received + 1
at <anonymous> (/home/dmills/development/coder-modules/filebrowser/main.test.ts:33:27)
✗ filebrowser > runs with default [546.26ms]
46 | agent_id: "foo",
47 | database_path: ".config/filebrowser.db",
48 | });
49 | const output = await executeScriptInContainer(state, "debian:bookworm-slim");
50 | expect(output.exitCode).toBe(0);
51 | expect(output.stdout).toEqual([
^
error: expect(received).toEqual(expected)
[
+ ""
- "\u001B[0;1mInstalling filebrowser ",
- "",
- "🥳 Installation complete! ",
- "",
- "👷 Starting filebrowser in background... ",
- "",
- "📂 Serving /root at http://localhost:13339 ",
- "",
- "Running 'filebrowser --noauth --root /root --port 13339 -d .config/filebrowser.db --baseurl ' ",
- "",
- "📝 Logs at /tmp/filebrowser.log"
]
- Expected - 11
+ Received + 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had some minor suggestions, but didn't spot anything terribly wrong that wasn't already. 😄
Also, since this is a Bash dependent script, we should use [[
instead of [
. The former has many benefits and no downsides compared to [
. (Not requiring this change though, as it's what was used before.)
@@ -21,10 +21,21 @@ if [ "${DB_PATH}" != "filebrowser.db" ]; then | |||
DB_FLAG=" -d ${DB_PATH}" | |||
fi | |||
|
|||
# Check if filebrowser db exists | |||
if [ ! -f ${DB_PATH} ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if [ ! -f ${DB_PATH} ]; then | |
if [ -n "$DB_FLAG" ]; then |
Ideally I'd want DB_FLAG to be an array, so it can handle spaces in DB_PATH, but for now let's at least improve this check to avoid syntax errors.
filebrowser $DB_FLAG config init >> ${LOG_PATH} 2>&1 | ||
filebrowser $DB_FLAG users add admin "" --perm.admin=true --viewMode=mosaic >> ${LOG_PATH} 2>&1 | ||
fi | ||
|
||
filebrowser $DB_FLAG config set --baseurl=${SERVER_BASE_PATH} --port=${PORT} --auth.method=noauth --root=$ROOT_DIR >> ${LOG_PATH} 2>&1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filebrowser $DB_FLAG config init >> ${LOG_PATH} 2>&1 | |
filebrowser $DB_FLAG users add admin "" --perm.admin=true --viewMode=mosaic >> ${LOG_PATH} 2>&1 | |
fi | |
filebrowser $DB_FLAG config set --baseurl=${SERVER_BASE_PATH} --port=${PORT} --auth.method=noauth --root=$ROOT_DIR >> ${LOG_PATH} 2>&1 | |
filebrowser $DB_FLAG config init 2>&1 | tee -a "${LOG_PATH}" | |
filebrowser $DB_FLAG users add admin "" --perm.admin=true --viewMode=mosaic 2>&1 | tee -a "${LOG_PATH}" | |
fi | |
filebrowser $DB_FLAG config set --baseurl=${SERVER_BASE_PATH} --port=${PORT} --auth.method=noauth --root=$ROOT_DIR 2>&1 | tee -a "${LOG_PATH}" |
Just a suggestion, this will allow showing the output in the Coder UI as well as the log file (useful in case of error).
printf "📂 Serving $${ROOT_DIR} at http://localhost:${PORT} \n\n" | ||
|
||
printf "Running 'filebrowser --noauth --root $ROOT_DIR --port ${PORT}$${DB_FLAG} --baseurl ${SERVER_BASE_PATH}' \n\n" | ||
printf "Running 'filebrowser $DB_FLAG' \n\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
printf "Running 'filebrowser $DB_FLAG' \n\n" | |
printf "Running 'filebrowser %s'\n\n" "$DB_FLAG" |
Since we're using printf, this is the typical way to include variable content. 😄
|
||
filebrowser --noauth --root $ROOT_DIR --port ${PORT}$${DB_FLAG} --baseurl ${SERVER_BASE_PATH} > ${LOG_PATH} 2>&1 & | ||
filebrowser $DB_FLAG >> ${LOG_PATH} 2>&1 & |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to make it clear that this issue was not introduced by this PR.
But I'll just mention this again; this will break if DB_PATH
has spaces in it. A better way would be to initialize this as an array and use it in a way that handles spaces:
args=()
if [ "${DB_PATH}" != "filebrowser.db" ]; then
args+=(-d "${DB_PATH}")
fi
Then use this as:
filebrowser "${args[@]}"
(I did not verify if $$
vs $
is required here due to terraform templates.)
This syntax works even in bash-3.2, so should be fine to use. (I opted for arrays as I see we already have a heavy dependency on Bash here.)
Fixes #399
Instead of trying to cram the config into one command we check if the db exists, if not initialize it then configure the various values before starting the app.