feat: add use_cached mode

Changes:
- Update docs to include use_cached mode
- Add validation checks
- Add support for use_cached mode
pull/184/head
Michael Brewer 1 year ago
parent a874354dd9
commit a150da4f47
No known key found for this signature in database
GPG Key ID: D7A137BA1254AFC7

@ -80,9 +80,23 @@ module "code-server" {
}
```
### Offline Mode
### Offline and Use Cached Modes
Run an existing copy of code-server if found, otherwise download from GitHub. By default the module looks for code-server at `/tmp/code-server` but this can be changed with `install_prefix`.
By default the module looks for code-server at `/tmp/code-server` but this can be changed with `install_prefix`.
Run an existing copy of code-server if found, otherwise download from GitHub:
```tf
module "code-server" {
source = "registry.coder.com/modules/code-server/coder"
version = "1.0.8"
agent_id = coder_agent.example.id
use_cached = true
extensions = ["dracula-theme.theme-dracula", "ms-azuretools.vscode-docker"]
}
```
Just run code-server in the background, don't fetch it from GitHub:
```tf
module "code-server" {

@ -89,6 +89,12 @@ variable "offline" {
default = false
}
variable "use_cached" {
type = bool
description = "Uses cached copy code-server in the background, otherwise fetched it from GitHub"
default = false
}
resource "coder_script" "code-server" {
agent_id = var.agent_id
display_name = "code-server"
@ -103,8 +109,21 @@ resource "coder_script" "code-server" {
// This is necessary otherwise the quotes are stripped!
SETTINGS : replace(jsonencode(var.settings), "\"", "\\\""),
OFFLINE : var.offline,
USE_CACHED : var.use_cached,
})
run_on_start = true
lifecycle {
precondition {
condition = !var.offline || length(var.extensions) == 0
error_message = "Offline mode does not allow extensions to be installed"
}
precondition {
condition = !var.offline || !var.use_cached
error_message = "Offline and Use Cached can not be used together"
}
}
}
resource "coder_app" "code-server" {

@ -19,10 +19,18 @@ if [ ! -f ~/.local/share/code-server/User/settings.json ]; then
echo "${SETTINGS}" > ~/.local/share/code-server/User/settings.json
fi
if [ "${OFFLINE}" = true ] && [ -f $CODE_SERVER ]; then
echo "🥳 Found offline copy of code-server"
# Check if code-server is already installed for offline or cached mode
if [ -f $CODE_SERVER ]; then
if "${OFFLINE}" = true || "${USE_CACHED}" = true; then
echo "🥳 Found a copy of code-server"
run_code_server
exit 0
fi
fi
# Offline mode always expects a copy of code-server to be present
if [ "${OFFLINE}" = true ]; then
echo "Failed to find a copy of code-server"
exit 1
fi
printf "$${BOLD}Installing code-server!\n"

Loading…
Cancel
Save