diff --git a/registry/coder/modules/agentapi/main.tf b/registry/coder/modules/agentapi/main.tf index e2d3c901..df1d35a9 100644 --- a/registry/coder/modules/agentapi/main.tf +++ b/registry/coder/modules/agentapi/main.tf @@ -191,6 +191,21 @@ variable "agentapi_subdomain" { variable "module_dir_name" { type = string description = "Name of the subdirectory in the home directory for module files." + default = null + validation { + condition = var.module_dir_name == null || var.module_dir_path == null + error_message = "Cannot set both module_dir_name and module_dir_path. Please set only one of them to specify the module directory location." + } +} + +variable "module_dir_path" { + type = string + description = "Path to the module directory." + default = null + validation { + condition = var.module_dir_name == null || var.module_dir_path == null + error_message = "Cannot set both module_dir_name and module_dir_path. Please set only one of them to specify the module directory location." + } } variable "enable_boundary" { @@ -267,7 +282,7 @@ locals { agentapi_main_script_name = "${var.agent_name}-main_script" - module_dir_path = "$HOME/${var.module_dir_name}" + module_dir_path = var.module_dir_path == null ? "$HOME/.coder-modules/coder/${var.module_dir_name}" : var.module_dir_path } module "agent-helper" { @@ -283,6 +298,25 @@ module "agent-helper" { start_script = var.start_script } +resource "coder_script" "boundary" { + count = var.enable_boundary ? 1 : 0 + agent_id = "" + display_name = "" + script = < /tmp/boundary.sh + chmod +x /tmp/boundary.sh + + ARG_ENABLE_BOUNDARY='${var.enable_boundary}' \ + ARG_BOUNDARY_VERSION='${var.boundary_version}' \ + ARG_COMPILE_BOUNDARY_FROM_SOURCE='${var.compile_boundary_from_source}' \ + ARG_USE_BOUNDARY_DIRECTLY='${var.use_boundary_directly}' \ + /tmp/boundary.sh + EOT +} + resource "coder_script" "agentapi" { count = var.enable_agentapi ? 1 : 0 agent_id = var.agent_id @@ -317,10 +351,6 @@ resource "coder_script" "agentapi" { ARG_AGENTAPI_CHAT_BASE_PATH='${local.agentapi_chat_base_path}' \ ARG_TASK_ID='${try(data.coder_task.me.id, "")}' \ ARG_TASK_LOG_SNAPSHOT='${var.task_log_snapshot}' \ - ARG_ENABLE_BOUNDARY='${var.enable_boundary}' \ - ARG_BOUNDARY_VERSION='${var.boundary_version}' \ - ARG_COMPILE_BOUNDARY_FROM_SOURCE='${var.compile_boundary_from_source}' \ - ARG_USE_BOUNDARY_DIRECTLY='${var.use_boundary_directly}' \ ARG_ENABLE_STATE_PERSISTENCE='${var.enable_state_persistence}' \ ARG_STATE_FILE_PATH='${var.state_file_path}' \ ARG_PID_FILE_PATH='${var.pid_file_path}' \ diff --git a/registry/coder/modules/agentapi/scripts/agentapi-wait-for-start.sh b/registry/coder/modules/agentapi/scripts/agentapi-wait-for-start.sh index 6ae5b14a..084677ff 100644 --- a/registry/coder/modules/agentapi/scripts/agentapi-wait-for-start.sh +++ b/registry/coder/modules/agentapi/scripts/agentapi-wait-for-start.sh @@ -11,14 +11,14 @@ max_attempts=150 agentapi_started=false -echo "Waiting for agentapi server to start on port $port..." -for i in $(seq 1 "$max_attempts"); do +echo "Waiting for agentapi server to start on port ${port}..." +for i in $(seq 1 "${max_attempts}"); do for j in $(seq 1 3); do sleep 0.1 - if curl -fs -o /dev/null "http://localhost:$port/status"; then - echo "agentapi response received ($j/3)" + if curl -fs -o /dev/null "http://localhost:${port}/status"; then + echo "agentapi response received (${j}/3)" else - echo "agentapi server not responding ($i/$max_attempts)" + echo "agentapi server not responding (${i}/${max_attempts})" continue 2 fi done @@ -26,9 +26,9 @@ for i in $(seq 1 "$max_attempts"); do break done -if [ "$agentapi_started" != "true" ]; then - echo "Error: agentapi server did not start on port $port after $max_attempts attempts." +if [[ "${agentapi_started}" != "true" ]]; then + echo "Error: agentapi server did not start on port ${port} after ${max_attempts} attempts." exit 1 fi -echo "agentapi server started on port $port." +echo "agentapi server started on port ${port}." diff --git a/registry/coder/modules/agentapi/scripts/main.sh b/registry/coder/modules/agentapi/scripts/main.sh index 9e68f29b..824441fb 100644 --- a/registry/coder/modules/agentapi/scripts/main.sh +++ b/registry/coder/modules/agentapi/scripts/main.sh @@ -118,7 +118,6 @@ if [ "${ENABLE_STATE_PERSISTENCE}" = "true" ]; then echo "Warning: State persistence requires agentapi >= v0.12.0 (current: ${actual_version:-unknown}), skipping." fi fi -nohup "$module_path/scripts/agentapi-start.sh" true "${AGENTAPI_PORT}" &> "$module_path/agentapi-start.log" & # Build agentapi server command arguments ARGS=(