diff --git a/.icons/filebrowser.svg b/.icons/filebrowser.svg new file mode 100644 index 0000000..5e78ecc --- /dev/null +++ b/.icons/filebrowser.svg @@ -0,0 +1,147 @@ + +image/svg+xml + + + + + \ No newline at end of file diff --git a/filebrowser/README.md b/filebrowser/README.md new file mode 100644 index 0000000..bd1ba07 --- /dev/null +++ b/filebrowser/README.md @@ -0,0 +1,31 @@ +--- +display_name: File Browser +description: A file browser for your workspace +icon: ../.icons/filebrowser.svg +maintainer_github: coder +verified: true +tags: [helper, filebrowser] +--- + +# File Browser + +A file browser for your workspace. + +```hcl +module "filebrowser" { + source = "https://registry.coder.com/modules/filebrowser" + agent_id = coder_agent.example.id +} +``` + +## Examples + +### Serve a specific directory + +```hcl +module "filebrowser" { + source = "https://registry.coder.com/modules/filebrowser" + agent_id = coder_agent.example.id + folder = "/home/coder/project" +} +``` diff --git a/filebrowser/main.tf b/filebrowser/main.tf new file mode 100644 index 0000000..895e754 --- /dev/null +++ b/filebrowser/main.tf @@ -0,0 +1,63 @@ +terraform { + required_version = ">= 1.0" + + required_providers { + coder = { + source = "coder/coder" + version = ">= 0.12" + } + } +} + +# Add required variables for your modules and remove any unneeded variables +variable "agent_id" { + type = string + description = "The ID of a Coder agent." +} + +variable "log_path" { + type = string + description = "The path to log filebrowser to." + default = "/tmp/filebrowser.log" +} + +variable "port" { + type = number + description = "The port to run filebrowser on." + default = 19999 +} + +variable "folder" { + type = string + description = "The folder to serve." + default = "~" +} + +resource "coder_script" "filebrowser" { + agent_id = var.agent_id + display_name = "filebrowser" + icon = "https://raw.githubusercontent.com/filebrowser/logo/master/icon_raw.svg" + script = templatefile("${path.module}/run.sh", { + LOG_PATH : var.log_path, + PORT : var.port, + FOLDER : var.folder, + }) + run_on_start = true +} + +resource "coder_app" "filebrowser" { + agent_id = var.agent_id + slug = "filebrowser" + display_name = "filebrowser" + url = "http://localhost:${var.port}" + icon = "https://raw.githubusercontent.com/filebrowser/logo/master/icon_raw.svg" + subdomain = false + share = "owner" + + # Remove if the app does not have a healthcheck endpoint + healthcheck { + url = "http://localhost:${var.port}/healthz" + interval = 5 + threshold = 6 + } +} diff --git a/filebrowser/run.sh b/filebrowser/run.sh new file mode 100644 index 0000000..def0e61 --- /dev/null +++ b/filebrowser/run.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env sh + +BOLD='\033[0;1m' +echo "$${BOLD}Installing filebrowser..." + +curl -fsSL https://raw.githubusercontent.com/filebrowser/get/master/get.sh | bash + +echo "🥳 Installation comlete!" + +echo "👷 Starting filebrowser in background..." + +# if FOLDER is ~ then use $HOME +if [ "${FOLDER}" = "~" ]; then + FOLDER=$HOME +else + FOLDER=${FOLDER} +fi +filebrowser --noauth --root $FOLDER --port ${PORT} >/tmp/filebrowser.log >${LOG_PATH} 2>&1 & + +echo "check logs at ${LOG_PATH}" diff --git a/new.sh b/new.sh index ea80ffe..29e4f52 100755 --- a/new.sh +++ b/new.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash # This scripts creates a new sample moduledir with requried files # Run it like : ./new.sh my-module