Skip to content

fix(filebrowser): configure before running #400

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 8 commits into from
Mar 21, 2025
Merged

Conversation

evilhamsterman
Copy link
Contributor

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.

@matifali
Copy link
Member

Hi @evilhamsterman, Could you take care of the tests that are failing?
Also, @dstoffel, can you review and verify if it works for your use case?

Thanks :)

@dstoffel
Copy link
Contributor

it's working correctly, thank you

@evilhamsterman
Copy link
Contributor Author

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 #!/usr/bin/env bash for the hash bang and calling bash to execute the script from curl. But the tests appear to be running in the Alpine container which doesn't have bash.

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 echo "Hello world" it doesn't register any output in the test and says it just received an empty string

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

Copy link
Member

@mafredri mafredri left a 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.)


filebrowser --noauth --root $ROOT_DIR --port ${PORT}$${DB_FLAG} --baseurl ${SERVER_BASE_PATH} > ${LOG_PATH} 2>&1 &
filebrowser $DB_FLAG >> ${LOG_PATH} 2>&1 &
Copy link
Member

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.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH There's a lot of places that it could break because of spaces in the path, the LOG_PATH and SERVER_BASE_PATH could also cause problems.

I do think I found a bit easier and more readable way to handle it. Filebrowser supports the FB_DATABASE environment variable. So I just set that at the top inside quotes and then it doesn't matter, it works with or without spaces.

@matifali matifali changed the title Configure filebrowser before running command fix(filebrowser): configure before running Feb 19, 2025
@matifali
Copy link
Member

matifali commented Mar 4, 2025

Hi @evilhamsterman, thank you for your contribution. Could you please address the review comments to merge this PR?

@evilhamsterman
Copy link
Contributor Author

@matifali Sorry I've had a very busy month. I should be able to get to it later this week

@evilhamsterman
Copy link
Contributor Author

I applied some of the suggestions above, I also resolved the issue of spaces in the DB path by using the FB_DATABASE environment variable instead. Let me know if there's anything else

@matifali matifali requested review from mafredri and Copilot March 7, 2025 19:27
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

@phorcys420 phorcys420 self-requested a review March 20, 2025 23:58
@phorcys420
Copy link
Member

phorcys420 commented Mar 21, 2025

@evilhamsterman the reason our tests are weird (even on main) is due to the fact the script is non-strict and ignores any stderr output, so the logs are correct even though everything is broken, basically meaning the tests are useless in this context.

the scripts should exit when errors like this occur, but they don't, i am puzzled as to how it even manages to run the script without bash though.

see this example
image

Copy link
Member

@phorcys420 phorcys420 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have confirmed that this works by creating a template on our internal instance.

image

@phorcys420
Copy link
Member

phorcys420 commented Mar 21, 2025

@matifali let's merge it with the broken tests and i'll fix the tests afterwards, could you force merge?

this PR is not the culprit for the broken tests, but our script is not strict enough, and our test suite will not fail on main even though the dependencies (bash and curl) are missing, I'm not sure why it's failing on this PR but the tests are wrong anyways so let's fix this afterwards.

we should look into having stricter values for our scripts like we do in coder/coder where set -euo pipefail is the standard, in this case we should at least have set -e in my opinion, this would at least make it so that the tests fail when they have to.

cc @mafredri for input

@matifali matifali merged commit 8b184eb into coder:main Mar 21, 2025
2 of 4 checks passed
@matifali
Copy link
Member

Force merged.

@evilhamsterman
Copy link
Contributor Author

Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Recent update to the filebrowser moduel breaks subdomains
5 participants