From 18efe83b89875e9b286b74891031e26473114ca3 Mon Sep 17 00:00:00 2001 From: timquinlan Date: Thu, 25 Apr 2024 13:17:08 +0000 Subject: [PATCH 1/6] corrected path in README.md to point to modules/apache-airflow --- apache-airflow/README.md | 11 +- package-lock.json | 263 +++++++++++++++++++++++++++++++++++++++ package.json | 3 +- 3 files changed, 271 insertions(+), 6 deletions(-) create mode 100644 package-lock.json diff --git a/apache-airflow/README.md b/apache-airflow/README.md index ae8a278..3d43147 100644 --- a/apache-airflow/README.md +++ b/apache-airflow/README.md @@ -13,8 +13,9 @@ A module that adds Apache Airflow in your Coder template. ```tf module "airflow" { - source = "registry.coder.com/modules/airflow/coder" - version = "1.0.2" + source = "registry.coder.com/modules/apache-airflow/coder" + version = "1.0.2" + agent_id = coder_agent.example.id } ``` @@ -28,7 +29,7 @@ Install the Dracula theme from [OpenVSX](https://open-vsx.org/): ```tf module "airflow" { - source = "registry.coder.com/modules/airflow/coder" + source = "registry.coder.com/modules/apache-airflow/coder" version = "1.0.2" agent_id = coder_agent.example.id extensions = [ @@ -45,7 +46,7 @@ Configure VS Code's [settings.json](https://code.visualstudio.com/docs/getstarte ```tf module "airflow" { - source = "registry.coder.com/modules/airflow/coder" + source = "registry.coder.com/modules/apache-airflow/coder" version = "1.0.2" agent_id = coder_agent.example.id extensions = ["dracula-theme.theme-dracula"] @@ -61,7 +62,7 @@ Run code-server in the background, don't fetch it from GitHub: ```tf module "airflow" { - source = "registry.coder.com/modules/airflow/coder" + source = "registry.coder.com/modules/apache-airflow/coder" version = "1.0.2" agent_id = coder_agent.example.id offline = true diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..8039c1c --- /dev/null +++ b/package-lock.json @@ -0,0 +1,263 @@ +{ + "name": "modules", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "modules", + "devDependencies": { + "bun-types": "^1.0.18", + "gray-matter": "^4.0.3", + "marked": "^12.0.0", + "prettier": "^3.2.5", + "prettier-plugin-sh": "^0.13.1", + "prettier-plugin-terraform-formatter": "^1.2.1" + }, + "peerDependencies": { + "typescript": "^5.3.3" + } + }, + "node_modules/@types/node": { + "version": "20.11.30", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.30.tgz", + "integrity": "sha512-dHM6ZxwlmuZaRmUPfv1p+KrdD1Dci04FbdEm/9wEMouFqxYoFl5aMkt0VMAUtYRQDyYvD41WJLukhq/ha3YuTw==", + "dev": true, + "dependencies": { + "undici-types": "~5.26.4" + } + }, + "node_modules/@types/ws": { + "version": "8.5.10", + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.10.tgz", + "integrity": "sha512-vmQSUcfalpIq0R9q7uTo2lXs6eGIpt9wtnLdMv9LVpIjCA/+ufZRozlVoVelIYixx1ugCBKDhn89vnsEGOCx9A==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/argparse": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", + "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "dev": true, + "dependencies": { + "sprintf-js": "~1.0.2" + } + }, + "node_modules/bun-types": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/bun-types/-/bun-types-1.1.4.tgz", + "integrity": "sha512-E1kk0FNpxpkSSlCVXEa4HfyhSUEpKtCFrybPVyz1A4TEnBGy5bqqtSYkyjKTfKScdyZTBeFrTxJLiKGOIRWgwg==", + "dev": true, + "dependencies": { + "@types/node": "~20.11.3", + "@types/ws": "~8.5.10" + } + }, + "node_modules/esprima": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", + "dev": true, + "bin": { + "esparse": "bin/esparse.js", + "esvalidate": "bin/esvalidate.js" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/extend-shallow": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz", + "integrity": "sha512-zCnTtlxNoAiDc3gqY2aYAWFx7XWWiasuF2K8Me5WbN8otHKTUKBwjPtNpRs/rbUZm7KxWAaNj7P1a/p52GbVug==", + "dev": true, + "dependencies": { + "is-extendable": "^0.1.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/gray-matter": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/gray-matter/-/gray-matter-4.0.3.tgz", + "integrity": "sha512-5v6yZd4JK3eMI3FqqCouswVqwugaA9r4dNZB1wwcmrD02QkV5H0y7XBQW8QwQqEaZY1pM9aqORSORhJRdNK44Q==", + "dev": true, + "dependencies": { + "js-yaml": "^3.13.1", + "kind-of": "^6.0.2", + "section-matter": "^1.0.0", + "strip-bom-string": "^1.0.0" + }, + "engines": { + "node": ">=6.0" + } + }, + "node_modules/is-extendable": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/is-extendable/-/is-extendable-0.1.1.tgz", + "integrity": "sha512-5BMULNob1vgFX6EjQw5izWDxrecWK9AM72rugNr0TFldMOi0fj6Jk+zeKIt0xGj4cEfQIJth4w3OKWOJ4f+AFw==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/js-yaml": { + "version": "3.14.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", + "integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==", + "dev": true, + "dependencies": { + "argparse": "^1.0.7", + "esprima": "^4.0.0" + }, + "bin": { + "js-yaml": "bin/js-yaml.js" + } + }, + "node_modules/kind-of": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", + "integrity": "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/marked": { + "version": "12.0.2", + "resolved": "https://registry.npmjs.org/marked/-/marked-12.0.2.tgz", + "integrity": "sha512-qXUm7e/YKFoqFPYPa3Ukg9xlI5cyAtGmyEIzMfW//m6kXwCy2Ps9DYf5ioijFKQ8qyuscrHoY04iJGctu2Kg0Q==", + "dev": true, + "bin": { + "marked": "bin/marked.js" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/mvdan-sh": { + "version": "0.10.1", + "resolved": "https://registry.npmjs.org/mvdan-sh/-/mvdan-sh-0.10.1.tgz", + "integrity": "sha512-kMbrH0EObaKmK3nVRKUIIya1dpASHIEusM13S4V1ViHFuxuNxCo+arxoa6j/dbV22YBGjl7UKJm9QQKJ2Crzhg==", + "dev": true + }, + "node_modules/prettier": { + "version": "3.2.5", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.2.5.tgz", + "integrity": "sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==", + "dev": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, + "node_modules/prettier-plugin-sh": { + "version": "0.13.1", + "resolved": "https://registry.npmjs.org/prettier-plugin-sh/-/prettier-plugin-sh-0.13.1.tgz", + "integrity": "sha512-ytMcl1qK4s4BOFGvsc9b0+k9dYECal7U29bL/ke08FEUsF/JLN0j6Peo0wUkFDG4y2UHLMhvpyd6Sd3zDXe/eg==", + "dev": true, + "dependencies": { + "mvdan-sh": "^0.10.1", + "sh-syntax": "^0.4.1" + }, + "engines": { + "node": ">=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/unts" + }, + "peerDependencies": { + "prettier": "^3.0.0" + } + }, + "node_modules/prettier-plugin-terraform-formatter": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/prettier-plugin-terraform-formatter/-/prettier-plugin-terraform-formatter-1.2.1.tgz", + "integrity": "sha512-rdzV61Bs/Ecnn7uAS/vL5usTX8xUWM+nQejNLZxt3I1kJH5WSeLEmq7LYu1wCoEQF+y7Uv1xGvPRfl3lIe6+tA==", + "dev": true, + "peerDependencies": { + "prettier": ">= 1.16.0" + }, + "peerDependenciesMeta": { + "prettier": { + "optional": true + } + } + }, + "node_modules/section-matter": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/section-matter/-/section-matter-1.0.0.tgz", + "integrity": "sha512-vfD3pmTzGpufjScBh50YHKzEu2lxBWhVEHsNGoEXmCmn2hKGfeNLYMzCJpe8cD7gqX7TJluOVpBkAequ6dgMmA==", + "dev": true, + "dependencies": { + "extend-shallow": "^2.0.1", + "kind-of": "^6.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/sh-syntax": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/sh-syntax/-/sh-syntax-0.4.2.tgz", + "integrity": "sha512-/l2UZ5fhGZLVZa16XQM9/Vq/hezGGbdHeVEA01uWjOL1+7Ek/gt6FquW0iKKws4a9AYPYvlz6RyVvjh3JxOteg==", + "dev": true, + "dependencies": { + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/unts" + } + }, + "node_modules/sprintf-js": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", + "integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==", + "dev": true + }, + "node_modules/strip-bom-string": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/strip-bom-string/-/strip-bom-string-1.0.0.tgz", + "integrity": "sha512-uCC2VHvQRYu+lMh4My/sFNmF2klFymLX1wHJeXnbEJERpV/ZsVuonzerjfrGpIGF7LBVa1O7i9kjiWvJiFck8g==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/tslib": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==", + "dev": true + }, + "node_modules/typescript": { + "version": "5.4.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", + "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==", + "peer": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true + } + } +} diff --git a/package.json b/package.json index 5a73d51..f3136b1 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "bun-types": "^1.0.18", "gray-matter": "^4.0.3", "marked": "^12.0.0", + "prettier": "^3.2.5", "prettier-plugin-sh": "^0.13.1", "prettier-plugin-terraform-formatter": "^1.2.1" }, @@ -23,4 +24,4 @@ "prettier-plugin-terraform-formatter" ] } -} \ No newline at end of file +} From fd985bedac27480caff69cdf77a47765eb2fb582 Mon Sep 17 00:00:00 2001 From: timquinlan Date: Thu, 25 Apr 2024 15:25:12 +0000 Subject: [PATCH 2/6] changed maintainer_github to coder, added partner_github: nataindata --- apache-airflow/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apache-airflow/README.md b/apache-airflow/README.md index 3d43147..65f808f 100644 --- a/apache-airflow/README.md +++ b/apache-airflow/README.md @@ -2,8 +2,9 @@ display_name: airflow description: A module that adds Apache Airflow in your Coder template icon: ../.icons/airflow.svg -maintainer_github: nataindata -verified: false +maintainer_github: coder +partner_github: nataindata +verified: true tags: [airflow, idea, web, helper] --- From c50c4259d990e2c39effc490adbf961f3901a2aa Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 25 Apr 2024 18:53:46 +0300 Subject: [PATCH 3/6] chore: bump version to 1.0.13 in README.md files (#238) Co-authored-by: matifali --- apache-airflow/README.md | 8 ++++---- jetbrains-gateway/README.md | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/apache-airflow/README.md b/apache-airflow/README.md index 65f808f..0483c9c 100644 --- a/apache-airflow/README.md +++ b/apache-airflow/README.md @@ -15,7 +15,7 @@ A module that adds Apache Airflow in your Coder template. ```tf module "airflow" { source = "registry.coder.com/modules/apache-airflow/coder" - version = "1.0.2" + version = "1.0.13" agent_id = coder_agent.example.id } ``` @@ -31,7 +31,7 @@ Install the Dracula theme from [OpenVSX](https://open-vsx.org/): ```tf module "airflow" { source = "registry.coder.com/modules/apache-airflow/coder" - version = "1.0.2" + version = "1.0.13" agent_id = coder_agent.example.id extensions = [ "dracula-theme.theme-dracula" @@ -48,7 +48,7 @@ Configure VS Code's [settings.json](https://code.visualstudio.com/docs/getstarte ```tf module "airflow" { source = "registry.coder.com/modules/apache-airflow/coder" - version = "1.0.2" + version = "1.0.13" agent_id = coder_agent.example.id extensions = ["dracula-theme.theme-dracula"] settings = { @@ -64,7 +64,7 @@ Run code-server in the background, don't fetch it from GitHub: ```tf module "airflow" { source = "registry.coder.com/modules/apache-airflow/coder" - version = "1.0.2" + version = "1.0.13" agent_id = coder_agent.example.id offline = true } diff --git a/jetbrains-gateway/README.md b/jetbrains-gateway/README.md index 03feae1..b2c0e0f 100644 --- a/jetbrains-gateway/README.md +++ b/jetbrains-gateway/README.md @@ -14,7 +14,7 @@ This module adds a JetBrains Gateway Button to open any workspace with a single ```tf module "jetbrains_gateway" { source = "registry.coder.com/modules/jetbrains-gateway/coder" - version = "1.0.12" + version = "1.0.13" agent_id = coder_agent.example.id agent_name = "example" folder = "/home/coder/example" @@ -32,7 +32,7 @@ module "jetbrains_gateway" { ```tf module "jetbrains_gateway" { source = "registry.coder.com/modules/jetbrains-gateway/coder" - version = "1.0.12" + version = "1.0.13" agent_id = coder_agent.example.id agent_name = "example" folder = "/home/coder/example" @@ -46,7 +46,7 @@ module "jetbrains_gateway" { ```tf module "jetbrains_gateway" { source = "registry.coder.com/modules/jetbrains-gateway/coder" - version = "1.0.12" + version = "1.0.13" agent_id = coder_agent.example.id agent_name = "example" folder = "/home/coder/example" @@ -61,7 +61,7 @@ module "jetbrains_gateway" { ```tf module "jetbrains_gateway" { source = "registry.coder.com/modules/jetbrains-gateway/coder" - version = "1.0.12" + version = "1.0.13" agent_id = coder_agent.example.id agent_name = "example" folder = "/home/coder/example" From b0d6224e236cc7576c65c6e0621ff1d929147a70 Mon Sep 17 00:00:00 2001 From: timquinlan Date: Fri, 26 Apr 2024 14:25:53 +0000 Subject: [PATCH 4/6] cleaned up apache-airflow readme --- apache-airflow/README.md | 48 ---------------------------------------- 1 file changed, 48 deletions(-) diff --git a/apache-airflow/README.md b/apache-airflow/README.md index 0483c9c..bf8e315 100644 --- a/apache-airflow/README.md +++ b/apache-airflow/README.md @@ -21,51 +21,3 @@ module "airflow" { ``` ![Airflow](../.images/airflow.png) - -## Examples - -### Example 1 - -Install the Dracula theme from [OpenVSX](https://open-vsx.org/): - -```tf -module "airflow" { - source = "registry.coder.com/modules/apache-airflow/coder" - version = "1.0.13" - agent_id = coder_agent.example.id - extensions = [ - "dracula-theme.theme-dracula" - ] -} -``` - -Enter the `.` into the extensions array and code-server will automatically install on start. - -### Example 2 - -Configure VS Code's [settings.json](https://code.visualstudio.com/docs/getstarted/settings#_settingsjson) file: - -```tf -module "airflow" { - source = "registry.coder.com/modules/apache-airflow/coder" - version = "1.0.13" - agent_id = coder_agent.example.id - extensions = ["dracula-theme.theme-dracula"] - settings = { - "workbench.colorTheme" = "Dracula" - } -} -``` - -### Example 3 - -Run code-server in the background, don't fetch it from GitHub: - -```tf -module "airflow" { - source = "registry.coder.com/modules/apache-airflow/coder" - version = "1.0.13" - agent_id = coder_agent.example.id - offline = true -} -``` From b686f2dbd569a45ca8aaf5770a5a3cd30d6198d0 Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Fri, 26 Apr 2024 07:56:50 -0700 Subject: [PATCH 5/6] feat(code-server): install extensions from `.vscode/extensions.json` (#231) --- code-server/main.tf | 8 ++++++++ code-server/run.sh | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/code-server/main.tf b/code-server/main.tf index 8c0f1e0..c186c14 100644 --- a/code-server/main.tf +++ b/code-server/main.tf @@ -101,6 +101,12 @@ variable "extensions_dir" { default = "" } +variable "auto_install_extensions" { + type = bool + description = "Automatically install recommended extensions when code-server starts." + default = false +} + resource "coder_script" "code-server" { agent_id = var.agent_id display_name = "code-server" @@ -117,6 +123,8 @@ resource "coder_script" "code-server" { OFFLINE : var.offline, USE_CACHED : var.use_cached, EXTENSIONS_DIR : var.extensions_dir, + FOLDER : var.folder, + AUTO_INSTALL_EXTENSIONS : var.auto_install_extensions, }) run_on_start = true diff --git a/code-server/run.sh b/code-server/run.sh index b04e131..26a1c6e 100755 --- a/code-server/run.sh +++ b/code-server/run.sh @@ -70,4 +70,24 @@ for extension in "$${EXTENSIONLIST[@]}"; do fi done +if [ "${AUTO_INSTALL_EXTENSIONS}" = true ]; then + if ! command -v jq > /dev/null; then + echo "jq is required to install extensions from a workspace file." + exit 0 + fi + + WORKSPACE_DIR="$HOME" + if [ -n "${FOLDER}" ]; then + WORKSPACE_DIR="${FOLDER}" + fi + + if [ -f "$WORKSPACE_DIR/.vscode/extensions.json" ]; then + printf "🧩 Installing extensions from %s/.vscode/extensions.json...\n" "$WORKSPACE_DIR" + extensions=$(jq -r '.recommendations[]' "$WORKSPACE_DIR"/.vscode/extensions.json) + for extension in $extensions; do + $CODE_SERVER "$EXTENSION_ARG" --install-extension "$extension" + done + fi +fi + run_code_server From 443485a2d707e1ae9f906850f00af23b9dd6e4ad Mon Sep 17 00:00:00 2001 From: Phorcys <57866459+phorcys420@users.noreply.github.com> Date: Fri, 26 Apr 2024 16:57:12 +0200 Subject: [PATCH 6/6] feat(dotfiles): add ability to apply dotfiles as any user (#133) Co-authored-by: Mathias Fredriksson Co-authored-by: Muhammad Atif Ali --- dotfiles/README.md | 47 +++++++++++++++++++++++++++++++++++++++++++++- dotfiles/main.tf | 38 +++++++++++++++++++++++++++---------- dotfiles/run.sh | 23 +++++++++++++++++++++++ 3 files changed, 97 insertions(+), 11 deletions(-) create mode 100644 dotfiles/run.sh diff --git a/dotfiles/README.md b/dotfiles/README.md index 435d366..be174c2 100644 --- a/dotfiles/README.md +++ b/dotfiles/README.md @@ -9,7 +9,11 @@ tags: [helper] # Dotfiles -Allow developers to optionally bring their own [dotfiles repository](https://dotfiles.github.io)! Under the hood, this module uses the [coder dotfiles](https://coder.com/docs/v2/latest/dotfiles) command. +Allow developers to optionally bring their own [dotfiles repository](https://dotfiles.github.io). + +This will prompt the user for their dotfiles repository URL on template creation using a `coder_parameter`. + +Under the hood, this module uses the [coder dotfiles](https://coder.com/docs/v2/latest/dotfiles) command. ```tf module "dotfiles" { @@ -19,6 +23,47 @@ module "dotfiles" { } ``` +## Examples + +### Apply dotfiles as the current user + +```tf +module "dotfiles" { + source = "registry.coder.com/modules/dotfiles/coder" + version = "1.0.0" + agent_id = coder_agent.example.id +} +``` + +### Apply dotfiles as another user (only works if sudo is passwordless) + +```tf +module "dotfiles" { + source = "registry.coder.com/modules/dotfiles/coder" + version = "1.0.0" + agent_id = coder_agent.example.id + user = "root" +} +``` + +### Apply the same dotfiles as the current user and root (the root dotfiles can only be applied if sudo is passwordless) + +```tf +module "dotfiles" { + source = "registry.coder.com/modules/dotfiles/coder" + version = "1.0.0" + agent_id = coder_agent.example.id +} + +module "dotfiles-root" { + source = "registry.coder.com/modules/dotfiles/coder" + version = "1.0.0" + agent_id = coder_agent.example.id + user = "root" + dotfiles_uri = module.dotfiles.dotfiles_uri +} +``` + ## Setting a default dotfiles repository You can set a default dotfiles repository for all users by setting the `default_dotfiles_uri` variable: diff --git a/dotfiles/main.tf b/dotfiles/main.tf index ac7f7e6..950cb9b 100644 --- a/dotfiles/main.tf +++ b/dotfiles/main.tf @@ -16,10 +16,23 @@ variable "agent_id" { variable "default_dotfiles_uri" { type = string - description = "The default dotfiles URI if the workspace user does not provide one." + description = "The default dotfiles URI if the workspace user does not provide one" default = "" } +variable "dotfiles_uri" { + type = string + description = "The URL to a dotfiles repository. (optional, when set, the user isn't prompted for their dotfiles)" + + default = null +} + +variable "user" { + type = string + description = "The name of the user to apply the dotfiles to. (optional, applies to the current user by default)" + default = null +} + variable "coder_parameter_order" { type = number description = "The order determines the position of a template parameter in the UI/CLI presentation. The lowest order is shown first and parameters with equal order are sorted by name (ascending order)." @@ -27,6 +40,8 @@ variable "coder_parameter_order" { } data "coder_parameter" "dotfiles_uri" { + count = var.dotfiles_uri == null ? 1 : 0 + type = "string" name = "dotfiles_uri" display_name = "Dotfiles URL (optional)" @@ -37,14 +52,17 @@ data "coder_parameter" "dotfiles_uri" { icon = "/icon/dotfiles.svg" } -resource "coder_script" "personalize" { - agent_id = var.agent_id - script = <<-EOT - DOTFILES_URI="${data.coder_parameter.dotfiles_uri.value}" - if [ -n "$${DOTFILES_URI// }" ]; then - coder dotfiles "$DOTFILES_URI" -y 2>&1 | tee -a ~/.dotfiles.log - fi - EOT +locals { + dotfiles_uri = var.dotfiles_uri != null ? var.dotfiles_uri : data.coder_parameter.dotfiles_uri[0].value + user = var.user != null ? var.user : "" +} + +resource "coder_script" "dotfiles" { + agent_id = var.agent_id + script = templatefile("${path.module}/run.sh", { + DOTFILES_URI : local.dotfiles_uri, + DOTFILES_USER : local.user + }) display_name = "Dotfiles" icon = "/icon/dotfiles.svg" run_on_start = true @@ -52,5 +70,5 @@ resource "coder_script" "personalize" { output "dotfiles_uri" { description = "Dotfiles URI" - value = data.coder_parameter.dotfiles_uri.value + value = local.dotfiles_uri } diff --git a/dotfiles/run.sh b/dotfiles/run.sh new file mode 100644 index 0000000..9463439 --- /dev/null +++ b/dotfiles/run.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +DOTFILES_URI="${DOTFILES_URI}" +DOTFILES_USER="${DOTFILES_USER}" + +if [ -n "$${DOTFILES_URI// }" ]; then + if [ -z "$DOTFILES_USER" ]; then + DOTFILES_USER="$USER" + fi + + echo "✨ Applying dotfiles for user $DOTFILES_USER" + + if [ "$DOTFILES_USER" = "$USER" ]; then + coder dotfiles "$DOTFILES_URI" -y 2>&1 | tee ~/.dotfiles.log + else + # The `eval echo ~"$DOTFILES_USER"` part is used to dynamically get the home directory of the user, see https://superuser.com/a/484280 + # eval echo ~coder -> "/home/coder" + # eval echo ~root -> "/root" + + CODER_BIN=$(which coder) + DOTFILES_USER_HOME=$(eval echo ~"$DOTFILES_USER") + sudo -u "$DOTFILES_USER" sh -c "'$CODER_BIN' dotfiles '$DOTFILES_URI' -y 2>&1 | tee '$DOTFILES_USER_HOME'/.dotfiles.log" + fi +fi