feat(git-gate): plumb ExtraHosts through to docker --add-host
GitGateUpstream carries each entry's extra_hosts; a new git_gate_aggregate_extra_hosts() merges them into one map for the gate container's /etc/hosts. Same host -> same IP is harmless duplication; same host -> different IPs is a manifest bug (/etc/hosts is per-container, not per-upstream) and dies with the conflicting upstream names. DockerGitGate.start passes one --add-host host:ip per merged entry on docker create. Empty map (the default) emits no flags and is a no-op for bottles that don't need DNS overrides.
This commit is contained in:
@@ -9,12 +9,15 @@ from claude_bottle.git_gate import (
|
||||
GitGate,
|
||||
GitGatePlan,
|
||||
GitGateUpstream,
|
||||
git_gate_aggregate_extra_hosts,
|
||||
git_gate_known_hosts_line,
|
||||
git_gate_render_access_hook,
|
||||
git_gate_render_entrypoint,
|
||||
git_gate_render_hook,
|
||||
git_gate_upstreams_for_bottle,
|
||||
)
|
||||
from claude_bottle.log import Die
|
||||
from claude_bottle.manifest import Manifest
|
||||
from tests.fixtures import fixture_minimal, fixture_with_git
|
||||
|
||||
|
||||
@@ -43,6 +46,84 @@ class TestUpstreamsForBottle(unittest.TestCase):
|
||||
self.assertEqual((), git_gate_upstreams_for_bottle(bottle))
|
||||
|
||||
|
||||
class TestExtraHostsPlumbing(unittest.TestCase):
|
||||
def test_upstream_carries_extra_hosts_from_manifest(self):
|
||||
m = Manifest.from_json_obj({
|
||||
"bottles": {
|
||||
"dev": {
|
||||
"git": [{
|
||||
"Name": "claude-bottle",
|
||||
"Upstream": "ssh://git@gitea.dideric.is:30009/didericis/claude-bottle.git",
|
||||
"IdentityFile": "/dev/null",
|
||||
"ExtraHosts": {"gitea.dideric.is": "100.78.141.42"},
|
||||
}],
|
||||
},
|
||||
},
|
||||
"agents": {"demo": {"skills": [], "prompt": "", "bottle": "dev"}},
|
||||
})
|
||||
ups = git_gate_upstreams_for_bottle(m.bottles["dev"])
|
||||
self.assertEqual(
|
||||
{"gitea.dideric.is": "100.78.141.42"}, dict(ups[0].extra_hosts)
|
||||
)
|
||||
|
||||
def test_aggregator_merges_distinct_hostnames(self):
|
||||
ups = (
|
||||
GitGateUpstream(
|
||||
name="a", upstream_url="", upstream_host="", upstream_port="",
|
||||
identity_file="", known_host_key="",
|
||||
extra_hosts={"a.example": "10.0.0.1"},
|
||||
),
|
||||
GitGateUpstream(
|
||||
name="b", upstream_url="", upstream_host="", upstream_port="",
|
||||
identity_file="", known_host_key="",
|
||||
extra_hosts={"b.example": "10.0.0.2"},
|
||||
),
|
||||
)
|
||||
self.assertEqual(
|
||||
{"a.example": "10.0.0.1", "b.example": "10.0.0.2"},
|
||||
git_gate_aggregate_extra_hosts(ups),
|
||||
)
|
||||
|
||||
def test_aggregator_allows_same_host_same_ip(self):
|
||||
# Two entries listing the same host:ip is harmless duplication,
|
||||
# not a conflict. The gate's /etc/hosts ends up with one line.
|
||||
ups = (
|
||||
GitGateUpstream(
|
||||
name="a", upstream_url="", upstream_host="", upstream_port="",
|
||||
identity_file="", known_host_key="",
|
||||
extra_hosts={"gitea.dideric.is": "100.78.141.42"},
|
||||
),
|
||||
GitGateUpstream(
|
||||
name="b", upstream_url="", upstream_host="", upstream_port="",
|
||||
identity_file="", known_host_key="",
|
||||
extra_hosts={"gitea.dideric.is": "100.78.141.42"},
|
||||
),
|
||||
)
|
||||
self.assertEqual(
|
||||
{"gitea.dideric.is": "100.78.141.42"},
|
||||
git_gate_aggregate_extra_hosts(ups),
|
||||
)
|
||||
|
||||
def test_aggregator_rejects_conflicting_ips(self):
|
||||
ups = (
|
||||
GitGateUpstream(
|
||||
name="a", upstream_url="", upstream_host="", upstream_port="",
|
||||
identity_file="", known_host_key="",
|
||||
extra_hosts={"gitea.dideric.is": "100.78.141.42"},
|
||||
),
|
||||
GitGateUpstream(
|
||||
name="b", upstream_url="", upstream_host="", upstream_port="",
|
||||
identity_file="", known_host_key="",
|
||||
extra_hosts={"gitea.dideric.is": "10.0.0.99"},
|
||||
),
|
||||
)
|
||||
with self.assertRaises(Die):
|
||||
git_gate_aggregate_extra_hosts(ups)
|
||||
|
||||
def test_aggregator_empty_is_empty(self):
|
||||
self.assertEqual({}, git_gate_aggregate_extra_hosts(()))
|
||||
|
||||
|
||||
class TestKnownHostsLine(unittest.TestCase):
|
||||
def test_default_port_unbracketed(self):
|
||||
line = git_gate_known_hosts_line("github.com", "22", "ssh-ed25519 AAAA")
|
||||
|
||||
Reference in New Issue
Block a user