Class: AgentHarness::DockerCommandExecutor
- Inherits:
-
CommandExecutor
- Object
- CommandExecutor
- AgentHarness::DockerCommandExecutor
- Defined in:
- lib/agent_harness/docker_command_executor.rb
Overview
Executes commands inside a Docker container
Wraps commands with ‘docker exec` so they run inside the specified container rather than on the host.
Instance Attribute Summary collapse
-
#container_id ⇒ Object
readonly
Returns the value of attribute container_id.
Attributes inherited from CommandExecutor
Instance Method Summary collapse
-
#execute(command, timeout: nil, env: {}, stdin_data: nil) ⇒ Result
Execute a command inside the Docker container.
-
#initialize(container_id:, logger: nil) ⇒ DockerCommandExecutor
constructor
Initialize the Docker command executor.
-
#which(binary) ⇒ String?
Check if a binary exists inside the container.
Methods inherited from CommandExecutor
Constructor Details
#initialize(container_id:, logger: nil) ⇒ DockerCommandExecutor
Initialize the Docker command executor
23 24 25 26 27 28 29 |
# File 'lib/agent_harness/docker_command_executor.rb', line 23 def initialize(container_id:, logger: nil) raise ArgumentError, "container_id cannot be nil or empty" if container_id.nil? || container_id.empty? super(logger: logger) @container_id = container_id validate_docker! end |
Instance Attribute Details
#container_id ⇒ Object (readonly)
Returns the value of attribute container_id.
16 17 18 |
# File 'lib/agent_harness/docker_command_executor.rb', line 16 def container_id @container_id end |
Instance Method Details
#execute(command, timeout: nil, env: {}, stdin_data: nil) ⇒ Result
Execute a command inside the Docker container
Wraps the given command with ‘docker exec` and delegates to the parent class for actual process execution.
41 42 43 44 |
# File 'lib/agent_harness/docker_command_executor.rb', line 41 def execute(command, timeout: nil, env: {}, stdin_data: nil) docker_cmd = build_docker_command(command, env: env, stdin_data: stdin_data) super(docker_cmd, timeout: timeout, env: {}, stdin_data: stdin_data) end |
#which(binary) ⇒ String?
Check if a binary exists inside the container
50 51 52 53 |
# File 'lib/agent_harness/docker_command_executor.rb', line 50 def which(binary) result = execute(["which", binary], timeout: 5) result.success? ? result.stdout.strip : nil end |