Initial commit

This commit is contained in:
Kyle Carberry
2023-09-07 14:54:27 +00:00
commit 4e5b8d1069
8 changed files with 290 additions and 0 deletions

62
code-server/README.md Normal file
View File

@@ -0,0 +1,62 @@
---
display_name: code-server
description: VS Code in the browser
icon: ../icons/code.svg
---
# code-server
Run [VS Code](https://github.com/Microsoft/vscode) on any machine anywhere and
access it in the browser.
![Screenshot 1](https://github.com/coder/code-server/raw/main/docs/assets/screenshot-1.png?raw=true)
![Screenshot 2](https://github.com/coder/code-server/raw/main/docs/assets/screenshot-2.png?raw=true)
## Highlights
- Code on any device with a consistent development environment
- Use cloud servers to speed up tests, compilations, downloads, and more
- Preserve battery life when you're on the go; all intensive tasks run on your
server
## Examples
### Extensions
Automatically install extensions from [OpenVSX](https://open-vsx.org/):
```hcl
module "code-server" {
source = "https://registry.coder.com/modules/code-server"
extensions = [
"
]
}
```
Enter the `<author>.<name>` into the extensions array and code-server will automatically install on start.
### Settings
Pre-configure code-server with settings:
```hcl
module "settings" {
source = "https://registry.coder.com/modules/code-server"
extensions = [ "dracula-theme.theme-dracula" ]
settings = {
"workbench.colorTheme" = "Dracula"
}
}
```
### Offline Mode
Just run code-server in the background, don't fetch it from GitHub:
```hcl
module "settings" {
source = "https://registry.coder.com/modules/code-server"
offline = true
}
```

82
code-server/main.tf Normal file
View File

@@ -0,0 +1,82 @@
terraform {
required_version = ">= 1.0"
required_providers {
coder = {
source = "terraform.local/coder/coder"
version = ">= 0.12"
}
}
}
variable "agent_id" {
type = string
description = "The ID of a Coder agent."
}
variable "extensions" {
type = list(string)
description = "A list of extensions to install."
default = [ ]
}
variable "port" {
type = number
description = "The port to run code-server on."
default = 13337
}
variable "settings" {
type = map(string)
description = "A map of settings to apply to code-server."
default = {}
}
variable "folder" {
type = string
description = "The folder to open in code-server."
default = ""
}
variable "install_prefix" {
type = string
description = "The prefix to install code-server to."
default = "/tmp/code-server"
}
variable "log_path" {
type = string
description = "The path to log code-server to."
default = "/tmp/code-server.log"
}
resource "coder_script" "code-server" {
agent_id = var.agent_id
display_name = "code-server"
icon = "/icon/code.svg"
script = templatefile("${path.module}/run.sh", {
EXTENSIONS: join(",", var.extensions),
PORT: var.port,
LOG_PATH: var.log_path,
INSTALL_PREFIX: var.install_prefix,
// This is necessary otherwise the quotes are stripped!
SETTINGS: replace(jsonencode(var.settings), "\"", "\\\""),
})
run_on_start = true
}
resource "coder_app" "code-server" {
agent_id = var.agent_id
slug = "code-server"
display_name = "code-server"
url = "http://localhost:${var.port}/?folder=${var.folder}"
icon = "/icon/code.svg"
subdomain = false
share = "owner"
healthcheck {
url = "http://localhost:${var.port}/healthz"
interval = 5
threshold = 6
}
}

37
code-server/run.sh Executable file
View File

@@ -0,0 +1,37 @@
#!/usr/bin/env sh
EXTENSIONS=("${EXTENSIONS}")
BOLD='\033[0;1m'
CODE='\033[36;40;1m'
RESET='\033[0m'
printf "$${BOLD}Installing code-server!\n"
output=$(curl -fsSL https://code-server.dev/install.sh | sh -s -- --method=standalone --prefix=${INSTALL_PREFIX})
if [ $? -ne 0 ]; then
echo "Failed to install code-server: $output"
exit 1
fi
printf "🥳 code-server has been installed in ${INSTALL_PREFIX}\n\n"
CODE_SERVER="${INSTALL_PREFIX}/bin/code-server"
# Install each extension...
for extension in "$${EXTENSIONS[@]}"; do
printf "🧩 Installing extension $${CODE}$extension$${RESET}...\n"
output=$($CODE_SERVER --install-extension "$extension")
if [ $? -ne 0 ]; then
echo "Failed to install extension: $extension: $output"
exit 1
fi
done
# Check if the settings file exists...
if [ ! -f ~/.local/share/code-server/User/settings.json ]; then
echo "⚙️ Creating settings file..."
mkdir -p ~/.local/share/code-server/User
echo "${SETTINGS}" > ~/.local/share/code-server/User/settings.json
fi
echo "👷 Running code-server in the background..."
echo "Check logs at ${LOG_PATH}!"
$CODE_SERVER --auth none --port ${PORT} >${LOG_PATH} 2>&1 &