mirror of
https://github.com/coder/registry.git
synced 2026-06-03 04:58:15 +00:00
Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 443db3b7dc | |||
| 057d40554b | |||
| 0d73bb6588 | |||
| 2932fb482b | |||
| 6ce61c9acd | |||
| 6677432df7 | |||
| 142167f9c0 | |||
| 798cb1d79c | |||
| 74c8698566 | |||
| 03333991a4 | |||
| 2b0dba4ed1 | |||
| 57c900b2c9 | |||
| 0ccee61192 | |||
| 494dc4b8a1 | |||
| 3b135ad4a4 | |||
| 258591833f | |||
| 3efc22c589 | |||
| 8ba4c323c2 | |||
| 3afa72095b | |||
| cf66809349 | |||
| 020a2cba79 | |||
| 3fd7b47097 | |||
| e1f077dac3 | |||
| 29c52b7072 | |||
| 312cb71bf0 |
@@ -1,6 +1,9 @@
|
||||
name: deploy-registry
|
||||
|
||||
on:
|
||||
schedule:
|
||||
# Runs at 02:30 UTC Monday through Friday
|
||||
- cron: "30 2 * * 1-5"
|
||||
push:
|
||||
tags:
|
||||
# Matches release/<namespace>/<resource_name>/<semantic_version>
|
||||
@@ -26,7 +29,7 @@ jobs:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
- name: Authenticate with Google Cloud
|
||||
uses: google-github-actions/auth@140bb5113ffb6b65a7e9b937a81fa96cf5064462
|
||||
uses: google-github-actions/auth@b7593ed2efd1c1617e1b0254da33b86225adb2a5
|
||||
with:
|
||||
workload_identity_provider: projects/309789351055/locations/global/workloadIdentityPools/github-actions/providers/github
|
||||
service_account: registry-v2-github@coder-registry-1.iam.gserviceaccount.com
|
||||
|
||||
+50
-4
@@ -42,12 +42,58 @@ go build ./cmd/readmevalidation && ./readmevalidation
|
||||
|
||||
## Making a Release
|
||||
|
||||
### Create Release Tags
|
||||
### Automated Tag and Release Process
|
||||
|
||||
After merging a PR:
|
||||
After merging a PR, use the automated script to create and push release tags:
|
||||
|
||||
1. Get the new version from the PR (shown as `old → new`)
|
||||
2. Checkout the merge commit and create the tag:
|
||||
**Prerequisites:**
|
||||
|
||||
- Ensure all module versions are updated in their respective README files (the script uses this as the source of truth)
|
||||
- Make sure you have the necessary permissions to push tags to the repository
|
||||
|
||||
**Steps:**
|
||||
|
||||
1. **Checkout the merge commit:**
|
||||
|
||||
```bash
|
||||
git checkout MERGE_COMMIT_ID
|
||||
```
|
||||
|
||||
2. **Run the tag release script:**
|
||||
|
||||
```bash
|
||||
./scripts/tag_release.sh
|
||||
```
|
||||
|
||||
3. **Review and confirm:**
|
||||
- The script will automatically scan all modules in the registry
|
||||
- It will detect which modules need version bumps by comparing README versions to existing tags
|
||||
- A summary will be displayed showing which modules need tagging
|
||||
- Confirm the list is correct when prompted
|
||||
|
||||
4. **Automatic tagging:**
|
||||
- After confirmation, the script will automatically create all necessary release tags
|
||||
- Tags will be pushed to the remote repository
|
||||
- The script operates on the current checked-out commit
|
||||
|
||||
**Example output:**
|
||||
|
||||
```text
|
||||
🔍 Scanning all modules for missing release tags...
|
||||
|
||||
📦 coder/code-server: v4.1.2 (needs tag)
|
||||
✅ coder/dotfiles: v1.0.5 (already tagged)
|
||||
|
||||
## Tags to be created:
|
||||
- `release/coder/code-server/v4.1.2`
|
||||
|
||||
❓ Do you want to proceed with creating and pushing these release tags?
|
||||
Continue? [y/N]: y
|
||||
```
|
||||
|
||||
### Manual Process (Fallback)
|
||||
|
||||
If the automated script fails, you can manually tag and release modules:
|
||||
|
||||
```bash
|
||||
# Checkout the merge commit
|
||||
|
||||
@@ -118,7 +118,6 @@ data "coder_workspace_preset" "default" {
|
||||
EOT
|
||||
"preview_port" = "4200"
|
||||
"container_image" = "codercom/example-universal:ubuntu"
|
||||
"jetbrains_ide" = "PY"
|
||||
}
|
||||
|
||||
# Pre-builds is a Coder Premium
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
---
|
||||
display_name: AgentAPI
|
||||
description: Building block for modules that need to run an agentapi server
|
||||
description: Building block for modules that need to run an AgentAPI server
|
||||
icon: ../../../../.icons/coder.svg
|
||||
verified: true
|
||||
tags: [internal]
|
||||
tags: [internal, library]
|
||||
---
|
||||
|
||||
# AgentAPI
|
||||
|
||||
The AgentAPI module is a building block for modules that need to run an agentapi server. It is intended primarily for internal use by Coder to create modules compatible with Tasks.
|
||||
> [!CAUTION]
|
||||
> We do not recommend using this module directly. Instead, please consider using one of our [Tasks-compatible AI agent modules](https://registry.coder.com/modules?search=tag%3Atasks).
|
||||
|
||||
We do not recommend using this module directly. Instead, please consider using one of our [Tasks-compatible AI agent modules](https://registry.coder.com/modules?search=tag%3Atasks).
|
||||
The AgentAPI module is a building block for modules that need to run an AgentAPI server. It is intended primarily for internal use by Coder to create modules compatible with Tasks.
|
||||
|
||||
```tf
|
||||
module "agentapi" {
|
||||
source = "registry.coder.com/coder/agentapi/coder"
|
||||
version = "1.0.1"
|
||||
version = "1.1.0"
|
||||
|
||||
agent_id = var.agent_id
|
||||
web_app_slug = local.app_slug
|
||||
@@ -50,4 +51,4 @@ module "agentapi" {
|
||||
|
||||
## For module developers
|
||||
|
||||
For a complete example of how to use this module, see the [goose module](https://github.com/coder/registry/blob/main/registry/coder/modules/goose/main.tf).
|
||||
For a complete example of how to use this module, see the [Goose module](https://github.com/coder/registry/blob/main/registry/coder/modules/goose/main.tf).
|
||||
|
||||
@@ -148,4 +148,92 @@ describe("agentapi", async () => {
|
||||
]);
|
||||
expect(respAgentAPI.exitCode).toBe(0);
|
||||
});
|
||||
|
||||
test("no-subdomain-base-path", async () => {
|
||||
const { id } = await setup({
|
||||
moduleVariables: {
|
||||
agentapi_subdomain: "false",
|
||||
},
|
||||
});
|
||||
|
||||
const respModuleScript = await execModuleScript(id);
|
||||
expect(respModuleScript.exitCode).toBe(0);
|
||||
|
||||
await expectAgentAPIStarted(id);
|
||||
const agentApiStartLog = await readFileContainer(
|
||||
id,
|
||||
"/home/coder/test-agentapi-start.log",
|
||||
);
|
||||
expect(agentApiStartLog).toContain("Using AGENTAPI_CHAT_BASE_PATH: /@default/default.foo/apps/agentapi-web/chat");
|
||||
});
|
||||
|
||||
test("validate-agentapi-version", async () => {
|
||||
const cases = [
|
||||
{
|
||||
moduleVariables: {
|
||||
agentapi_version: "v0.3.2",
|
||||
},
|
||||
shouldThrow: "",
|
||||
},
|
||||
{
|
||||
moduleVariables: {
|
||||
agentapi_version: "v0.3.3",
|
||||
},
|
||||
shouldThrow: "",
|
||||
},
|
||||
{
|
||||
moduleVariables: {
|
||||
agentapi_version: "v0.0.1",
|
||||
agentapi_subdomain: "false",
|
||||
},
|
||||
shouldThrow: "Running with subdomain = false is only supported by agentapi >= v0.3.3.",
|
||||
},
|
||||
{
|
||||
moduleVariables: {
|
||||
agentapi_version: "v0.3.2",
|
||||
agentapi_subdomain: "false",
|
||||
},
|
||||
shouldThrow: "Running with subdomain = false is only supported by agentapi >= v0.3.3.",
|
||||
},
|
||||
{
|
||||
moduleVariables: {
|
||||
agentapi_version: "v0.3.3",
|
||||
agentapi_subdomain: "false",
|
||||
},
|
||||
shouldThrow: "",
|
||||
},
|
||||
{
|
||||
moduleVariables: {
|
||||
agentapi_version: "v0.3.999",
|
||||
agentapi_subdomain: "false",
|
||||
},
|
||||
shouldThrow: "",
|
||||
},
|
||||
{
|
||||
moduleVariables: {
|
||||
agentapi_version: "v0.999.999",
|
||||
agentapi_subdomain: "false",
|
||||
},
|
||||
},
|
||||
{
|
||||
moduleVariables: {
|
||||
agentapi_version: "v999.999.999",
|
||||
agentapi_subdomain: "false",
|
||||
},
|
||||
},
|
||||
{
|
||||
moduleVariables: {
|
||||
agentapi_version: "arbitrary-string-bypasses-validation",
|
||||
},
|
||||
shouldThrow: "",
|
||||
}
|
||||
];
|
||||
for (const { moduleVariables, shouldThrow } of cases) {
|
||||
if (shouldThrow) {
|
||||
expect(setup({ moduleVariables: moduleVariables as Record<string, string> })).rejects.toThrow(shouldThrow);
|
||||
} else {
|
||||
expect(setup({ moduleVariables: moduleVariables as Record<string, string> })).resolves.toBeDefined();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -117,7 +117,7 @@ variable "install_agentapi" {
|
||||
variable "agentapi_version" {
|
||||
type = string
|
||||
description = "The version of AgentAPI to install."
|
||||
default = "v0.2.3"
|
||||
default = "v0.3.3"
|
||||
}
|
||||
|
||||
variable "agentapi_port" {
|
||||
@@ -126,6 +126,31 @@ variable "agentapi_port" {
|
||||
default = 3284
|
||||
}
|
||||
|
||||
locals {
|
||||
# agentapi_subdomain_false_min_version_expr matches a semantic version >= v0.3.3.
|
||||
# Initial support was added in v0.3.1 but configuration via environment variable
|
||||
# was added in v0.3.3.
|
||||
# This is unfortunately a regex because there is no builtin way to compare semantic versions in Terraform.
|
||||
# See: https://regex101.com/r/oHPyRa/1
|
||||
agentapi_subdomain_false_min_version_expr = "^v(0\\.(3\\.[3-9]|3.[1-9]\\d+|[4-9]\\.\\d+|[1-9]\\d+\\.\\d+)|[1-9]\\d*\\.\\d+\\.\\d+)$"
|
||||
}
|
||||
|
||||
variable "agentapi_subdomain" {
|
||||
type = bool
|
||||
description = "Whether to use a subdomain for AgentAPI."
|
||||
default = true
|
||||
validation {
|
||||
condition = var.agentapi_subdomain || (
|
||||
# If version doesn't look like a valid semantic version, just allow it.
|
||||
# Note that boolean operators do not short-circuit in Terraform.
|
||||
can(regex("^v\\d+\\.\\d+\\.\\d+$", var.agentapi_version)) ?
|
||||
can(regex(local.agentapi_subdomain_false_min_version_expr, var.agentapi_version)) :
|
||||
true
|
||||
)
|
||||
error_message = "Running with subdomain = false is only supported by agentapi >= v0.3.3."
|
||||
}
|
||||
}
|
||||
|
||||
variable "module_dir_name" {
|
||||
type = string
|
||||
description = "Name of the subdirectory in the home directory for module files."
|
||||
@@ -140,7 +165,14 @@ locals {
|
||||
encoded_post_install_script = var.post_install_script != null ? base64encode(var.post_install_script) : ""
|
||||
agentapi_start_script_b64 = base64encode(var.start_script)
|
||||
agentapi_wait_for_start_script_b64 = base64encode(file("${path.module}/scripts/agentapi-wait-for-start.sh"))
|
||||
main_script = file("${path.module}/scripts/main.sh")
|
||||
// Chat base path is only set if not using a subdomain.
|
||||
// NOTE:
|
||||
// - Initial support for --chat-base-path was added in v0.3.1 but configuration
|
||||
// via environment variable AGENTAPI_CHAT_BASE_PATH was added in v0.3.3.
|
||||
// - As CODER_WORKSPACE_AGENT_NAME is a recent addition we use agent ID
|
||||
// for backward compatibility.
|
||||
agentapi_chat_base_path = var.agentapi_subdomain ? "" : "/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}.${var.agent_id}/apps/${var.web_app_slug}/chat"
|
||||
main_script = file("${path.module}/scripts/main.sh")
|
||||
}
|
||||
|
||||
resource "coder_script" "agentapi" {
|
||||
@@ -165,6 +197,7 @@ resource "coder_script" "agentapi" {
|
||||
ARG_WAIT_FOR_START_SCRIPT="$(echo -n '${local.agentapi_wait_for_start_script_b64}' | base64 -d)" \
|
||||
ARG_POST_INSTALL_SCRIPT="$(echo -n '${local.encoded_post_install_script}' | base64 -d)" \
|
||||
ARG_AGENTAPI_PORT='${var.agentapi_port}' \
|
||||
ARG_AGENTAPI_CHAT_BASE_PATH='${local.agentapi_chat_base_path}' \
|
||||
/tmp/main.sh
|
||||
EOT
|
||||
run_on_start = true
|
||||
@@ -178,7 +211,7 @@ resource "coder_app" "agentapi_web" {
|
||||
icon = var.web_app_icon
|
||||
order = var.web_app_order
|
||||
group = var.web_app_group
|
||||
subdomain = true
|
||||
subdomain = var.agentapi_subdomain
|
||||
healthcheck {
|
||||
url = "http://localhost:${var.agentapi_port}/status"
|
||||
interval = 3
|
||||
|
||||
@@ -13,6 +13,7 @@ START_SCRIPT="$ARG_START_SCRIPT"
|
||||
WAIT_FOR_START_SCRIPT="$ARG_WAIT_FOR_START_SCRIPT"
|
||||
POST_INSTALL_SCRIPT="$ARG_POST_INSTALL_SCRIPT"
|
||||
AGENTAPI_PORT="$ARG_AGENTAPI_PORT"
|
||||
AGENTAPI_CHAT_BASE_PATH="${ARG_AGENTAPI_CHAT_BASE_PATH:-}"
|
||||
set +o nounset
|
||||
|
||||
command_exists() {
|
||||
@@ -92,5 +93,7 @@ export LANG=en_US.UTF-8
|
||||
export LC_ALL=en_US.UTF-8
|
||||
|
||||
cd "${WORKDIR}"
|
||||
|
||||
export AGENTAPI_CHAT_BASE_PATH="${AGENTAPI_CHAT_BASE_PATH:-}"
|
||||
nohup "$module_path/scripts/agentapi-start.sh" true "${AGENTAPI_PORT}" &>"$module_path/agentapi-start.log" &
|
||||
"$module_path/scripts/agentapi-wait-for-start.sh" "${AGENTAPI_PORT}"
|
||||
|
||||
@@ -24,7 +24,16 @@ export const setupContainer = async ({
|
||||
});
|
||||
const coderScript = findResourceInstance(state, "coder_script");
|
||||
const id = await runContainer(image ?? "codercom/enterprise-node:latest");
|
||||
return { id, coderScript, cleanup: () => removeContainer(id) };
|
||||
return {
|
||||
id, coderScript, cleanup: async () => {
|
||||
if (process.env["DEBUG"] === "true" || process.env["DEBUG"] === "1" || process.env["DEBUG"] === "yes") {
|
||||
console.log(`Not removing container ${id} in debug mode`);
|
||||
console.log(`Run "docker rm -f ${id}" to remove it manually.`);
|
||||
} else {
|
||||
await removeContainer(id);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const loadTestFile = async (
|
||||
|
||||
@@ -11,6 +11,12 @@ log_file_path="$module_path/agentapi.log"
|
||||
echo "using prompt: $use_prompt" >>/home/coder/test-agentapi-start.log
|
||||
echo "using port: $port" >>/home/coder/test-agentapi-start.log
|
||||
|
||||
AGENTAPI_CHAT_BASE_PATH="${AGENTAPI_CHAT_BASE_PATH:-}"
|
||||
if [ -n "$AGENTAPI_CHAT_BASE_PATH" ]; then
|
||||
echo "Using AGENTAPI_CHAT_BASE_PATH: $AGENTAPI_CHAT_BASE_PATH" >>/home/coder/test-agentapi-start.log
|
||||
export AGENTAPI_CHAT_BASE_PATH
|
||||
fi
|
||||
|
||||
agentapi server --port "$port" --term-width 67 --term-height 1190 -- \
|
||||
bash -c aiagent \
|
||||
>"$log_file_path" 2>&1
|
||||
|
||||
@@ -13,7 +13,7 @@ Run [Aider](https://aider.chat) AI pair programming in your workspace. This modu
|
||||
```tf
|
||||
module "aider" {
|
||||
source = "registry.coder.com/coder/aider/coder"
|
||||
version = "1.1.1"
|
||||
version = "1.1.2"
|
||||
agent_id = coder_agent.example.id
|
||||
}
|
||||
```
|
||||
@@ -30,29 +30,8 @@ module "aider" {
|
||||
|
||||
## Module Parameters
|
||||
|
||||
| Parameter | Description | Type | Default |
|
||||
| ---------------------------------- | -------------------------------------------------------------------------- | -------- | ------------------- |
|
||||
| `agent_id` | The ID of a Coder agent (required) | `string` | - |
|
||||
| `folder` | The folder to run Aider in | `string` | `/home/coder` |
|
||||
| `install_aider` | Whether to install Aider | `bool` | `true` |
|
||||
| `aider_version` | The version of Aider to install | `string` | `"latest"` |
|
||||
| `use_screen` | Whether to use screen for running Aider in the background | `bool` | `true` |
|
||||
| `use_tmux` | Whether to use tmux instead of screen for running Aider in the background | `bool` | `false` |
|
||||
| `session_name` | Name for the persistent session (screen or tmux) | `string` | `"aider"` |
|
||||
| `order` | Position of the app in the UI presentation | `number` | `null` |
|
||||
| `icon` | The icon to use for the app | `string` | `"/icon/aider.svg"` |
|
||||
| `experiment_report_tasks` | Whether to enable task reporting | `bool` | `true` |
|
||||
| `system_prompt` | System prompt for instructing Aider on task reporting and behavior | `string` | See default in code |
|
||||
| `task_prompt` | Task prompt to use with Aider | `string` | `""` |
|
||||
| `ai_provider` | AI provider to use with Aider (openai, anthropic, azure, etc.) | `string` | `"anthropic"` |
|
||||
| `ai_model` | AI model to use (can use Aider's built-in aliases like "sonnet", "4o") | `string` | `"sonnet"` |
|
||||
| `ai_api_key` | API key for the selected AI provider | `string` | `""` |
|
||||
| `custom_env_var_name` | Custom environment variable name when using custom provider | `string` | `""` |
|
||||
| `experiment_pre_install_script` | Custom script to run before installing Aider | `string` | `null` |
|
||||
| `experiment_post_install_script` | Custom script to run after installing Aider | `string` | `null` |
|
||||
| `experiment_additional_extensions` | Additional extensions configuration in YAML format to append to the config | `string` | `null` |
|
||||
|
||||
> **Note**: `use_screen` and `use_tmux` cannot both be enabled at the same time. By default, `use_screen` is set to `true` and `use_tmux` is set to `false`.
|
||||
> [!NOTE]
|
||||
> The `use_screen` and `use_tmux` parameters cannot both be enabled at the same time. By default, `use_screen` is set to `true` and `use_tmux` is set to `false`.
|
||||
|
||||
## Usage Examples
|
||||
|
||||
@@ -68,7 +47,7 @@ variable "anthropic_api_key" {
|
||||
module "aider" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
source = "registry.coder.com/coder/aider/coder"
|
||||
version = "1.1.1"
|
||||
version = "1.1.2"
|
||||
agent_id = coder_agent.example.id
|
||||
ai_api_key = var.anthropic_api_key
|
||||
}
|
||||
@@ -93,7 +72,7 @@ variable "openai_api_key" {
|
||||
module "aider" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
source = "registry.coder.com/coder/aider/coder"
|
||||
version = "1.1.1"
|
||||
version = "1.1.2"
|
||||
agent_id = coder_agent.example.id
|
||||
use_tmux = true
|
||||
ai_provider = "openai"
|
||||
@@ -114,7 +93,7 @@ variable "custom_api_key" {
|
||||
module "aider" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
source = "registry.coder.com/coder/aider/coder"
|
||||
version = "1.1.1"
|
||||
version = "1.1.2"
|
||||
agent_id = coder_agent.example.id
|
||||
ai_provider = "custom"
|
||||
custom_env_var_name = "MY_CUSTOM_API_KEY"
|
||||
@@ -131,7 +110,7 @@ You can extend Aider's capabilities by adding custom extensions:
|
||||
module "aider" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
source = "registry.coder.com/coder/aider/coder"
|
||||
version = "1.1.1"
|
||||
version = "1.1.2"
|
||||
agent_id = coder_agent.example.id
|
||||
ai_api_key = var.anthropic_api_key
|
||||
|
||||
@@ -210,7 +189,7 @@ data "coder_parameter" "ai_prompt" {
|
||||
module "aider" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
source = "registry.coder.com/coder/aider/coder"
|
||||
version = "1.1.1"
|
||||
version = "1.1.2"
|
||||
agent_id = coder_agent.example.id
|
||||
ai_api_key = var.anthropic_api_key
|
||||
task_prompt = data.coder_parameter.ai_prompt.value
|
||||
@@ -308,7 +287,3 @@ If you encounter issues:
|
||||
3. **Browser mode issues**: If the browser interface doesn't open, check that you're accessing it from a machine that can reach your Coder workspace
|
||||
|
||||
For more information on using Aider, see the [Aider documentation](https://aider.chat/docs/).
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
@@ -13,8 +13,9 @@ Run [Amazon Q](https://aws.amazon.com/q/) in your workspace to access Amazon's A
|
||||
```tf
|
||||
module "amazon-q" {
|
||||
source = "registry.coder.com/coder/amazon-q/coder"
|
||||
version = "1.1.1"
|
||||
version = "1.1.2"
|
||||
agent_id = coder_agent.example.id
|
||||
|
||||
# Required: see below for how to generate
|
||||
experiment_auth_tarball = var.amazon_q_auth_tarball
|
||||
}
|
||||
@@ -81,7 +82,7 @@ module "amazon-q" {
|
||||
```tf
|
||||
module "amazon-q" {
|
||||
source = "registry.coder.com/coder/amazon-q/coder"
|
||||
version = "1.1.1"
|
||||
version = "1.1.2"
|
||||
agent_id = coder_agent.example.id
|
||||
experiment_auth_tarball = var.amazon_q_auth_tarball
|
||||
experiment_use_tmux = true
|
||||
@@ -93,7 +94,7 @@ module "amazon-q" {
|
||||
```tf
|
||||
module "amazon-q" {
|
||||
source = "registry.coder.com/coder/amazon-q/coder"
|
||||
version = "1.1.1"
|
||||
version = "1.1.2"
|
||||
agent_id = coder_agent.example.id
|
||||
experiment_auth_tarball = var.amazon_q_auth_tarball
|
||||
experiment_report_tasks = true
|
||||
@@ -105,7 +106,7 @@ module "amazon-q" {
|
||||
```tf
|
||||
module "amazon-q" {
|
||||
source = "registry.coder.com/coder/amazon-q/coder"
|
||||
version = "1.1.1"
|
||||
version = "1.1.2"
|
||||
agent_id = coder_agent.example.id
|
||||
experiment_auth_tarball = var.amazon_q_auth_tarball
|
||||
experiment_pre_install_script = "echo Pre-install!"
|
||||
|
||||
@@ -125,24 +125,7 @@ variable "ai_prompt" {
|
||||
locals {
|
||||
encoded_pre_install_script = var.experiment_pre_install_script != null ? base64encode(var.experiment_pre_install_script) : ""
|
||||
encoded_post_install_script = var.experiment_post_install_script != null ? base64encode(var.experiment_post_install_script) : ""
|
||||
# We need to use allowed tools to limit the context Amazon Q receives.
|
||||
# Amazon Q can't handle big contexts, and the `create_template_version` tool
|
||||
# has a description that's too long.
|
||||
mcp_json = <<EOT
|
||||
{
|
||||
"mcpServers": {
|
||||
"coder": {
|
||||
"command": "coder",
|
||||
"args": ["exp", "mcp", "server", "--allowed-tools", "coder_report_task"],
|
||||
"env": {
|
||||
"CODER_MCP_APP_STATUS_SLUG": "amazon-q"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
EOT
|
||||
encoded_mcp_json = base64encode(local.mcp_json)
|
||||
full_prompt = <<-EOT
|
||||
full_prompt = <<-EOT
|
||||
${var.system_prompt}
|
||||
|
||||
Your first task is:
|
||||
@@ -211,6 +194,12 @@ resource "coder_script" "amazon_q" {
|
||||
cd "$PREV_DIR"
|
||||
echo "Extracted auth tarball"
|
||||
|
||||
if [ "${var.experiment_report_tasks}" = "true" ]; then
|
||||
echo "Configuring Amazon Q to report tasks via Coder MCP..."
|
||||
q mcp add --name coder --command "coder" --args "exp,mcp,server,--allowed-tools,coder_report_task" --env "CODER_MCP_APP_STATUS_SLUG=amazon-q" --scope global --force
|
||||
echo "Added Coder MCP server to Amazon Q configuration"
|
||||
fi
|
||||
|
||||
if [ -n "${local.encoded_post_install_script}" ]; then
|
||||
echo "Running post-install script..."
|
||||
echo "${local.encoded_post_install_script}" | base64 -d > /tmp/post_install.sh
|
||||
@@ -218,13 +207,6 @@ resource "coder_script" "amazon_q" {
|
||||
/tmp/post_install.sh
|
||||
fi
|
||||
|
||||
if [ "${var.experiment_report_tasks}" = "true" ]; then
|
||||
echo "Configuring Amazon Q to report tasks via Coder MCP..."
|
||||
mkdir -p ~/.aws/amazonq
|
||||
echo "${local.encoded_mcp_json}" | base64 -d > ~/.aws/amazonq/mcp.json
|
||||
echo "Created the ~/.aws/amazonq/mcp.json configuration file"
|
||||
fi
|
||||
|
||||
if [ "${var.experiment_use_tmux}" = "true" ] && [ "${var.experiment_use_screen}" = "true" ]; then
|
||||
echo "Error: Both experiment_use_tmux and experiment_use_screen cannot be true simultaneously."
|
||||
echo "Please set only one of them to true."
|
||||
|
||||
@@ -13,7 +13,7 @@ Run the [Claude Code](https://docs.anthropic.com/en/docs/agents-and-tools/claude
|
||||
```tf
|
||||
module "claude-code" {
|
||||
source = "registry.coder.com/coder/claude-code/coder"
|
||||
version = "2.0.3"
|
||||
version = "2.0.6"
|
||||
agent_id = coder_agent.example.id
|
||||
folder = "/home/coder"
|
||||
install_claude_code = true
|
||||
@@ -84,7 +84,7 @@ resource "coder_agent" "main" {
|
||||
module "claude-code" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
source = "registry.coder.com/coder/claude-code/coder"
|
||||
version = "2.0.3"
|
||||
version = "2.0.6"
|
||||
agent_id = coder_agent.example.id
|
||||
folder = "/home/coder"
|
||||
install_claude_code = true
|
||||
@@ -102,7 +102,7 @@ Run Claude Code as a standalone app in your workspace. This will install Claude
|
||||
```tf
|
||||
module "claude-code" {
|
||||
source = "registry.coder.com/coder/claude-code/coder"
|
||||
version = "2.0.3"
|
||||
version = "2.0.6"
|
||||
agent_id = coder_agent.example.id
|
||||
folder = "/home/coder"
|
||||
install_claude_code = true
|
||||
|
||||
@@ -100,7 +100,7 @@ variable "install_agentapi" {
|
||||
variable "agentapi_version" {
|
||||
type = string
|
||||
description = "The version of AgentAPI to install."
|
||||
default = "v0.2.3"
|
||||
default = "v0.3.0"
|
||||
}
|
||||
|
||||
locals {
|
||||
|
||||
@@ -0,0 +1,261 @@
|
||||
---
|
||||
display_name: Cursor CLI
|
||||
description: Run Cursor CLI agent in your workspace with MCP and force mode support
|
||||
icon: ../../../../.icons/cursor.svg
|
||||
verified: true
|
||||
tags: [cli, cursor, ai, agent, mcp, automation]
|
||||
---
|
||||
|
||||
# Cursor CLI
|
||||
|
||||
Run the [Cursor CLI](https://docs.cursor.com/en/cli/overview) agent in your workspace for terminal-based AI coding assistance. Supports both interactive and non-interactive modes, MCP (Model Context Protocol), and automation features.
|
||||
|
||||
```tf
|
||||
module "cursor-cli" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
source = "registry.coder.com/coder/cursor-cli/coder"
|
||||
version = "1.0.0"
|
||||
agent_id = coder_agent.example.id
|
||||
folder = "/home/coder"
|
||||
}
|
||||
```
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- You must add the [Coder Login](https://registry.coder.com/modules/coder-login) module to your template
|
||||
|
||||
## Features
|
||||
|
||||
- **CLI Agent**: Terminal-based AI coding assistant with interactive and non-interactive modes
|
||||
- **AgentAPI Integration**: Web interface for CLI interactions
|
||||
- **Interactive Mode**: Conversational sessions with text output
|
||||
- **Non-Interactive Mode**: Automation-friendly for scripts and CI pipelines
|
||||
- **Session Management**: List, resume, and manage coding sessions
|
||||
- **Model Selection**: Support for multiple AI models (GPT-5, Claude, etc.)
|
||||
- **MCP Support**: Model Context Protocol for extended functionality
|
||||
- **Rules System**: Custom agent behavior configuration
|
||||
|
||||
## Examples
|
||||
|
||||
### Basic setup
|
||||
|
||||
```tf
|
||||
module "coder-login" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
source = "registry.coder.com/coder/coder-login/coder"
|
||||
version = "1.0.15"
|
||||
agent_id = coder_agent.example.id
|
||||
}
|
||||
|
||||
module "cursor-cli" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
source = "registry.coder.com/coder/cursor-cli/coder"
|
||||
version = "1.0.0"
|
||||
agent_id = coder_agent.example.id
|
||||
folder = "/home/coder/project"
|
||||
install_cursor_cli = true
|
||||
install_agentapi = true
|
||||
}
|
||||
```
|
||||
|
||||
### CLI only (no web interface)
|
||||
|
||||
```tf
|
||||
module "cursor-cli" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
source = "registry.coder.com/coder/cursor-cli/coder"
|
||||
version = "1.0.0"
|
||||
agent_id = coder_agent.example.id
|
||||
folder = "/home/coder/project"
|
||||
install_cursor_cli = true
|
||||
install_agentapi = false
|
||||
}
|
||||
```
|
||||
|
||||
### With MCP and force mode for automation
|
||||
|
||||
```tf
|
||||
module "cursor-cli" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
source = "registry.coder.com/coder/cursor-cli/coder"
|
||||
version = "1.0.0"
|
||||
agent_id = coder_agent.example.id
|
||||
folder = "/home/coder/project"
|
||||
|
||||
# MCP Configuration
|
||||
enable_mcp = true
|
||||
mcp_config_path = "/home/coder/.cursor/custom-mcp.json"
|
||||
|
||||
# Automation Features
|
||||
enable_force_mode = true
|
||||
default_model = "gpt-5"
|
||||
|
||||
# Rules System
|
||||
enable_rules = true
|
||||
}
|
||||
```
|
||||
|
||||
### Integration with Coder Tasks
|
||||
|
||||
```tf
|
||||
# Cursor CLI module with automation features
|
||||
module "cursor-cli" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
source = "registry.coder.com/coder/cursor-cli/coder"
|
||||
version = "1.0.0"
|
||||
agent_id = coder_agent.example.id
|
||||
enable_force_mode = true
|
||||
default_model = "claude-4-sonnet"
|
||||
}
|
||||
|
||||
# Automated code review task
|
||||
resource "coder_task" "ai_code_review" {
|
||||
agent_id = coder_agent.example.id
|
||||
name = "AI Code Review"
|
||||
command = "cursor-agent -p 'review the latest git changes for security issues and best practices' --force --output-format text"
|
||||
cron = "0 9 * * 1-5" # Weekdays at 9 AM
|
||||
}
|
||||
|
||||
# Automated test generation
|
||||
resource "coder_task" "generate_tests" {
|
||||
agent_id = coder_agent.example.id
|
||||
name = "Generate Missing Tests"
|
||||
command = "cursor-agent -p 'analyze the src/ directory and generate unit tests for functions missing test coverage' --force"
|
||||
cron = "0 18 * * *" # Daily at 6 PM
|
||||
}
|
||||
|
||||
# Documentation updates
|
||||
resource "coder_task" "update_docs" {
|
||||
agent_id = coder_agent.example.id
|
||||
name = "Update Documentation"
|
||||
command = "cursor-agent -p 'review and update README.md to reflect any new features or API changes' --force --model gpt-5"
|
||||
cron = "0 12 * * 0" # Sundays at noon
|
||||
}
|
||||
```
|
||||
|
||||
### With custom pre-install script
|
||||
|
||||
```tf
|
||||
module "cursor-cli" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
source = "registry.coder.com/coder/cursor-cli/coder"
|
||||
version = "1.0.0"
|
||||
agent_id = coder_agent.example.id
|
||||
|
||||
pre_install_script = <<-EOT
|
||||
# Install additional dependencies
|
||||
npm install -g typescript
|
||||
EOT
|
||||
}
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Web Interface
|
||||
|
||||
1. Click the "Cursor CLI" button to access the web interface
|
||||
2. Start interactive sessions with text output
|
||||
|
||||
### Terminal Usage
|
||||
|
||||
```bash
|
||||
# Interactive mode (default)
|
||||
cursor-agent
|
||||
|
||||
# Interactive mode with initial prompt
|
||||
cursor-agent "refactor the auth module to use JWT tokens"
|
||||
|
||||
# Non-interactive mode with text output
|
||||
cursor-agent -p "find and fix performance issues" --output-format text
|
||||
|
||||
# Force mode for automation (non-interactive)
|
||||
cursor-agent -p "review code for security issues" --force
|
||||
|
||||
# Use specific model
|
||||
cursor-agent -p "add error handling" --model "gpt-5"
|
||||
|
||||
# Combine force mode with model selection
|
||||
cursor-agent -p "generate comprehensive tests" --force --model "claude-4-sonnet"
|
||||
|
||||
# Session management
|
||||
cursor-agent ls # List all previous chats
|
||||
cursor-agent resume # Resume latest conversation
|
||||
cursor-agent --resume="chat-id" # Resume specific conversation
|
||||
```
|
||||
|
||||
### Interactive Mode Features
|
||||
|
||||
- Conversational sessions with the agent
|
||||
- Review proposed changes before applying
|
||||
- Real-time guidance and steering
|
||||
- Text-based output optimized for terminal use
|
||||
- Session persistence and resumption
|
||||
|
||||
### Non-Interactive Mode Features
|
||||
|
||||
- Automation-friendly for scripts and CI pipelines
|
||||
- Direct prompt execution with text output
|
||||
- Model selection support
|
||||
- Git integration for change reviews
|
||||
|
||||
## Screenshots
|
||||
|
||||
### Cursor CLI with Coder Tasks Integration
|
||||
|
||||
*Screenshot showing the cursor-cli module working with automated Coder Tasks will be added here*
|
||||
|
||||
- Interactive web interface for cursor-agent
|
||||
- Automated code review tasks running in background
|
||||
- Terminal output showing force mode execution
|
||||
- MCP integration with custom tools
|
||||
|
||||
## Configuration
|
||||
|
||||
The module supports comprehensive configuration options:
|
||||
|
||||
### Core Features
|
||||
- **MCP (Model Context Protocol)**: Automatically detects `mcp.json` configuration or uses custom path
|
||||
- **Rules System**: Supports `.cursor/rules` directory for custom agent behavior
|
||||
- **Force Mode**: Enable non-interactive automation for CI/CD pipelines
|
||||
- **Model Selection**: Set default AI model (gpt-5, claude-4-sonnet, etc.)
|
||||
- **Environment Variables**: Respects Cursor CLI environment settings
|
||||
|
||||
### Available Variables
|
||||
|
||||
| Variable | Type | Default | Description |
|
||||
|----------|------|---------|-------------|
|
||||
| `enable_mcp` | bool | `true` | Enable MCP (Model Context Protocol) support |
|
||||
| `mcp_config_path` | string | `""` | Path to custom MCP configuration file |
|
||||
| `enable_force_mode` | bool | `false` | Enable force mode for non-interactive automation |
|
||||
| `default_model` | string | `""` | Default AI model (e.g., gpt-5, claude-4-sonnet) |
|
||||
| `enable_rules` | bool | `true` | Enable the rules system (.cursor/rules directory) |
|
||||
| `install_cursor_cli` | bool | `true` | Whether to install Cursor CLI |
|
||||
| `install_agentapi` | bool | `true` | Whether to install AgentAPI web interface |
|
||||
| `folder` | string | `"/home/coder"` | Working directory for cursor-agent |
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
The module creates log files in the workspace's `~/.cursor-cli-module` directory. Check these files if you encounter issues:
|
||||
|
||||
```bash
|
||||
# Check installation logs
|
||||
cat ~/.cursor-cli-module/install.log
|
||||
|
||||
# Check runtime logs
|
||||
cat ~/.cursor-cli-module/runtime.log
|
||||
|
||||
# Verify Cursor CLI installation
|
||||
cursor-agent --help
|
||||
```
|
||||
|
||||
### Common Issues
|
||||
|
||||
1. **Cursor CLI not found**: Ensure `install_cursor_cli = true` or install manually:
|
||||
|
||||
```bash
|
||||
curl https://cursor.com/install -fsS | bash
|
||||
```
|
||||
|
||||
2. **Permission issues**: Check that the installation script has proper permissions
|
||||
|
||||
3. **Path issues**: The module automatically adds Cursor CLI to PATH, but you may need to restart your shell
|
||||
@@ -0,0 +1,80 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import {
|
||||
runTerraformApply,
|
||||
runTerraformInit,
|
||||
testRequiredVariables,
|
||||
} from "~test";
|
||||
|
||||
describe("cursor-cli", async () => {
|
||||
await runTerraformInit(import.meta.dir);
|
||||
|
||||
testRequiredVariables(import.meta.dir, {
|
||||
agent_id: "foo",
|
||||
});
|
||||
|
||||
it("default output with CLI enabled", async () => {
|
||||
const state = await runTerraformApply(import.meta.dir, {
|
||||
agent_id: "foo",
|
||||
});
|
||||
|
||||
// Check that AgentAPI module is created
|
||||
const agentapi_module = state.resources.find(
|
||||
(res) => res.type === "module" && res.name === "agentapi",
|
||||
);
|
||||
expect(agentapi_module).not.toBeNull();
|
||||
});
|
||||
|
||||
it("adds custom folder", async () => {
|
||||
const state = await runTerraformApply(import.meta.dir, {
|
||||
agent_id: "foo",
|
||||
folder: "/foo/bar",
|
||||
});
|
||||
|
||||
// Check that AgentAPI module is created with custom folder
|
||||
const agentapi_module = state.resources.find(
|
||||
(res) => res.type === "module" && res.name === "agentapi",
|
||||
);
|
||||
expect(agentapi_module).not.toBeNull();
|
||||
});
|
||||
|
||||
it("expect order to be set", async () => {
|
||||
const state = await runTerraformApply(import.meta.dir, {
|
||||
agent_id: "foo",
|
||||
order: "22",
|
||||
});
|
||||
|
||||
// Check that AgentAPI module is created
|
||||
const agentapi_module = state.resources.find(
|
||||
(res) => res.type === "module" && res.name === "agentapi",
|
||||
);
|
||||
expect(agentapi_module).not.toBeNull();
|
||||
});
|
||||
|
||||
it("disables CLI installation", async () => {
|
||||
const state = await runTerraformApply(import.meta.dir, {
|
||||
agent_id: "foo",
|
||||
install_cursor_cli: "false",
|
||||
install_agentapi: "false",
|
||||
});
|
||||
|
||||
// AgentAPI module should still exist but with install_agentapi = false
|
||||
const agentapi_module = state.resources.find(
|
||||
(res) => res.type === "module" && res.name === "agentapi",
|
||||
);
|
||||
expect(agentapi_module).not.toBeNull();
|
||||
});
|
||||
|
||||
it("enables only CLI without web interface", async () => {
|
||||
const state = await runTerraformApply(import.meta.dir, {
|
||||
agent_id: "foo",
|
||||
install_cursor_cli: "true",
|
||||
install_agentapi: "false",
|
||||
});
|
||||
|
||||
// AgentAPI module should exist but with install_agentapi = false
|
||||
const agentapi_module = state.resources.find(
|
||||
(res) => res.type === "module" && res.name === "agentapi",
|
||||
);
|
||||
expect(agentapi_module).not.toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,154 @@
|
||||
terraform {
|
||||
required_version = ">= 1.0"
|
||||
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
version = ">= 2.7"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
variable "agent_id" {
|
||||
type = string
|
||||
description = "The ID of a Coder agent."
|
||||
}
|
||||
|
||||
data "coder_workspace" "me" {}
|
||||
|
||||
data "coder_workspace_owner" "me" {}
|
||||
|
||||
variable "order" {
|
||||
type = number
|
||||
description = "The order determines the position of app in the UI presentation. The lowest order is shown first and apps with equal order are sorted by name (ascending order)."
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "group" {
|
||||
type = string
|
||||
description = "The name of a group that this app belongs to."
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "icon" {
|
||||
type = string
|
||||
description = "The icon to use for the app."
|
||||
default = "/icon/cursor.svg"
|
||||
}
|
||||
|
||||
variable "folder" {
|
||||
type = string
|
||||
description = "The folder to run Cursor CLI in."
|
||||
default = "/home/coder"
|
||||
}
|
||||
|
||||
variable "install_cursor_cli" {
|
||||
type = bool
|
||||
description = "Whether to install Cursor CLI."
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "install_agentapi" {
|
||||
type = bool
|
||||
description = "Whether to install AgentAPI."
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "agentapi_version" {
|
||||
type = string
|
||||
description = "The version of AgentAPI to install."
|
||||
default = "v0.3.3"
|
||||
}
|
||||
|
||||
variable "subdomain" {
|
||||
type = bool
|
||||
description = "Whether to use a subdomain for AgentAPI."
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "pre_install_script" {
|
||||
type = string
|
||||
description = "Custom script to run before installing Cursor CLI."
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "post_install_script" {
|
||||
type = string
|
||||
description = "Custom script to run after installing Cursor CLI."
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "enable_mcp" {
|
||||
type = bool
|
||||
description = "Whether to enable MCP (Model Context Protocol) support."
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "mcp_config_path" {
|
||||
type = string
|
||||
description = "Path to the MCP configuration file (mcp.json)."
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "enable_force_mode" {
|
||||
type = bool
|
||||
description = "Whether to enable force mode for non-interactive automation."
|
||||
default = false
|
||||
}
|
||||
|
||||
variable "default_model" {
|
||||
type = string
|
||||
description = "Default AI model to use (e.g., gpt-5, claude-4-sonnet)."
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "enable_rules" {
|
||||
type = bool
|
||||
description = "Whether to enable the rules system (.cursor/rules directory)."
|
||||
default = true
|
||||
}
|
||||
|
||||
locals {
|
||||
app_slug = "cursor-cli"
|
||||
install_script = file("${path.module}/scripts/install.sh")
|
||||
start_script = file("${path.module}/scripts/start.sh")
|
||||
module_dir_name = ".cursor-cli-module"
|
||||
}
|
||||
|
||||
module "agentapi" {
|
||||
source = "registry.coder.com/coder/agentapi/coder"
|
||||
version = "1.1.0"
|
||||
|
||||
agent_id = var.agent_id
|
||||
web_app_slug = local.app_slug
|
||||
web_app_order = var.order
|
||||
web_app_group = var.group
|
||||
web_app_icon = var.icon
|
||||
web_app_display_name = "Cursor CLI"
|
||||
cli_app_slug = "${local.app_slug}-terminal"
|
||||
cli_app_display_name = "Cursor CLI Terminal"
|
||||
module_dir_name = local.module_dir_name
|
||||
install_agentapi = var.install_agentapi
|
||||
agentapi_version = var.agentapi_version
|
||||
agentapi_subdomain = var.subdomain
|
||||
pre_install_script = var.pre_install_script
|
||||
post_install_script = var.post_install_script
|
||||
start_script = local.start_script
|
||||
install_script = <<-EOT
|
||||
#!/bin/bash
|
||||
set -o errexit
|
||||
set -o pipefail
|
||||
|
||||
echo -n '${base64encode(local.install_script)}' | base64 -d > /tmp/install.sh
|
||||
chmod +x /tmp/install.sh
|
||||
|
||||
ARG_FOLDER='${var.folder}' \
|
||||
ARG_INSTALL='${var.install_cursor_cli}' \
|
||||
ARG_ENABLE_MCP='${var.enable_mcp}' \
|
||||
ARG_MCP_CONFIG_PATH='${var.mcp_config_path}' \
|
||||
ARG_ENABLE_FORCE_MODE='${var.enable_force_mode}' \
|
||||
ARG_DEFAULT_MODEL='${var.default_model}' \
|
||||
ARG_ENABLE_RULES='${var.enable_rules}' \
|
||||
/tmp/install.sh
|
||||
EOT
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Function to check if a command exists
|
||||
command_exists() {
|
||||
command -v "$1" > /dev/null 2>&1
|
||||
}
|
||||
|
||||
set -o nounset
|
||||
|
||||
echo "--------------------------------"
|
||||
echo "folder: $ARG_FOLDER"
|
||||
echo "install: $ARG_INSTALL"
|
||||
echo "enable_mcp: $ARG_ENABLE_MCP"
|
||||
echo "mcp_config_path: $ARG_MCP_CONFIG_PATH"
|
||||
echo "enable_force_mode: $ARG_ENABLE_FORCE_MODE"
|
||||
echo "default_model: $ARG_DEFAULT_MODEL"
|
||||
echo "enable_rules: $ARG_ENABLE_RULES"
|
||||
echo "--------------------------------"
|
||||
|
||||
set +o nounset
|
||||
|
||||
if [ "${ARG_INSTALL}" = "true" ]; then
|
||||
echo "Installing Cursor CLI..."
|
||||
|
||||
# Install Cursor CLI using the official installer
|
||||
curl https://cursor.com/install -fsS | bash
|
||||
|
||||
# Add cursor-agent to PATH if not already there
|
||||
if ! command_exists cursor-agent; then
|
||||
echo 'export PATH="$HOME/.cursor/bin:$PATH"' >> "$HOME/.bashrc"
|
||||
echo 'export PATH="$HOME/.cursor/bin:$PATH"' >> "$HOME/.zshrc" 2> /dev/null || true
|
||||
export PATH="$HOME/.cursor/bin:$PATH"
|
||||
fi
|
||||
|
||||
echo "Cursor CLI installed"
|
||||
|
||||
# Configure MCP if enabled
|
||||
if [ "${ARG_ENABLE_MCP}" = "true" ]; then
|
||||
echo "Configuring MCP (Model Context Protocol)..."
|
||||
|
||||
# Create MCP config directory if it doesn't exist
|
||||
mkdir -p "$HOME/.cursor"
|
||||
|
||||
# If custom MCP config path is provided, copy it
|
||||
if [ -n "${ARG_MCP_CONFIG_PATH}" ] && [ -f "${ARG_MCP_CONFIG_PATH}" ]; then
|
||||
cp "${ARG_MCP_CONFIG_PATH}" "$HOME/.cursor/mcp.json"
|
||||
echo "MCP configuration copied from ${ARG_MCP_CONFIG_PATH}"
|
||||
else
|
||||
# Create a basic MCP config if none exists
|
||||
if [ ! -f "$HOME/.cursor/mcp.json" ]; then
|
||||
cat > "$HOME/.cursor/mcp.json" << 'EOF'
|
||||
{
|
||||
"mcpServers": {
|
||||
"filesystem": {
|
||||
"command": "npx",
|
||||
"args": ["@modelcontextprotocol/server-filesystem", "/tmp"]
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
echo "Basic MCP configuration created"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Configure rules system if enabled
|
||||
if [ "${ARG_ENABLE_RULES}" = "true" ]; then
|
||||
echo "Setting up Cursor rules system..."
|
||||
mkdir -p "$HOME/.cursor/rules"
|
||||
|
||||
# Create a basic rules file if none exists
|
||||
if [ ! -f "$HOME/.cursor/rules/general.md" ]; then
|
||||
cat > "$HOME/.cursor/rules/general.md" << 'EOF'
|
||||
# General Coding Rules
|
||||
|
||||
## Code Style
|
||||
- Use consistent indentation (2 spaces for JS/TS, 4 for Python)
|
||||
- Add meaningful comments for complex logic
|
||||
- Follow language-specific naming conventions
|
||||
|
||||
## Best Practices
|
||||
- Write tests for new functionality
|
||||
- Handle errors gracefully
|
||||
- Use descriptive variable and function names
|
||||
EOF
|
||||
echo "Basic rules configuration created"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo "Skipping Cursor CLI installation"
|
||||
fi
|
||||
|
||||
# Verify installation
|
||||
if command_exists cursor-agent; then
|
||||
CURSOR_CMD=cursor-agent
|
||||
elif [ -f "$HOME/.cursor/bin/cursor-agent" ]; then
|
||||
CURSOR_CMD="$HOME/.cursor/bin/cursor-agent"
|
||||
else
|
||||
echo "Warning: Cursor CLI is not installed or not found in PATH. Please enable install_cursor_cli or install it manually."
|
||||
echo "You can install it manually with: curl https://cursor.com/install -fsS | bash"
|
||||
fi
|
||||
|
||||
echo "Cursor CLI setup complete"
|
||||
@@ -0,0 +1,67 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Function to check if a command exists
|
||||
command_exists() {
|
||||
command -v "$1" > /dev/null 2>&1
|
||||
}
|
||||
|
||||
# Set working directory
|
||||
if [ -n "${ARG_FOLDER:-}" ] && [ -d "${ARG_FOLDER}" ]; then
|
||||
cd "${ARG_FOLDER}" || {
|
||||
echo "Warning: Could not change to directory ${ARG_FOLDER}, using current directory"
|
||||
}
|
||||
fi
|
||||
|
||||
# Find cursor-agent command
|
||||
if command_exists cursor-agent; then
|
||||
CURSOR_CMD=cursor-agent
|
||||
elif [ -f "$HOME/.cursor/bin/cursor-agent" ]; then
|
||||
CURSOR_CMD="$HOME/.cursor/bin/cursor-agent"
|
||||
else
|
||||
echo "Error: Cursor CLI is not installed. Please enable install_cursor_cli or install it manually."
|
||||
echo "You can install it manually with: curl https://cursor.com/install -fsS | bash"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Starting Cursor CLI in $(pwd)"
|
||||
echo "Interactive mode with text output enabled"
|
||||
echo "Available commands:"
|
||||
echo " - Start interactive session: cursor-agent"
|
||||
echo " - Non-interactive mode: cursor-agent -p 'your prompt here'"
|
||||
echo " - With specific model: cursor-agent -p 'prompt' --model 'gpt-5'"
|
||||
echo " - Text output format: cursor-agent -p 'prompt' --output-format text"
|
||||
echo " - Force mode (non-interactive): cursor-agent -p 'prompt' --force"
|
||||
echo " - List sessions: cursor-agent ls"
|
||||
echo " - Resume session: cursor-agent resume"
|
||||
echo ""
|
||||
|
||||
# Set up environment variables for configuration
|
||||
if [ -n "${ARG_DEFAULT_MODEL:-}" ]; then
|
||||
export CURSOR_DEFAULT_MODEL="${ARG_DEFAULT_MODEL}"
|
||||
echo "Default model set to: ${ARG_DEFAULT_MODEL}"
|
||||
fi
|
||||
|
||||
if [ "${ARG_ENABLE_FORCE_MODE:-false}" = "true" ]; then
|
||||
export CURSOR_FORCE_MODE="true"
|
||||
echo "Force mode enabled for non-interactive automation"
|
||||
fi
|
||||
|
||||
if [ "${ARG_ENABLE_MCP:-true}" = "true" ]; then
|
||||
echo "MCP (Model Context Protocol) support enabled"
|
||||
fi
|
||||
|
||||
if [ "${ARG_ENABLE_RULES:-true}" = "true" ]; then
|
||||
echo "Rules system enabled (.cursor/rules directory)"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
# Configure for interactive mode with text output
|
||||
# If no arguments provided, start in interactive mode
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "Starting interactive session..."
|
||||
exec "$CURSOR_CMD"
|
||||
else
|
||||
# Pass through all arguments for custom usage
|
||||
exec "$CURSOR_CMD" "$@"
|
||||
fi
|
||||
@@ -15,7 +15,7 @@ The devcontainers-cli module provides an easy way to install [`@devcontainers/cl
|
||||
```tf
|
||||
module "devcontainers-cli" {
|
||||
source = "registry.coder.com/coder/devcontainers-cli/coder"
|
||||
version = "1.0.31"
|
||||
version = "1.0.32"
|
||||
agent_id = coder_agent.example.id
|
||||
}
|
||||
```
|
||||
|
||||
@@ -45,6 +45,8 @@ const executeScriptInContainerWithPackageManager = async (
|
||||
|
||||
console.log(path);
|
||||
|
||||
await execContainer(id, [shell, "-c", "mkdir -p /tmp/coder-script-data"]);
|
||||
|
||||
const resp = await execContainer(
|
||||
id,
|
||||
[shell, "-c", instance.script],
|
||||
@@ -52,6 +54,8 @@ const executeScriptInContainerWithPackageManager = async (
|
||||
"--env",
|
||||
"CODER_SCRIPT_BIN_DIR=/tmp/coder-script-data/bin",
|
||||
"--env",
|
||||
"CODER_SCRIPT_DATA_DIR=/tmp/coder-script-data",
|
||||
"--env",
|
||||
`PATH=${path}:/tmp/coder-script-data/bin`,
|
||||
],
|
||||
);
|
||||
|
||||
Regular → Executable
+7
-1
@@ -1,5 +1,11 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# We want to cd into `$CODER_SCRIPT_DATA_DIR` as the current directory
|
||||
# might contain a `package.json` with `packageManager` set to something
|
||||
# other than the detected package manager. When this happens, it can
|
||||
# cause the installation to fail.
|
||||
cd "$CODER_SCRIPT_DATA_DIR"
|
||||
|
||||
# If @devcontainers/cli is already installed, we can skip
|
||||
if command -v devcontainer >/dev/null 2>&1; then
|
||||
echo "🥳 @devcontainers/cli is already installed into $(which devcontainer)!"
|
||||
@@ -34,7 +40,7 @@ install() {
|
||||
# so that the devcontainer command is available
|
||||
if [ -z "$PNPM_HOME" ]; then
|
||||
PNPM_HOME="$CODER_SCRIPT_BIN_DIR"
|
||||
export M_HOME
|
||||
export PNPM_HOME
|
||||
fi
|
||||
pnpm add -g @devcontainers/cli
|
||||
elif [ "$PACKAGE_MANAGER" = "yarn" ]; then
|
||||
|
||||
@@ -13,7 +13,7 @@ Run the [Goose](https://block.github.io/goose/) agent in your workspace to gener
|
||||
```tf
|
||||
module "goose" {
|
||||
source = "registry.coder.com/coder/goose/coder"
|
||||
version = "2.0.1"
|
||||
version = "2.1.0"
|
||||
agent_id = coder_agent.example.id
|
||||
folder = "/home/coder"
|
||||
install_goose = true
|
||||
@@ -79,7 +79,7 @@ resource "coder_agent" "main" {
|
||||
module "goose" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
source = "registry.coder.com/coder/goose/coder"
|
||||
version = "2.0.1"
|
||||
version = "2.1.0"
|
||||
agent_id = coder_agent.example.id
|
||||
folder = "/home/coder"
|
||||
install_goose = true
|
||||
|
||||
@@ -251,4 +251,21 @@ describe("goose", async () => {
|
||||
expect(prompt.exitCode).not.toBe(0);
|
||||
expect(prompt.stderr).toContain("No such file or directory");
|
||||
});
|
||||
|
||||
test("subdomain-false", async () => {
|
||||
const { id } = await setup({
|
||||
agentapiMockScript: await loadTestFile(
|
||||
import.meta.dir,
|
||||
"agentapi-mock-print-args.js",
|
||||
),
|
||||
moduleVariables: {
|
||||
subdomain: "false",
|
||||
},
|
||||
});
|
||||
|
||||
await execModuleScript(id);
|
||||
|
||||
const agentapiMockOutput = await readFileContainer(id, agentapiStartLog);
|
||||
expect(agentapiMockOutput).toContain("AGENTAPI_CHAT_BASE_PATH=/@default/default.foo/apps/goose/chat");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -63,7 +63,13 @@ variable "install_agentapi" {
|
||||
variable "agentapi_version" {
|
||||
type = string
|
||||
description = "The version of AgentAPI to install."
|
||||
default = "v0.2.3"
|
||||
default = "v0.3.3"
|
||||
}
|
||||
|
||||
variable "subdomain" {
|
||||
type = bool
|
||||
description = "Whether to use a subdomain for AgentAPI."
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "goose_provider" {
|
||||
@@ -133,7 +139,7 @@ EOT
|
||||
|
||||
module "agentapi" {
|
||||
source = "registry.coder.com/coder/agentapi/coder"
|
||||
version = "1.0.0"
|
||||
version = "1.1.0"
|
||||
|
||||
agent_id = var.agent_id
|
||||
web_app_slug = local.app_slug
|
||||
@@ -146,6 +152,7 @@ module "agentapi" {
|
||||
module_dir_name = local.module_dir_name
|
||||
install_agentapi = var.install_agentapi
|
||||
agentapi_version = var.agentapi_version
|
||||
agentapi_subdomain = var.subdomain
|
||||
pre_install_script = var.pre_install_script
|
||||
post_install_script = var.post_install_script
|
||||
start_script = local.start_script
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
const http = require("http");
|
||||
const args = process.argv.slice(2);
|
||||
console.log(args);
|
||||
console.log(`AGENTAPI_CHAT_BASE_PATH=${process.env["AGENTAPI_CHAT_BASE_PATH"]}`);
|
||||
const port = 3284;
|
||||
|
||||
console.log(`starting server on port ${port}`);
|
||||
|
||||
@@ -15,9 +15,9 @@ tags: [integration, vault, hashicorp, hvs]
|
||||
>
|
||||
> **Use these Coder registry modules instead:**
|
||||
>
|
||||
> - **[vault-token](https://registry.coder.com/modules/vault-token)** - Connect to Vault using access tokens
|
||||
> - **[vault-jwt](https://registry.coder.com/modules/vault-jwt)** - Connect to Vault using JWT/OIDC authentication
|
||||
> - **[vault-github](https://registry.coder.com/modules/vault-github)** - Connect to Vault using GitHub authentication
|
||||
> - **[vault-token](https://registry.coder.com/modules/coder/vault-token)** - Connect to Vault using access tokens
|
||||
> - **[vault-jwt](https://registry.coder.com/modules/coder/vault-jwt)** - Connect to Vault using JWT/OIDC authentication
|
||||
> - **[vault-github](https://registry.coder.com/modules/coder/vault-github)** - Connect to Vault using GitHub authentication
|
||||
>
|
||||
> These modules work with both self-hosted Vault and HCP Vault Dedicated. For migration help, see the [official HashiCorp announcement](https://developer.hashicorp.com/hcp/docs/vault-secrets/end-of-sale-announcement).
|
||||
|
||||
@@ -26,7 +26,7 @@ This module lets you fetch all or selective secrets from a [HCP Vault Secrets](h
|
||||
```tf
|
||||
module "vault" {
|
||||
source = "registry.coder.com/coder/hcp-vault-secrets/coder"
|
||||
version = "1.0.33"
|
||||
version = "1.0.34"
|
||||
agent_id = coder_agent.example.id
|
||||
app_name = "demo-app"
|
||||
project_id = "aaa-bbb-ccc"
|
||||
@@ -52,7 +52,7 @@ To fetch all secrets from the HCP Vault Secrets app, skip the `secrets` input.
|
||||
```tf
|
||||
module "vault" {
|
||||
source = "registry.coder.com/coder/hcp-vault-secrets/coder"
|
||||
version = "1.0.33"
|
||||
version = "1.0.34"
|
||||
agent_id = coder_agent.example.id
|
||||
app_name = "demo-app"
|
||||
project_id = "aaa-bbb-ccc"
|
||||
@@ -66,7 +66,7 @@ To fetch selective secrets from the HCP Vault Secrets app, set the `secrets` inp
|
||||
```tf
|
||||
module "vault" {
|
||||
source = "registry.coder.com/coder/hcp-vault-secrets/coder"
|
||||
version = "1.0.33"
|
||||
version = "1.0.34"
|
||||
agent_id = coder_agent.example.id
|
||||
app_name = "demo-app"
|
||||
project_id = "aaa-bbb-ccc"
|
||||
@@ -81,7 +81,7 @@ Set `client_id` and `client_secret` as module inputs.
|
||||
```tf
|
||||
module "vault" {
|
||||
source = "registry.coder.com/coder/hcp-vault-secrets/coder"
|
||||
version = "1.0.33"
|
||||
version = "1.0.34"
|
||||
agent_id = coder_agent.example.id
|
||||
app_name = "demo-app"
|
||||
project_id = "aaa-bbb-ccc"
|
||||
|
||||
@@ -14,7 +14,7 @@ This module adds JetBrains IDE buttons to launch IDEs directly from the dashboar
|
||||
module "jetbrains" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
source = "registry.coder.com/coder/jetbrains/coder"
|
||||
version = "1.0.1"
|
||||
version = "1.0.2"
|
||||
agent_id = coder_agent.example.id
|
||||
folder = "/home/coder/project"
|
||||
}
|
||||
@@ -39,7 +39,7 @@ When `default` contains IDE codes, those IDEs are created directly without user
|
||||
module "jetbrains" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
source = "registry.coder.com/coder/jetbrains/coder"
|
||||
version = "1.0.1"
|
||||
version = "1.0.2"
|
||||
agent_id = coder_agent.example.id
|
||||
folder = "/home/coder/project"
|
||||
default = ["PY", "IU"] # Pre-configure GoLand and IntelliJ IDEA
|
||||
@@ -52,7 +52,7 @@ module "jetbrains" {
|
||||
module "jetbrains" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
source = "registry.coder.com/coder/jetbrains/coder"
|
||||
version = "1.0.1"
|
||||
version = "1.0.2"
|
||||
agent_id = coder_agent.example.id
|
||||
folder = "/home/coder/project"
|
||||
# Show parameter with limited options
|
||||
@@ -66,7 +66,7 @@ module "jetbrains" {
|
||||
module "jetbrains" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
source = "registry.coder.com/coder/jetbrains/coder"
|
||||
version = "1.0.1"
|
||||
version = "1.0.2"
|
||||
agent_id = coder_agent.example.id
|
||||
folder = "/home/coder/project"
|
||||
default = ["IU", "PY"]
|
||||
@@ -81,7 +81,7 @@ module "jetbrains" {
|
||||
module "jetbrains" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
source = "registry.coder.com/coder/jetbrains/coder"
|
||||
version = "1.0.1"
|
||||
version = "1.0.2"
|
||||
agent_id = coder_agent.example.id
|
||||
folder = "/workspace/project"
|
||||
|
||||
@@ -107,7 +107,7 @@ module "jetbrains" {
|
||||
module "jetbrains_pycharm" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
source = "registry.coder.com/coder/jetbrains/coder"
|
||||
version = "1.0.1"
|
||||
version = "1.0.2"
|
||||
agent_id = coder_agent.example.id
|
||||
folder = "/workspace/project"
|
||||
|
||||
|
||||
@@ -202,6 +202,7 @@ data "coder_parameter" "jetbrains_ides" {
|
||||
count = length(var.default) == 0 ? 1 : 0
|
||||
type = "list(string)"
|
||||
name = "jetbrains_ides"
|
||||
description = "Select which JetBrains IDEs to configure for use in this workspace."
|
||||
display_name = "JetBrains IDEs"
|
||||
icon = "/icon/jetbrains-toolbox.svg"
|
||||
mutable = true
|
||||
|
||||
@@ -16,7 +16,7 @@ A module that adds Jupyter Notebook in your Coder template.
|
||||
module "jupyter-notebook" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
source = "registry.coder.com/coder/jupyter-notebook/coder"
|
||||
version = "1.1.1"
|
||||
version = "1.2.0"
|
||||
agent_id = coder_agent.example.id
|
||||
}
|
||||
```
|
||||
|
||||
@@ -48,13 +48,27 @@ variable "group" {
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "requirements_path" {
|
||||
type = string
|
||||
description = "The path to requirements.txt with packages to preinstall"
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "pip_install_extra_packages" {
|
||||
type = string
|
||||
description = "List of extra packages to preinstall (example: numpy==1.26.4 pandas matplotlib<4 scikit-learn)"
|
||||
default = ""
|
||||
}
|
||||
|
||||
resource "coder_script" "jupyter-notebook" {
|
||||
agent_id = var.agent_id
|
||||
display_name = "jupyter-notebook"
|
||||
icon = "/icon/jupyter.svg"
|
||||
script = templatefile("${path.module}/run.sh", {
|
||||
LOG_PATH : var.log_path,
|
||||
PORT : var.port
|
||||
PORT : var.port,
|
||||
REQUIREMENTS_PATH : var.requirements_path,
|
||||
PIP_INSTALL_EXTRA_PACKAGES : var.pip_install_extra_packages
|
||||
})
|
||||
run_on_start = true
|
||||
}
|
||||
|
||||
@@ -20,6 +20,24 @@ else
|
||||
echo "🥳 jupyter-notebook is already installed\n\n"
|
||||
fi
|
||||
|
||||
# Install packages selected with REQUIREMENTS_PATH
|
||||
if [ -n "${REQUIREMENTS_PATH}" ]; then
|
||||
if [ -f "${REQUIREMENTS_PATH}" ]; then
|
||||
echo "📄 Installing packages from ${REQUIREMENTS_PATH}..."
|
||||
pipx -q runpip notebook install -r "${REQUIREMENTS_PATH}"
|
||||
echo "🥳 Packages from ${REQUIREMENTS_PATH} have been installed\n\n"
|
||||
else
|
||||
echo "⚠️ REQUIREMENTS_PATH is set to '${REQUIREMENTS_PATH}' but the file does not exist!\n\n"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Install packages selected with PIP_INSTALL_EXTRA_PACKAGES
|
||||
if [ -n "${PIP_INSTALL_EXTRA_PACKAGES}" ]; then
|
||||
echo "📦 Installing additional packages: ${PIP_INSTALL_EXTRA_PACKAGES}"
|
||||
pipx -q runpip notebook install ${PIP_INSTALL_EXTRA_PACKAGES}
|
||||
echo "🥳 Additional packages have been installed\n\n"
|
||||
fi
|
||||
|
||||
echo "👷 Starting jupyter-notebook in background..."
|
||||
echo "check logs at ${LOG_PATH}"
|
||||
$HOME/.local/bin/jupyter-notebook --NotebookApp.ip='0.0.0.0' --ServerApp.port=${PORT} --no-browser --ServerApp.token='' --ServerApp.password='' > ${LOG_PATH} 2>&1 &
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
@@ -0,0 +1,16 @@
|
||||
---
|
||||
display_name: "Eric Paulsen"
|
||||
bio: "Field CTO, EMEA @ Coder"
|
||||
avatar_url: "./.images/avatar.png"
|
||||
github: "ericpaulsen"
|
||||
linkedin: "https://www.linkedin.com/in/ericpaulsen17" # Optional
|
||||
website: "https://ericpaulsen.io" # Optional
|
||||
support_email: "ericpaulsen@hey.com" # Optional
|
||||
status: "community"
|
||||
---
|
||||
|
||||
# Eric Paulsen
|
||||
|
||||
I'm Eric Paulsen, Coder's EMEA Field CTO based in London, originating from Miami.
|
||||
Outside of working with our customers, I enjoy teaching myself things,
|
||||
playing volleyball, and dabbling in a bit of DJing & photography.
|
||||
@@ -0,0 +1,51 @@
|
||||
---
|
||||
display_name: Kubernetes (Deployment) with Dynamic Username
|
||||
description: Provision Kubernetes Deployments as Coder workspaces with your Username
|
||||
icon: ../../../../.icons/kubernetes.svg
|
||||
verified: true
|
||||
tags: [kubernetes, container, username]
|
||||
---
|
||||
|
||||
# Remote development on Kubernetes with dynamic usernames
|
||||
|
||||
Provision Kubernetes Pods as [Coder workspaces](https://coder.com/docs/workspaces) with this example template. This template
|
||||
will run the workspace container as a non-root UID using your Coder username.
|
||||
|
||||
Here is the entrypoint logic in the template that enables Coder to source your username and write it to the Ubuntu operating system at start-up.
|
||||
|
||||
> These commands may differ if you run your workspace image with a distro other than Ubuntu.
|
||||
|
||||
```terraform
|
||||
command = ["sh", "-c", <<EOF
|
||||
# Create user and setup home directory
|
||||
sudo useradd ${data.coder_workspace_owner.me.name} --home=/home/${data.coder_workspace_owner.me.name} --shell=/bin/bash --uid=1001 --user-group
|
||||
sudo chown -R ${data.coder_workspace_owner.me.name}:${data.coder_workspace_owner.me.name} /home/${data.coder_workspace_owner.me.name}
|
||||
|
||||
# Switch to user and run agent
|
||||
exec sudo --preserve-env=CODER_AGENT_TOKEN -u ${data.coder_workspace_owner.me.name} sh -c '${coder_agent.main.init_script}'
|
||||
EOF
|
||||
]
|
||||
```
|
||||
|
||||
<!-- TODO: Add screenshot -->
|
||||
|
||||
## Prerequisites
|
||||
|
||||
### Infrastructure
|
||||
|
||||
**Cluster**: This template requires an existing Kubernetes cluster
|
||||
|
||||
**Container Image**: This template uses the [codercom/enterprise-base:ubuntu image](https://github.com/coder/enterprise-images/tree/main/images/base) with some dev tools preinstalled. To add additional tools, extend this image or build it yourself.
|
||||
|
||||
### Authentication
|
||||
|
||||
This template authenticates using a `~/.kube/config`, if present on the server, or via built-in authentication if the Coder provisioner is running on Kubernetes with an authorized ServiceAccount. To use another [authentication method](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs#authentication), edit the template.
|
||||
|
||||
## Architecture
|
||||
|
||||
This template provisions the following resources:
|
||||
|
||||
- Kubernetes Deployment (ephemeral)
|
||||
- Kubernetes persistent volume claim (persistent on `/home/${username}`, where `${username}` is your Coder username)
|
||||
|
||||
This means, when the workspace restarts, any tools or files outside of the home directory are not persisted. To pre-bake tools into the workspace (e.g. `python3`), modify the container image. Alternatively, individual developers can [personalize](https://coder.com/docs/dotfiles) their workspaces with dotfiles.
|
||||
@@ -0,0 +1,327 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
}
|
||||
kubernetes = {
|
||||
source = "hashicorp/kubernetes"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "coder" {
|
||||
}
|
||||
|
||||
variable "use_kubeconfig" {
|
||||
type = bool
|
||||
description = <<-EOF
|
||||
Use host kubeconfig? (true/false)
|
||||
|
||||
Set this to false if the Coder host is itself running as a Pod on the same
|
||||
Kubernetes cluster as you are deploying workspaces to.
|
||||
|
||||
Set this to true if the Coder host is running outside the Kubernetes cluster
|
||||
for workspaces. A valid "~/.kube/config" must be present on the Coder host.
|
||||
EOF
|
||||
default = false
|
||||
}
|
||||
|
||||
variable "namespace" {
|
||||
type = string
|
||||
description = "The Kubernetes namespace to create workspaces in (must exist prior to creating workspaces). If the Coder host is itself running as a Pod on the same Kubernetes cluster as you are deploying workspaces to, set this to the same namespace."
|
||||
}
|
||||
|
||||
data "coder_parameter" "cpu" {
|
||||
name = "cpu"
|
||||
display_name = "CPU"
|
||||
description = "The number of CPU cores"
|
||||
default = "2"
|
||||
icon = "/icon/memory.svg"
|
||||
mutable = true
|
||||
option {
|
||||
name = "2 Cores"
|
||||
value = "2"
|
||||
}
|
||||
option {
|
||||
name = "4 Cores"
|
||||
value = "4"
|
||||
}
|
||||
option {
|
||||
name = "6 Cores"
|
||||
value = "6"
|
||||
}
|
||||
option {
|
||||
name = "8 Cores"
|
||||
value = "8"
|
||||
}
|
||||
}
|
||||
|
||||
data "coder_parameter" "memory" {
|
||||
name = "memory"
|
||||
display_name = "Memory"
|
||||
description = "The amount of memory in GB"
|
||||
default = "2"
|
||||
icon = "/icon/memory.svg"
|
||||
mutable = true
|
||||
option {
|
||||
name = "2 GB"
|
||||
value = "2"
|
||||
}
|
||||
option {
|
||||
name = "4 GB"
|
||||
value = "4"
|
||||
}
|
||||
option {
|
||||
name = "6 GB"
|
||||
value = "6"
|
||||
}
|
||||
option {
|
||||
name = "8 GB"
|
||||
value = "8"
|
||||
}
|
||||
}
|
||||
|
||||
data "coder_parameter" "home_disk_size" {
|
||||
name = "home_disk_size"
|
||||
display_name = "Home disk size"
|
||||
description = "The size of the home disk in GB"
|
||||
default = "10"
|
||||
type = "number"
|
||||
icon = "/emojis/1f4be.png"
|
||||
mutable = false
|
||||
validation {
|
||||
min = 1
|
||||
max = 99999
|
||||
}
|
||||
}
|
||||
|
||||
provider "kubernetes" {
|
||||
# Authenticate via ~/.kube/config or a Coder-specific ServiceAccount, depending on admin preferences
|
||||
config_path = var.use_kubeconfig == true ? "~/.kube/config" : null
|
||||
}
|
||||
|
||||
data "coder_workspace" "me" {}
|
||||
data "coder_workspace_owner" "me" {}
|
||||
|
||||
module "vscode-web" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
source = "registry.coder.com/coder/vscode-web/coder"
|
||||
version = "1.3.1"
|
||||
agent_id = coder_agent.main.id
|
||||
accept_license = true
|
||||
}
|
||||
|
||||
resource "coder_agent" "main" {
|
||||
os = "linux"
|
||||
arch = "amd64"
|
||||
|
||||
# The following metadata blocks are optional. They are used to display
|
||||
# information about your workspace in the dashboard. You can remove them
|
||||
# if you don't want to display any information.
|
||||
# For basic resources, you can use the `coder stat` command.
|
||||
# If you need more control, you can write your own script.
|
||||
metadata {
|
||||
display_name = "CPU Usage"
|
||||
key = "0_cpu_usage"
|
||||
script = "coder stat cpu"
|
||||
interval = 10
|
||||
timeout = 1
|
||||
}
|
||||
|
||||
metadata {
|
||||
display_name = "RAM Usage"
|
||||
key = "1_ram_usage"
|
||||
script = "coder stat mem"
|
||||
interval = 10
|
||||
timeout = 1
|
||||
}
|
||||
|
||||
metadata {
|
||||
display_name = "Home Disk"
|
||||
key = "3_home_disk"
|
||||
script = "coder stat disk --path $${HOME}"
|
||||
interval = 60
|
||||
timeout = 1
|
||||
}
|
||||
|
||||
metadata {
|
||||
display_name = "CPU Usage (Host)"
|
||||
key = "4_cpu_usage_host"
|
||||
script = "coder stat cpu --host"
|
||||
interval = 10
|
||||
timeout = 1
|
||||
}
|
||||
|
||||
metadata {
|
||||
display_name = "Memory Usage (Host)"
|
||||
key = "5_mem_usage_host"
|
||||
script = "coder stat mem --host"
|
||||
interval = 10
|
||||
timeout = 1
|
||||
}
|
||||
|
||||
metadata {
|
||||
display_name = "Load Average (Host)"
|
||||
key = "6_load_host"
|
||||
# get load avg scaled by number of cores
|
||||
script = <<EOT
|
||||
echo "`cat /proc/loadavg | awk '{ print $1 }'` `nproc`" | awk '{ printf "%0.2f", $1/$2 }'
|
||||
EOT
|
||||
interval = 60
|
||||
timeout = 1
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_persistent_volume_claim" "home" {
|
||||
metadata {
|
||||
name = "coder-${data.coder_workspace.me.id}-home"
|
||||
namespace = var.namespace
|
||||
labels = {
|
||||
"app.kubernetes.io/name" = "coder-pvc"
|
||||
"app.kubernetes.io/instance" = "coder-pvc-${data.coder_workspace.me.id}"
|
||||
"app.kubernetes.io/part-of" = "coder"
|
||||
//Coder-specific labels.
|
||||
"com.coder.resource" = "true"
|
||||
"com.coder.workspace.id" = data.coder_workspace.me.id
|
||||
"com.coder.workspace.name" = data.coder_workspace.me.name
|
||||
"com.coder.user.id" = data.coder_workspace_owner.me.id
|
||||
"com.coder.user.username" = data.coder_workspace_owner.me.name
|
||||
}
|
||||
annotations = {
|
||||
"com.coder.user.email" = data.coder_workspace_owner.me.email
|
||||
}
|
||||
}
|
||||
wait_until_bound = false
|
||||
spec {
|
||||
access_modes = ["ReadWriteOnce"]
|
||||
resources {
|
||||
requests = {
|
||||
storage = "${data.coder_parameter.home_disk_size.value}Gi"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_deployment" "main" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
depends_on = [
|
||||
kubernetes_persistent_volume_claim.home
|
||||
]
|
||||
wait_for_rollout = false
|
||||
metadata {
|
||||
name = "coder-${data.coder_workspace.me.id}"
|
||||
namespace = var.namespace
|
||||
labels = {
|
||||
"app.kubernetes.io/name" = "coder-workspace"
|
||||
"app.kubernetes.io/instance" = "coder-workspace-${data.coder_workspace.me.id}"
|
||||
"app.kubernetes.io/part-of" = "coder"
|
||||
"com.coder.resource" = "true"
|
||||
"com.coder.workspace.id" = data.coder_workspace.me.id
|
||||
"com.coder.workspace.name" = data.coder_workspace.me.name
|
||||
"com.coder.user.id" = data.coder_workspace_owner.me.id
|
||||
"com.coder.user.username" = data.coder_workspace_owner.me.name
|
||||
}
|
||||
annotations = {
|
||||
"com.coder.user.email" = data.coder_workspace_owner.me.email
|
||||
}
|
||||
}
|
||||
|
||||
spec {
|
||||
replicas = 1
|
||||
selector {
|
||||
match_labels = {
|
||||
"app.kubernetes.io/name" = "coder-workspace"
|
||||
"app.kubernetes.io/instance" = "coder-workspace-${data.coder_workspace.me.id}"
|
||||
"app.kubernetes.io/part-of" = "coder"
|
||||
"com.coder.resource" = "true"
|
||||
"com.coder.workspace.id" = data.coder_workspace.me.id
|
||||
"com.coder.workspace.name" = data.coder_workspace.me.name
|
||||
"com.coder.user.id" = data.coder_workspace_owner.me.id
|
||||
"com.coder.user.username" = data.coder_workspace_owner.me.name
|
||||
}
|
||||
}
|
||||
strategy {
|
||||
type = "Recreate"
|
||||
}
|
||||
|
||||
template {
|
||||
metadata {
|
||||
labels = {
|
||||
"app.kubernetes.io/name" = "coder-workspace"
|
||||
"app.kubernetes.io/instance" = "coder-workspace-${data.coder_workspace.me.id}"
|
||||
"app.kubernetes.io/part-of" = "coder"
|
||||
"com.coder.resource" = "true"
|
||||
"com.coder.workspace.id" = data.coder_workspace.me.id
|
||||
"com.coder.workspace.name" = data.coder_workspace.me.name
|
||||
"com.coder.user.id" = data.coder_workspace_owner.me.id
|
||||
"com.coder.user.username" = data.coder_workspace_owner.me.name
|
||||
}
|
||||
}
|
||||
spec {
|
||||
|
||||
|
||||
container {
|
||||
name = "dev"
|
||||
image = "codercom/enterprise-base:ubuntu"
|
||||
image_pull_policy = "Always"
|
||||
command = ["sh", "-c", <<EOF
|
||||
# Create user and setup home directory
|
||||
sudo useradd ${lower(data.coder_workspace_owner.me.name)} --home=/home/${lower(data.coder_workspace_owner.me.name)} --shell=/bin/bash --uid=1001 --user-group
|
||||
sudo chown -R ${lower(data.coder_workspace_owner.me.name)}:${lower(data.coder_workspace_owner.me.name)} /home/${lower(data.coder_workspace_owner.me.name)}
|
||||
|
||||
# Switch to user and run agent
|
||||
exec sudo --preserve-env=CODER_AGENT_TOKEN -u ${lower(data.coder_workspace_owner.me.name)} sh -c '${coder_agent.main.init_script}'
|
||||
EOF
|
||||
]
|
||||
env {
|
||||
name = "CODER_AGENT_TOKEN"
|
||||
value = coder_agent.main.token
|
||||
}
|
||||
resources {
|
||||
requests = {
|
||||
"cpu" = "250m"
|
||||
"memory" = "512Mi"
|
||||
}
|
||||
limits = {
|
||||
"cpu" = "${data.coder_parameter.cpu.value}"
|
||||
"memory" = "${data.coder_parameter.memory.value}Gi"
|
||||
}
|
||||
}
|
||||
volume_mount {
|
||||
mount_path = "/home/${lower(data.coder_workspace_owner.me.name)}"
|
||||
name = "home"
|
||||
read_only = false
|
||||
}
|
||||
}
|
||||
|
||||
volume {
|
||||
name = "home"
|
||||
persistent_volume_claim {
|
||||
claim_name = kubernetes_persistent_volume_claim.home.metadata.0.name
|
||||
read_only = false
|
||||
}
|
||||
}
|
||||
|
||||
affinity {
|
||||
// This affinity attempts to spread out all workspace pods evenly across
|
||||
// nodes.
|
||||
pod_anti_affinity {
|
||||
preferred_during_scheduling_ignored_during_execution {
|
||||
weight = 1
|
||||
pod_affinity_term {
|
||||
topology_key = "kubernetes.io/hostname"
|
||||
label_selector {
|
||||
match_expressions {
|
||||
key = "app.kubernetes.io/name"
|
||||
operator = "In"
|
||||
values = ["coder-workspace"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Find all directories that contain any .tftest.hcl files and run terraform test in each
|
||||
|
||||
run_dir() {
|
||||
local dir="$1"
|
||||
echo "==> Running terraform test in $dir"
|
||||
(cd "$dir" && terraform init -upgrade -input=false -no-color > /dev/null && terraform test -no-color -verbose)
|
||||
}
|
||||
|
||||
mapfile -t test_dirs < <(find . -type f -name "*.tftest.hcl" -print0 | xargs -0 -I{} dirname {} | sort -u)
|
||||
|
||||
if [[ ${#test_dirs[@]} -eq 0 ]]; then
|
||||
echo "No .tftest.hcl tests found."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
status=0
|
||||
for d in "${test_dirs[@]}"; do
|
||||
if ! run_dir "$d"; then
|
||||
status=1
|
||||
fi
|
||||
done
|
||||
|
||||
exit $status
|
||||
Reference in New Issue
Block a user