Skip to content
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

feat(filebrowser): check if already installed #334

Merged
merged 6 commits into from
Oct 30, 2024
Merged

Conversation

IamTaoChen
Copy link
Contributor

Add check if the filebrowser exist

@matifali matifali changed the title Filebrowser will only be installed if it doesn’t exist on the system. feat(filebrowser): check if already installed Oct 28, 2024
filebrowser/run.sh Outdated Show resolved Hide resolved
Copy link
Member

@matifali matifali left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution.
Can you please run bun update-version or ./scripts/update-version.sh.

@IamTaoChen
Copy link
Contributor Author

Done

@matifali
Copy link
Member

Hi @IamTaoChen could you also run bun install && bun fmt?
Then run bun test filebrowser/main.test.ts with docker installed to run tests for the module. Make sure they pass.

@IamTaoChen
Copy link
Contributor Author

During testing, I encountered an error in main.tf related to the variable validation logic:

modules2 git:(main) ✗ bun test filebrowser/main.test.ts --verbose
bun test v1.1.33 (247456b6)

filebrowser/main.test.ts:
Terraform encountered problems during initialisation, including problems
with the configuration, described below.

The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.
╷
│ Error: Invalid reference in variable validation
│ 
│   on main.tf line 27, in variable "agent_name":
│   27:     condition     = var.subdomain || var.agent_name != ""
│ 
│ The condition for variable "agent_name" can only refer to the variable itself, using var.agent_name.
╵

Terraform’s validation rules don’t allow a variable’s validation logic to reference other variables, such as var.subdomain. If I comment out or mask this part of the code, the test passes successfully. However, I’m unsure if masking it in this PR is the right approach.

Should I proceed by temporarily masking the validation to unblock the tests, or would you recommend another way to handle this dependency.

@matifali
Copy link
Member

matifali commented Oct 30, 2024

@IamTaoChen Let us remove the validation from agent_name and make it an optional variable with a default set to null.

I am actually doing some changes in https://github.com/coder/modules/blob/atif/qol-improvments/filebrowser/main.tf

Feel free to bring them in for filebrowser in your PR.

@IamTaoChen
Copy link
Contributor Author

Now, it passed the test

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.

LGTM, thanks for your contribution!

printf "$${BOLD}Installing filebrowser \n\n"

curl -fsSL https://raw.githubusercontent.com/filebrowser/get/master/get.sh | bash
# Check if filebrowser is installed
if ! command -v filebrowser &> /dev/null; then
Copy link
Member

Choose a reason for hiding this comment

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

(No action, just commentary.)

This is nice, but unfortunately it's rare that users will benefit since it's usually installed to /usr/local/bin. For containers it's rarely persisted.

It'd be cool if we could store this in $CODER_SCRIPT_BIN_DIR instead. Usually this is within /tmp but it's possible to change by starting the coder agent with CODER_AGENT_SCRIPT_DATA_DIR=/path/to/persistent/dir.

This is something to consider for all modules, should we track this in a new issue @matifali?

Copy link
Member

Choose a reason for hiding this comment

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

This is nice, but unfortunately it's rare that users will benefit since it's usually installed to /usr/local/bin. For containers it's rarely persisted.

For air-gapped scenarios where the image already has it installed this is beneficial.

It'd be cool if we could store this in $CODER_SCRIPT_BIN_DIR instead. Usually this is within /tmp but it's possible to change by starting the coder agent with CODER_AGENT_SCRIPT_DATA_DIR=/path/to/persistent/dir.

I am a bit confused about $CODER_SCRIPT_BIN_DIR and $CODER_AGENT_SCRIPT_DATA_DIR. Do we have them already and how are the used? Or are you proposing this new concept.

Copy link
Member

Choose a reason for hiding this comment

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

For air-gapped scenarios where the image already has it installed this is beneficial.

👍🏻

I am a bit confused about $CODER_SCRIPT_BIN_DIR and $CODER_AGENT_SCRIPT_DATA_DIR. Do we have them already and how are the used? Or are you proposing this new concept.

We have them.

Let's say you run the agent this way:

coder agent --script-data-dir=/home/coder/.local/coder-script

Now all coder scripts will be executed with the following environment variables:

CODER_SCRIPT_DATA_DIR=/home/coder/.local/coder-script/[UUID]
CODER_SCRIPT_BIN_DIR=/home/coder/.local/coder-script/bin

And the coder agent will automatically add /home/coder/.local/coder-script/bin to the PATH.

Even without specifying the script dir, a default will be used, you can verify this in your workspace:

ls /tmp/coder-script-data

Copy link
Member

Choose a reason for hiding this comment

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

This is super useful and we should start using it in our modules.

@matifali matifali merged commit f5ab799 into coder:main Oct 30, 2024
2 checks passed
@IamTaoChen
Copy link
Contributor Author

Hi I just noticed that /icon/filebrowser.svg doesn't exist on version of 2.16

johnstcn added a commit to coder/coder that referenced this pull request Nov 4, 2024
Fixes #15365

We used to hit
https://raw.githubusercontent.com/filebrowser/logo/master/icon_raw.svg
for the filebrowser icon but coder/modules#334 modified the icon URL to
point to a self-hosted icon.

I simply copied the icon from the `coder/modules` repo.
stirby pushed a commit to coder/coder that referenced this pull request Nov 4, 2024
Fixes #15365

We used to hit
https://raw.githubusercontent.com/filebrowser/logo/master/icon_raw.svg
for the filebrowser icon but coder/modules#334 modified the icon URL to
point to a self-hosted icon.

I simply copied the icon from the `coder/modules` repo.

(cherry picked from commit dc29b81)
stirby added a commit to coder/coder that referenced this pull request Nov 4, 2024
Fixes #15365

We used to hit
https://raw.githubusercontent.com/filebrowser/logo/master/icon_raw.svg
for the filebrowser icon but coder/modules#334 modified the icon URL to
point to a self-hosted icon.

I simply copied the icon from the `coder/modules` repo.

(cherry picked from commit dc29b81)

Co-authored-by: Cian Johnston <[email protected]>
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.

3 participants