Resolves the IP address of the proxy container on the specified network. Inspects the running proxy container and extracts the IP address assigned on the given network. This IP is used for `extra_hosts` entries so the proxy hostname resolves inside agent containers even in nested network namespaces (e.g., Podman builds). Callers should pass the **agent network** name so the returned IP is routab
(
&self,
container_name: &str,
network_name: &str,
)
| 236 | /// Callers should pass the **agent network** name so the returned IP is |
| 237 | /// routable from the agent container. |
| 238 | pub(crate) async fn resolve_proxy_ip( |
| 239 | &self, |
| 240 | container_name: &str, |
| 241 | network_name: &str, |
| 242 | ) -> Result<String> { |
| 243 | let json_data = self |
| 244 | .docker_client |
| 245 | .inspect_container(container_name) |
| 246 | .await |
| 247 | .map_err(|e| anyhow::anyhow!("Failed to inspect proxy container: {e}"))?; |
| 248 | |
| 249 | let data: serde_json::Value = serde_json::from_str(&json_data) |
| 250 | .context("Failed to parse proxy container inspect data")?; |
| 251 | |
| 252 | let ip = data |
| 253 | .get("NetworkSettings") |
| 254 | .and_then(|ns| ns.get("Networks")) |
| 255 | .and_then(|n| n.get(network_name)) |
| 256 | .and_then(|net| net.get("IPAddress")) |
| 257 | .and_then(|ip| ip.as_str()) |
| 258 | .filter(|ip| !ip.is_empty()) |
| 259 | .ok_or_else(|| { |
| 260 | anyhow::anyhow!( |
| 261 | "Could not resolve IP for proxy container '{container_name}' on network '{network_name}'" |
| 262 | ) |
| 263 | })?; |
| 264 | |
| 265 | Ok(ip.to_string()) |
| 266 | } |
| 267 | |
| 268 | /// Builds the generic proxy Docker image. |
| 269 | /// |