fix(tunnels): connect tool containers to backend network for cloudflared access
This commit is contained in:
@@ -23,18 +23,14 @@ from src.models.tool_instance import ToolInstance
|
|||||||
from src.models.tool_type import ToolType
|
from src.models.tool_type import ToolType
|
||||||
from src.models.user import User
|
from src.models.user import User
|
||||||
from src.services.docker import (
|
from src.services.docker import (
|
||||||
check_tunnel_health,
|
connect_container_to_network,
|
||||||
ensure_instance_directory,
|
ensure_instance_directory,
|
||||||
execute_compose_command,
|
execute_compose_command,
|
||||||
find_free_port,
|
find_free_port,
|
||||||
get_container_id,
|
get_container_id,
|
||||||
recreate_tunnel,
|
get_container_name,
|
||||||
start_cloudflared_tunnel,
|
start_cloudflared_tunnel,
|
||||||
stop_cloudflared_tunnel,
|
stop_cloudflared_tunnel,
|
||||||
get_container_name,
|
|
||||||
get_container_logs,
|
|
||||||
get_container_status,
|
|
||||||
render_compose_template,
|
|
||||||
write_compose_file,
|
write_compose_file,
|
||||||
write_config_files,
|
write_config_files,
|
||||||
write_env_file,
|
write_env_file,
|
||||||
@@ -411,6 +407,14 @@ async def start_instance(
|
|||||||
if container_name:
|
if container_name:
|
||||||
instance.container_name = container_name
|
instance.container_name = container_name
|
||||||
logger.info("Container name for instance %s: %s", instance.id, container_name)
|
logger.info("Container name for instance %s: %s", instance.id, container_name)
|
||||||
|
|
||||||
|
# Connect container to backend network so API can reach it
|
||||||
|
logger.info("Connecting container %s to backend network...", container_name)
|
||||||
|
connected = connect_container_to_network(container_name, "backend")
|
||||||
|
if connected:
|
||||||
|
logger.info("Successfully connected %s to backend network", container_name)
|
||||||
|
else:
|
||||||
|
logger.warning("Failed to connect %s to backend network", container_name)
|
||||||
|
|
||||||
instance.status = "running"
|
instance.status = "running"
|
||||||
instance.last_started_at = datetime.now()
|
instance.last_started_at = datetime.now()
|
||||||
|
|||||||
@@ -173,6 +173,24 @@ def get_container_name(instance_name: str) -> str | None:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def connect_container_to_network(container_name: str, network_name: str = "backend") -> bool:
|
||||||
|
"""Connect a Docker container to an existing network.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
container_name: Name or ID of the container
|
||||||
|
network_name: Name of the Docker network (default: backend)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True if successful, False otherwise
|
||||||
|
"""
|
||||||
|
result = subprocess.run(
|
||||||
|
["docker", "network", "connect", network_name, container_name],
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
|
return result.returncode == 0
|
||||||
|
|
||||||
|
|
||||||
def get_container_status(container_id: str) -> str:
|
def get_container_status(container_id: str) -> str:
|
||||||
"""Get the status of a Docker container.
|
"""Get the status of a Docker container.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user