wip
This commit is contained in:
parent
b92045181e
commit
65c6d67547
@ -191,6 +191,21 @@ variable "agentapi_subdomain" {
|
|||||||
variable "module_dir_name" {
|
variable "module_dir_name" {
|
||||||
type = string
|
type = string
|
||||||
description = "Name of the subdirectory in the home directory for module files."
|
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" {
|
variable "enable_boundary" {
|
||||||
@ -267,7 +282,7 @@ locals {
|
|||||||
|
|
||||||
agentapi_main_script_name = "${var.agent_name}-main_script"
|
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" {
|
module "agent-helper" {
|
||||||
@ -283,6 +298,25 @@ module "agent-helper" {
|
|||||||
start_script = var.start_script
|
start_script = var.start_script
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resource "coder_script" "boundary" {
|
||||||
|
count = var.enable_boundary ? 1 : 0
|
||||||
|
agent_id = ""
|
||||||
|
display_name = ""
|
||||||
|
script = <<EOT
|
||||||
|
#!/bin/bash
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
|
echo -n '${base64encode(local.boundary_script)}' | base64 -d > /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" {
|
resource "coder_script" "agentapi" {
|
||||||
count = var.enable_agentapi ? 1 : 0
|
count = var.enable_agentapi ? 1 : 0
|
||||||
agent_id = var.agent_id
|
agent_id = var.agent_id
|
||||||
@ -317,10 +351,6 @@ resource "coder_script" "agentapi" {
|
|||||||
ARG_AGENTAPI_CHAT_BASE_PATH='${local.agentapi_chat_base_path}' \
|
ARG_AGENTAPI_CHAT_BASE_PATH='${local.agentapi_chat_base_path}' \
|
||||||
ARG_TASK_ID='${try(data.coder_task.me.id, "")}' \
|
ARG_TASK_ID='${try(data.coder_task.me.id, "")}' \
|
||||||
ARG_TASK_LOG_SNAPSHOT='${var.task_log_snapshot}' \
|
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_ENABLE_STATE_PERSISTENCE='${var.enable_state_persistence}' \
|
||||||
ARG_STATE_FILE_PATH='${var.state_file_path}' \
|
ARG_STATE_FILE_PATH='${var.state_file_path}' \
|
||||||
ARG_PID_FILE_PATH='${var.pid_file_path}' \
|
ARG_PID_FILE_PATH='${var.pid_file_path}' \
|
||||||
|
|||||||
@ -11,14 +11,14 @@ max_attempts=150
|
|||||||
|
|
||||||
agentapi_started=false
|
agentapi_started=false
|
||||||
|
|
||||||
echo "Waiting for agentapi server to start on port $port..."
|
echo "Waiting for agentapi server to start on port ${port}..."
|
||||||
for i in $(seq 1 "$max_attempts"); do
|
for i in $(seq 1 "${max_attempts}"); do
|
||||||
for j in $(seq 1 3); do
|
for j in $(seq 1 3); do
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
if curl -fs -o /dev/null "http://localhost:$port/status"; then
|
if curl -fs -o /dev/null "http://localhost:${port}/status"; then
|
||||||
echo "agentapi response received ($j/3)"
|
echo "agentapi response received (${j}/3)"
|
||||||
else
|
else
|
||||||
echo "agentapi server not responding ($i/$max_attempts)"
|
echo "agentapi server not responding (${i}/${max_attempts})"
|
||||||
continue 2
|
continue 2
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@ -26,9 +26,9 @@ for i in $(seq 1 "$max_attempts"); do
|
|||||||
break
|
break
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ "$agentapi_started" != "true" ]; then
|
if [[ "${agentapi_started}" != "true" ]]; then
|
||||||
echo "Error: agentapi server did not start on port $port after $max_attempts attempts."
|
echo "Error: agentapi server did not start on port ${port} after ${max_attempts} attempts."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "agentapi server started on port $port."
|
echo "agentapi server started on port ${port}."
|
||||||
|
|||||||
@ -118,7 +118,6 @@ if [ "${ENABLE_STATE_PERSISTENCE}" = "true" ]; then
|
|||||||
echo "Warning: State persistence requires agentapi >= v0.12.0 (current: ${actual_version:-unknown}), skipping."
|
echo "Warning: State persistence requires agentapi >= v0.12.0 (current: ${actual_version:-unknown}), skipping."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
nohup "$module_path/scripts/agentapi-start.sh" true "${AGENTAPI_PORT}" &> "$module_path/agentapi-start.log" &
|
|
||||||
|
|
||||||
# Build agentapi server command arguments
|
# Build agentapi server command arguments
|
||||||
ARGS=(
|
ARGS=(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user