From ab527c8ffdf52391d4cae6e53b05f64b9e735dbf Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Wed, 27 Sep 2023 09:14:17 -0500 Subject: [PATCH] fix: add `install_version` to code-server --- code-server/main.tf | 7 +++++++ code-server/run.sh | 13 +++++++++++-- test.ts | 3 ++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/code-server/main.tf b/code-server/main.tf index 87e3036..e9bede3 100644 --- a/code-server/main.tf +++ b/code-server/main.tf @@ -50,11 +50,18 @@ variable "log_path" { default = "/tmp/code-server.log" } +variable "install_version" { + type = string + description = "The version of code-server to install." + default = "" +} + resource "coder_script" "code-server" { agent_id = var.agent_id display_name = "code-server" icon = "/icon/code.svg" script = templatefile("${path.module}/run.sh", { + VERSION : var.install_version, EXTENSIONS : join(",", var.extensions), PORT : var.port, LOG_PATH : var.log_path, diff --git a/code-server/run.sh b/code-server/run.sh index 116af8c..d6218a1 100755 --- a/code-server/run.sh +++ b/code-server/run.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash EXTENSIONS=("${EXTENSIONS}") BOLD='\033[0;1m' @@ -6,7 +6,16 @@ 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}) + +ARGS=( + "--method=standalone" + "--prefix=${INSTALL_PREFIX}" +) +if [ -n "${VERSION}" ]; then + args+=("--version=${VERSION}") +fi + +output=$(curl -fsSL https://code-server.dev/install.sh | sh -s -- "$${ARGS[@]}") if [ $? -ne 0 ]; then echo "Failed to install code-server: $output" exit 1 diff --git a/test.ts b/test.ts index 747601d..6546490 100644 --- a/test.ts +++ b/test.ts @@ -32,6 +32,7 @@ export const runContainer = async ( export const executeScriptInContainer = async ( state: TerraformState, image: string, + shell: string = "sh", ): Promise<{ exitCode: number; stdout: string[]; @@ -39,7 +40,7 @@ export const executeScriptInContainer = async ( }> => { const instance = findResourceInstance(state, "coder_script"); const id = await runContainer(image); - const resp = await execContainer(id, ["sh", "-c", instance.script]); + const resp = await execContainer(id, [shell, "-c", instance.script]); const stdout = resp.stdout.trim().split("\n"); const stderr = resp.stderr.trim().split("\n"); return {