fix(cloudflared): use --host 0.0.0.0 instead of --bind-addr for code-server
The --bind-addr flag caused code-server to fail entirely (app not responding on any interface). The correct override for the coder/code-server image is --host 0.0.0.0, which overrides the entrypoint's --host 127.0.0.1. Changes: - Migration: Replace --bind-addr with --host 0.0.0.0, also handle existing broken templates by detecting --bind-addr and replacing it - Runtime safety net: _ensure_web_bind_address uses --host 0.0.0.0 - Test fixture: Updated compose template to match Quality gates: pytest 42 passed
This commit is contained in:
@@ -5,6 +5,7 @@ Revises: 2026_05_29_remove_ssh_keys_mount_from_manifest
|
||||
Create Date: 2026-05-29 14:00:00.000000
|
||||
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
@@ -35,25 +36,32 @@ def _fix_code_server_compose(conn) -> None:
|
||||
if definition_type != "compose" or not compose_template:
|
||||
return
|
||||
|
||||
# Add command to bind to 0.0.0.0 if not already present
|
||||
if "command:" in compose_template:
|
||||
# Already has a command override, skip
|
||||
return
|
||||
|
||||
# Insert command line after the image line
|
||||
# Fix or add command to bind to 0.0.0.0
|
||||
lines = compose_template.split("\n")
|
||||
new_lines = []
|
||||
image_line_idx = -1
|
||||
command_fixed = False
|
||||
for i, line in enumerate(lines):
|
||||
# Replace broken --bind-addr with correct --host
|
||||
if "command:" in line and "--bind-addr" in line:
|
||||
indent = line[: len(line) - len(line.lstrip())]
|
||||
new_lines.append(f"{indent}command: --host 0.0.0.0")
|
||||
command_fixed = True
|
||||
continue
|
||||
new_lines.append(line)
|
||||
if "image:" in line and image_line_idx == -1:
|
||||
image_line_idx = i
|
||||
# Insert command with proper indentation (same as image line)
|
||||
indent = line[: len(line) - len(line.lstrip())]
|
||||
new_lines.append(f"{indent}command: --bind-addr 0.0.0.0:8443")
|
||||
|
||||
if image_line_idx == -1:
|
||||
# No image line found, can't safely modify
|
||||
# If no command line exists, insert one after image
|
||||
if not command_fixed and image_line_idx != -1:
|
||||
image_line = lines[image_line_idx]
|
||||
indent = image_line[: len(image_line) - len(image_line.lstrip())]
|
||||
# Insert after the image line in new_lines
|
||||
insert_idx = new_lines.index(image_line) + 1
|
||||
new_lines.insert(insert_idx, f"{indent}command: --host 0.0.0.0")
|
||||
command_fixed = True
|
||||
|
||||
if not command_fixed:
|
||||
return
|
||||
|
||||
updated_compose = "\n".join(new_lines)
|
||||
@@ -67,7 +75,7 @@ def _fix_code_server_compose(conn) -> None:
|
||||
{"compose_template": updated_compose, "id": tool_id},
|
||||
)
|
||||
|
||||
print(f"Updated code-server tool type ({tool_id}) to bind to 0.0.0.0:8443")
|
||||
print(f"Updated code-server tool type ({tool_id}) to bind to 0.0.0.0")
|
||||
|
||||
|
||||
def _fix_jupyter_compose(conn) -> None:
|
||||
@@ -100,7 +108,9 @@ def _fix_jupyter_compose(conn) -> None:
|
||||
image_line_idx = i
|
||||
indent = line[: len(line) - len(line.lstrip())]
|
||||
# Jupyter needs --ip=0.0.0.0 to bind to all interfaces
|
||||
new_lines.append(f'{indent}command: start-notebook.sh --ip=0.0.0.0 --port=8888 --no-browser')
|
||||
new_lines.append(
|
||||
f"{indent}command: start-notebook.sh --ip=0.0.0.0 --port=8888 --no-browser"
|
||||
)
|
||||
|
||||
if image_line_idx == -1:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user