From c6e92b656c5b59c67115e7189ca2342fa7929083 Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Sat, 25 May 2024 08:18:05 -0700 Subject: [PATCH 01/12] fix(code-server): USE_CACHED should still install extensions When USE_CACHED is true and no extensions have been installed Then we should still try to install them --- code-server/run.sh | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/code-server/run.sh b/code-server/run.sh index 26a1c6ec..8ef7763b 100755 --- a/code-server/run.sh +++ b/code-server/run.sh @@ -10,6 +10,9 @@ CODE_SERVER="${INSTALL_PREFIX}/bin/code-server" EXTENSION_ARG="" if [ -n "${EXTENSIONS_DIR}" ]; then EXTENSION_ARG="--extensions-dir=${EXTENSIONS_DIR}" + EXTENSIONS_DIR="${EXTENSIONS_DIR}" +else + EXTENSIONS_DIR="${INSTALL_PREFIX}/extensions" fi function run_code_server() { @@ -27,7 +30,9 @@ fi # Check if code-server is already installed for offline or cached mode if [ -f "$CODE_SERVER" ]; then - if [ "${OFFLINE}" = true ] || [ "${USE_CACHED}" = true ]; then + if [ "${USE_CACHED}" = true ] && [ ! -d "$EXTENSIONS_DIR" ]; then + echo "No extensions have been installed yet..." + elif [ "${OFFLINE}" = true ] || [ "${USE_CACHED}" = true ]; then echo "🥳 Found a copy of code-server" run_code_server exit 0 @@ -39,22 +44,25 @@ if [ "${OFFLINE}" = true ]; then exit 1 fi -printf "$${BOLD}Installing code-server!\n" +# If there is no cached install OR we don't want to use a cached install +if [ ! -f "$CODE_SERVER" ] || [ "${USE_CACHED}" != true ]; then + printf "$${BOLD}Installing code-server!\n" -ARGS=( - "--method=standalone" - "--prefix=${INSTALL_PREFIX}" -) -if [ -n "${VERSION}" ]; then - ARGS+=("--version=${VERSION}") -fi + 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 + 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 + fi + printf "🥳 code-server has been installed in ${INSTALL_PREFIX}\n\n" fi -printf "🥳 code-server has been installed in ${INSTALL_PREFIX}\n\n" # Install each extension... IFS=',' read -r -a EXTENSIONLIST <<< "$${EXTENSIONS}" From 1ea9771ae7d156ff63619f54f5412a04dde654ff Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Sat, 25 May 2024 11:21:06 -0700 Subject: [PATCH 02/12] fix(git-config): debug why tests fail --- git-config/main.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-config/main.test.ts b/git-config/main.test.ts index fe410aa3..2f050f66 100644 --- a/git-config/main.test.ts +++ b/git-config/main.test.ts @@ -20,12 +20,12 @@ describe("git-config", async () => { }); const resources = state.resources; - expect(resources).toHaveLength(3); expect(resources).toMatchObject([ { type: "coder_workspace", name: "me" }, { type: "coder_env", name: "git_author_name" }, { type: "coder_env", name: "git_commmiter_name" }, ]); + expect(resources).toHaveLength(3); }); it("can run apply allow_email_change enabled", async () => { @@ -35,7 +35,6 @@ describe("git-config", async () => { }); const resources = state.resources; - expect(resources).toHaveLength(5); expect(resources).toMatchObject([ { type: "coder_parameter", name: "user_email" }, { type: "coder_parameter", name: "username" }, @@ -43,6 +42,7 @@ describe("git-config", async () => { { type: "coder_env", name: "git_author_name" }, { type: "coder_env", name: "git_commmiter_name" }, ]); + expect(resources).toHaveLength(5); }); it("can run apply allow_email_change enabled", async () => { From fab10eb675ff7075c2969e6f04d3e5d2aa4a9b2d Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Sat, 25 May 2024 11:36:24 -0700 Subject: [PATCH 03/12] test(git-config): debug tests --- git-config/main.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-config/main.test.ts b/git-config/main.test.ts index 2f050f66..fe410aa3 100644 --- a/git-config/main.test.ts +++ b/git-config/main.test.ts @@ -20,12 +20,12 @@ describe("git-config", async () => { }); const resources = state.resources; + expect(resources).toHaveLength(3); expect(resources).toMatchObject([ { type: "coder_workspace", name: "me" }, { type: "coder_env", name: "git_author_name" }, { type: "coder_env", name: "git_commmiter_name" }, ]); - expect(resources).toHaveLength(3); }); it("can run apply allow_email_change enabled", async () => { @@ -35,6 +35,7 @@ describe("git-config", async () => { }); const resources = state.resources; + expect(resources).toHaveLength(5); expect(resources).toMatchObject([ { type: "coder_parameter", name: "user_email" }, { type: "coder_parameter", name: "username" }, @@ -42,7 +43,6 @@ describe("git-config", async () => { { type: "coder_env", name: "git_author_name" }, { type: "coder_env", name: "git_commmiter_name" }, ]); - expect(resources).toHaveLength(5); }); it("can run apply allow_email_change enabled", async () => { From 26a87282cfe15158dbfd81acc2c91fcad0d9ba8c Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Sat, 25 May 2024 11:48:15 -0700 Subject: [PATCH 04/12] test(git-config): use booleans --- bun.lockb | Bin 9456 -> 9792 bytes git-config/main.test.ts | 14 +++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/bun.lockb b/bun.lockb index d3e22141efbd6a38f0a17c4768e00326156a716d..0c42f3ce2a5974bff542fef12184d21d46efa4c4 100755 GIT binary patch delta 1672 zcmb_ceQZ-z6u(sa`8~CzrcAH`LH7FZ{F~&z2#BB;`4YirYZkiGU zTa*u{k+7Xeh(-krFk>Lgn#cwtA<+@1kmw|Y$bu$=KY)Z_Gy#Jyp7Yik`iDjnPjc?> zo%=iY+;i_c_uOqh*Ro%&D4LC~TmNh8?2?X+*MGR)Iqj&l9ZrPDrPud*&cAmea%!ZE z=^_udmkJ?yFdcbnTPoJu8;_;BH>VP@C}Uo9urk*Fy}+0YaT3vin25g|eIofHOBT%A z_Xcm4R+JkVD?}2NiHI4r35O9WNQH?p8`%)#O_rIis^k(K{Bb-Znq|B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allow_email_change disabled", async () => { - const state = await runTerraformApply(import.meta.dir, { - agent_id: "foo", - allow_username_change: "false", - allow_email_change: "false", - }); + const state = await runTerraformApply( + import.meta.dir, + { + agent_id: "foo", + allow_username_change: false, + allow_email_change: false, + }, + {}, + ); const resources = state.resources; expect(resources).toHaveLength(3); From d806b4eb756618e8b6d94a99da8bb18a6e2e0f7a Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Sat, 25 May 2024 11:51:39 -0700 Subject: [PATCH 05/12] test(git-config): check terraform version --- .github/workflows/ci.yaml | 1 + git-config/main.test.ts | 14 +++++--------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 960cd035..25ab8f6f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -21,6 +21,7 @@ jobs: with: bun-version: latest - name: Setup + run: terraform --version run: bun install - run: bun test pretty: diff --git a/git-config/main.test.ts b/git-config/main.test.ts index 8da34d0a..fe410aa3 100644 --- a/git-config/main.test.ts +++ b/git-config/main.test.ts @@ -13,15 +13,11 @@ describe("git-config", async () => { }); it("can run apply allow_username_change and allow_email_change disabled", async () => { - const state = await runTerraformApply( - import.meta.dir, - { - agent_id: "foo", - allow_username_change: false, - allow_email_change: false, - }, - {}, - ); + const state = await runTerraformApply(import.meta.dir, { + agent_id: "foo", + allow_username_change: "false", + allow_email_change: "false", + }); const resources = state.resources; expect(resources).toHaveLength(3); From d6a32b94661ec2c3ea3ef79065a3fa6ba44eb45f Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Sat, 25 May 2024 11:52:31 -0700 Subject: [PATCH 06/12] test(git-config): revert --- .github/workflows/ci.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 25ab8f6f..960cd035 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -21,7 +21,6 @@ jobs: with: bun-version: latest - name: Setup - run: terraform --version run: bun install - run: bun test pretty: From 84caaa1455a7219a770fa7dac7eb6399f255f6b8 Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Sat, 25 May 2024 12:06:07 -0700 Subject: [PATCH 07/12] chore(git-config): rollback --- bun.lockb | Bin 9792 -> 9456 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/bun.lockb b/bun.lockb index 0c42f3ce2a5974bff542fef12184d21d46efa4c4..d3e22141efbd6a38f0a17c4768e00326156a716d 100755 GIT binary patch delta 1478 zcmbtUUq}>T5dXe)*K^g|yYsZWJ@2$c3N0@$t4p$5Df=T?8W-4Am`5sET^-rOm6Q?| zQWVNS^pBvI$b!hMsGu~0Fwm&CM0$uIq6bYPD5|TOy)`=O&4KxT%>2HY*;(eBp_)(C zJ>H^%s`)J`rxq0EeX9=!W75jT?fu2 zdzzaVvm=qgSm#B7F)QL}L%OLv{VmL&lCTGRr}B#?MaI&RL}fB!yOh8vA|;tZ z%tVYrIbS=_&Fcj20#(#_Erdi(zJa;dA4F250-Xk`h$MvMcadSp%o^xmY=#}otO0l{Z{`e^rq|6F zS}hdSU~#}`GGznRN|a)Cz!7UwlpUVy)MKPdY)MoO9I{c=KAQvHBvTG3%BlgIunO*H z)mf(>q!|aoj57^S>@lblM0s~x$)Rv$FH;8k?LjHMlZFK4niGaR*$`BV;H4@mEdDDY z#La>$vR$Fcd2QTYtip9Qu#pCC7Aj3P{YNZBuU&r$X^8l!^`WE5rOiMSPOpL{n5LTs zwb7W)VMh8}_4<6?vUaHTsP2FHVysUxCBbEnQ%FGi2Y14|%Y*;9vW&6jwrKc3TQeJ3 z8F=`8?Y5yHJ|xQ1z=_0D$(kF{Exs>dVX%hOyje6O?;yOu2(;V~tC U&XY*HrEuV6UYRiPW%hdMH%(sa`8~CzrcAH`LH7FZ{F~&z2#BB;`4YirYZkiGU zTa*u{k+7Xeh(-krFk>Lgn#cwtA<+@1kmw|Y$bu$=KY)Z_Gy#Jyp7Yik`iDjnPjc?> zo%=iY+;i_c_uOqh*Ro%&D4LC~TmNh8?2?X+*MGR)Iqj&l9ZrPDrPud*&cAmea%!ZE z=^_udmkJ?yFdcbnTPoJu8;_;BH>VP@C}Uo9urk*Fy}+0YaT3vin25g|eIofHOBT%A z_Xcm4R+JkVD?}2NiHI4r35O9WNQH?p8`%)#O_rIis^k(K{Bb-Znq|B$=xucu!2uTqEYVh87NS!~BqEu?XeK3>zuS}V=$ zv$k)-gK{?KoI|8D=EU&h&j%8h_gNbQ&e2Odf7x^8%9~$%4>Ue_6>iN`dQWcY@m+oE zNa4X3KD<%-c*E|_YoA3QDIXh2-fZe`JCoS0P5#6oY?I&*YsB`@4k9$$T5#h#NS(0d zQC9d(r#`Yv&}q-3?C`0bR<$}LusiZ7Cv0*MHHXyMe98@?lcK+X?*aCyJbkw@U0n!JZ(cBR}uZ2Tmx8!h8-UWaBrGi zV8&zNjhP#sbw)TO1`E?vcPNKsSn7KkcKM3@()>7FjQ{5M#QjO8u!ur?W1{M9rY^8sxhZSjx+(n4V<&6}G0@EUD zN3;Riw22#)0@7on1ZV>aObL Date: Sat, 25 May 2024 12:14:25 -0700 Subject: [PATCH 08/12] chore(git-config): uuidv4 generator --- test.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test.ts b/test.ts index c2eb65ee..193bb043 100644 --- a/test.ts +++ b/test.ts @@ -2,6 +2,12 @@ import { readableStreamToText, spawn } from "bun"; import { afterEach, expect, it } from "bun:test"; import { readFile, unlink } from "fs/promises"; +function uuidv4() { + return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, c => + (+c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> +c / 4).toString(16) + ); +} + export const runContainer = async ( image: string, init = "sleep infinity", @@ -173,7 +179,7 @@ export const runTerraformApply = async ( vars: Record, env: Record = {}, ): Promise => { - const stateFile = `${dir}/${crypto.randomUUID()}.tfstate`; + const stateFile = `${dir}/${uuidv4()}.tfstate`; Object.keys(vars).forEach((key) => (env[`TF_VAR_${key}`] = vars[key])); const proc = spawn( [ From 1ed633f937896340f5f414e9071e74b4a1c42887 Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Sat, 25 May 2024 12:16:14 -0700 Subject: [PATCH 09/12] chore(git-config): revert --- test.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/test.ts b/test.ts index 193bb043..c2eb65ee 100644 --- a/test.ts +++ b/test.ts @@ -2,12 +2,6 @@ import { readableStreamToText, spawn } from "bun"; import { afterEach, expect, it } from "bun:test"; import { readFile, unlink } from "fs/promises"; -function uuidv4() { - return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, c => - (+c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> +c / 4).toString(16) - ); -} - export const runContainer = async ( image: string, init = "sleep infinity", @@ -179,7 +173,7 @@ export const runTerraformApply = async ( vars: Record, env: Record = {}, ): Promise => { - const stateFile = `${dir}/${uuidv4()}.tfstate`; + const stateFile = `${dir}/${crypto.randomUUID()}.tfstate`; Object.keys(vars).forEach((key) => (env[`TF_VAR_${key}`] = vars[key])); const proc = spawn( [ From 22e112db375e2a4c633e87d57b4755fac2188adb Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Wed, 29 May 2024 23:18:58 -0700 Subject: [PATCH 10/12] fix(code-server): install missing extensions --- code-server/run.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/code-server/run.sh b/code-server/run.sh index 8ef7763b..b69692ff 100755 --- a/code-server/run.sh +++ b/code-server/run.sh @@ -10,9 +10,6 @@ CODE_SERVER="${INSTALL_PREFIX}/bin/code-server" EXTENSION_ARG="" if [ -n "${EXTENSIONS_DIR}" ]; then EXTENSION_ARG="--extensions-dir=${EXTENSIONS_DIR}" - EXTENSIONS_DIR="${EXTENSIONS_DIR}" -else - EXTENSIONS_DIR="${INSTALL_PREFIX}/extensions" fi function run_code_server() { @@ -30,7 +27,7 @@ fi # Check if code-server is already installed for offline or cached mode if [ -f "$CODE_SERVER" ]; then - if [ "${USE_CACHED}" = true ] && [ ! -d "$EXTENSIONS_DIR" ]; then + if [ "${USE_CACHED}" = true ] && [ -n "${EXTENSIONS_DIR}" ] && [ ! -d "${EXTENSIONS_DIR}" ]; then echo "No extensions have been installed yet..." elif [ "${OFFLINE}" = true ] || [ "${USE_CACHED}" = true ]; then echo "🥳 Found a copy of code-server" From 3df1906aaf66e45c27d8ed94d8fe4d7649e5b724 Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Thu, 30 May 2024 08:13:23 -0700 Subject: [PATCH 11/12] feat(code-server): always install extensions --- code-server/run.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/code-server/run.sh b/code-server/run.sh index b69692ff..1022eb2e 100755 --- a/code-server/run.sh +++ b/code-server/run.sh @@ -29,6 +29,8 @@ fi if [ -f "$CODE_SERVER" ]; then if [ "${USE_CACHED}" = true ] && [ -n "${EXTENSIONS_DIR}" ] && [ ! -d "${EXTENSIONS_DIR}" ]; then echo "No extensions have been installed yet..." + elif [ "${USE_CACHED}" = true ] && [ -z "${EXTENSIONS_DIR}" ]; then + echo "Checking if extensions needs to be installed..." elif [ "${OFFLINE}" = true ] || [ "${USE_CACHED}" = true ]; then echo "🥳 Found a copy of code-server" run_code_server From 1f6a620d651c5d4ac57fb3f051b5711de5b4291f Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Thu, 30 May 2024 23:15:34 -0700 Subject: [PATCH 12/12] feat(code-server): always try to install extensions --- code-server/run.sh | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/code-server/run.sh b/code-server/run.sh index 1022eb2e..c89502b5 100755 --- a/code-server/run.sh +++ b/code-server/run.sh @@ -25,20 +25,14 @@ if [ ! -f ~/.local/share/code-server/User/settings.json ]; then echo "${SETTINGS}" > ~/.local/share/code-server/User/settings.json fi -# Check if code-server is already installed for offline or cached mode -if [ -f "$CODE_SERVER" ]; then - if [ "${USE_CACHED}" = true ] && [ -n "${EXTENSIONS_DIR}" ] && [ ! -d "${EXTENSIONS_DIR}" ]; then - echo "No extensions have been installed yet..." - elif [ "${USE_CACHED}" = true ] && [ -z "${EXTENSIONS_DIR}" ]; then - echo "Checking if extensions needs to be installed..." - elif [ "${OFFLINE}" = true ] || [ "${USE_CACHED}" = true ]; then +# Check if code-server is already installed for offline +if [ "${OFFLINE}" = true ]; then + if [ -f "$CODE_SERVER" ]; 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 + # Offline mode always expects a copy of code-server to be present echo "Failed to find a copy of code-server" exit 1 fi