fix(cloudflare): use correct container port in tunnel config

Cloudflared was hardcoded to route to port 8080, but containers
listen on different ports (8443 for code-server, 8888 for jupyter).

- Add instance_port parameter to create_tunnel and update_cloudflared_config
- Fetch tool type default_port when creating tunnels
- Route to correct internal port instead of hardcoded 8080
This commit is contained in:
Fusion
2026-05-20 15:23:39 +02:00
parent d11b43b69f
commit 1d33735e2f
2 changed files with 15 additions and 1 deletions
+10
View File
@@ -402,11 +402,16 @@ async def start_instance(
instance.last_started_at = datetime.now()
await session.commit()
# Get tool type for default port
tool_type = await session.get(ToolType, instance.tool_type_id)
instance_port = tool_type.default_port if tool_type and tool_type.default_port else 8080
# Create Cloudflare tunnel for public access
try:
tunnel_info = await create_tunnel(
instance_name=instance.name,
instance_id=str(instance.id),
instance_port=instance_port,
)
instance.tunnel_id = tunnel_info["tunnel_id"]
instance.public_url = tunnel_info["public_url"]
@@ -539,11 +544,16 @@ async def restart_instance(
instance.status = "running"
instance.last_started_at = datetime.now()
# Get tool type for default port
tool_type = await session.get(ToolType, instance.tool_type_id)
instance_port = tool_type.default_port if tool_type and tool_type.default_port else 8080
# Create new tunnel
try:
tunnel_info = await create_tunnel(
instance_name=instance.name,
instance_id=str(instance.id),
instance_port=instance_port,
)
instance.tunnel_id = tunnel_info["tunnel_id"]
instance.public_url = tunnel_info["public_url"]
+5 -1
View File
@@ -25,6 +25,7 @@ def _get_headers(settings: Settings) -> dict[str, str]:
async def create_tunnel(
instance_name: str,
instance_id: str,
instance_port: int = 8080,
settings: Settings | None = None,
) -> dict[str, str]:
"""Create a Cloudflare tunnel for an instance.
@@ -32,6 +33,7 @@ async def create_tunnel(
Args:
instance_name: Name of the instance (used for tunnel name)
instance_id: UUID of the instance
instance_port: Internal port the container listens on
settings: Optional settings override
Returns:
@@ -97,6 +99,7 @@ async def create_tunnel(
tunnel_token=tunnel_token,
hostname=hostname,
instance_name=instance_name,
instance_port=instance_port,
settings=settings,
)
@@ -161,6 +164,7 @@ async def update_cloudflared_config(
tunnel_token: str,
hostname: str,
instance_name: str,
instance_port: int = 8080,
settings: Settings | None = None,
) -> None:
"""Update the cloudflared config.yml with a new tunnel.
@@ -206,7 +210,7 @@ async def update_cloudflared_config(
# Add ingress rule for this instance
ingress_rule = {
"hostname": hostname,
"service": f"http://{instance_name}:8080",
"service": f"http://{instance_name}:{instance_port}",
}
# Remove existing rule for this hostname if present