Skip to content

Commit f5ab799

Browse files
IamTaoChenmatifali
andauthored
feat(filebrowser): check if already installed (#334)
Co-authored-by: Muhammad Atif Ali <[email protected]>
1 parent 528a8a9 commit f5ab799

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

filebrowser/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ A file browser for your workspace.
1414
```tf
1515
module "filebrowser" {
1616
source = "registry.coder.com/modules/filebrowser/coder"
17-
version = "1.0.22"
17+
version = "1.0.23"
1818
agent_id = coder_agent.example.id
1919
}
2020
```
@@ -28,7 +28,7 @@ module "filebrowser" {
2828
```tf
2929
module "filebrowser" {
3030
source = "registry.coder.com/modules/filebrowser/coder"
31-
version = "1.0.22"
31+
version = "1.0.23"
3232
agent_id = coder_agent.example.id
3333
folder = "/home/coder/project"
3434
}
@@ -39,7 +39,7 @@ module "filebrowser" {
3939
```tf
4040
module "filebrowser" {
4141
source = "registry.coder.com/modules/filebrowser/coder"
42-
version = "1.0.22"
42+
version = "1.0.23"
4343
agent_id = coder_agent.example.id
4444
database_path = ".config/filebrowser.db"
4545
}

filebrowser/main.tf

+25-12
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,8 @@ data "coder_workspace_owner" "me" {}
2020

2121
variable "agent_name" {
2222
type = string
23-
description = "The name of the main deployment. (Used to build the subpath for coder_app.)"
24-
default = ""
25-
validation {
26-
# If subdomain is false, then agent_name must be set.
27-
condition = var.subdomain || var.agent_name != ""
28-
error_message = "The agent_name must be set."
29-
}
23+
description = "The name of the coder_agent resource. (Only required if subdomain is false and the template uses multiple agents.)"
24+
default = null
3025
}
3126

3227
variable "database_path" {
@@ -73,6 +68,12 @@ variable "order" {
7368
default = null
7469
}
7570

71+
variable "slug" {
72+
type = string
73+
description = "The slug of the coder_app resource."
74+
default = "filebrowser"
75+
}
76+
7677
variable "subdomain" {
7778
type = bool
7879
description = <<-EOT
@@ -85,26 +86,38 @@ variable "subdomain" {
8586
resource "coder_script" "filebrowser" {
8687
agent_id = var.agent_id
8788
display_name = "File Browser"
88-
icon = "https://raw.githubusercontent.com/filebrowser/logo/master/icon_raw.svg"
89+
icon = "/icon/filebrowser.svg"
8990
script = templatefile("${path.module}/run.sh", {
9091
LOG_PATH : var.log_path,
9192
PORT : var.port,
9293
FOLDER : var.folder,
9394
LOG_PATH : var.log_path,
9495
DB_PATH : var.database_path,
9596
SUBDOMAIN : var.subdomain,
96-
SERVER_BASE_PATH : var.subdomain ? "" : format("/@%s/%s.%s/apps/filebrowser", data.coder_workspace_owner.me.name, data.coder_workspace.me.name, var.agent_name),
97+
SERVER_BASE_PATH : local.server_base_path
9798
})
9899
run_on_start = true
99100
}
100101

101102
resource "coder_app" "filebrowser" {
102103
agent_id = var.agent_id
103-
slug = "filebrowser"
104+
slug = var.slug
104105
display_name = "File Browser"
105-
url = "http://localhost:${var.port}"
106-
icon = "https://raw.githubusercontent.com/filebrowser/logo/master/icon_raw.svg"
106+
url = local.url
107+
icon = "/icon/filebrowser.svg"
107108
subdomain = var.subdomain
108109
share = var.share
109110
order = var.order
111+
112+
healthcheck {
113+
url = local.healthcheck_url
114+
interval = 5
115+
threshold = 6
116+
}
110117
}
118+
119+
locals {
120+
server_base_path = var.subdomain ? "" : format("/@%s/%s%s/apps/%s", data.coder_workspace_owner.me.name, data.coder_workspace.me.name, var.agent_name != null ? ".${var.agent_name}" : "", var.slug)
121+
url = "http://localhost:${var.port}${local.server_base_path}"
122+
healthcheck_url = "http://localhost:${var.port}${local.server_base_path}/health"
123+
}

filebrowser/run.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#!/usr/bin/env bash
22

33
BOLD='\033[0;1m'
4+
45
printf "$${BOLD}Installing filebrowser \n\n"
56

6-
curl -fsSL https://raw.githubusercontent.com/filebrowser/get/master/get.sh | bash
7+
# Check if filebrowser is installed
8+
if ! command -v filebrowser &> /dev/null; then
9+
curl -fsSL https://raw.githubusercontent.com/filebrowser/get/master/get.sh | bash
10+
fi
711

812
printf "🥳 Installation complete! \n\n"
913

0 commit comments

Comments
 (0)