fix(cloudflared): replace broken --bind-addr at runtime + new migration
Problem: The first migration already ran on the user's server with --bind-addr (broken). Alembic won't re-run the fixed migration. Changes: - _ensure_web_bind_address(): Now detects existing --bind-addr commands and replaces them with --host 0.0.0.0 instead of skipping - New migration 2026_05_29_fix_code_server_bind_addr: Finds code-server tool types with --bind-addr in compose_template and replaces with --host 0.0.0.0 Quality gates: pytest 42 passed (2 pre-existing unrelated failures)
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
"""fix code-server bind-addr to host in DB template
|
||||
|
||||
Revision ID: 2026_05_29_fix_code_server_bind_addr
|
||||
Revises: 2026_05_29_fix_web_tool_bind_address
|
||||
Create Date: 2026-05-29 15:00:00.000000
|
||||
|
||||
"""
|
||||
from typing import Sequence
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "2026_05_29_fix_code_server_bind_addr"
|
||||
down_revision: str | None = "2026_05_29_fix_web_tool_bind_address"
|
||||
branch_labels: Sequence[str] | None = None
|
||||
depends_on: Sequence[str] | None = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
conn = op.get_bind()
|
||||
|
||||
# Find code-server tool types with broken --bind-addr in compose template
|
||||
result = conn.execute(
|
||||
sa.text("""
|
||||
SELECT id, compose_template
|
||||
FROM tool_types
|
||||
WHERE name = 'code-server'
|
||||
AND compose_template LIKE '%--bind-addr%'
|
||||
""")
|
||||
).fetchall()
|
||||
|
||||
for tool_id, compose_template in result:
|
||||
updated = compose_template.replace(
|
||||
"--bind-addr 0.0.0.0:8443", "--host 0.0.0.0"
|
||||
).replace(
|
||||
"--bind-addr", "--host 0.0.0.0"
|
||||
)
|
||||
|
||||
conn.execute(
|
||||
sa.text("""
|
||||
UPDATE tool_types
|
||||
SET compose_template = :compose_template
|
||||
WHERE id = :id
|
||||
"""),
|
||||
{"compose_template": updated, "id": tool_id},
|
||||
)
|
||||
|
||||
print(f"Fixed code-server template ({tool_id}): replaced --bind-addr with --host")
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
pass
|
||||
Reference in New Issue
Block a user