Mount host repositories for Docker execution with host user ownership

This commit is contained in:
2026-10-10 01:22:02 +01:00
parent 7565693957
commit 68042aad5d
10 changed files with 161 additions and 12 deletions
+37
View File
@@ -51,6 +51,41 @@ class DockerSetupTests(unittest.TestCase):
with patch.object(setup.shutil,"which",return_value="/fixture/go"), self.assertRaises(ValueError):
setup.Setup(".",runner=runner).verify_host_endpoint("ws://127.0.0.1:8081/connect")
def test_workspace_mount_uses_host_home_uid_and_preserves_settings(self):
with tempfile.TemporaryDirectory() as directory:
path=Path(directory,".env");path.write_text("CUSTOM=keep\nPIPELINES_UID=10001\n")
setup.Setup(directory).configure_workspaces()
content=path.read_text()
self.assertIn("CUSTOM=keep\n",content)
self.assertIn("PIPELINES_HOST_HOME='"+str(Path.home().resolve())+"'",content)
self.assertIn("PIPELINES_UID="+str(os.getuid()),content)
self.assertIn("PIPELINES_GID="+str(os.getgid()),content)
setup.Setup(directory).configure_workspaces()
self.assertEqual(path.read_text(),content)
def test_ownership_migration_and_workspace_verification_are_scoped(self):
calls=[]
def runner(command,**kwargs):
calls.append(command)
config={"services":{"pipelines":{"volumes":[{"type":"volume","target":target} for target in ["/data","/home/pipelines","/workspace"]]}}}
return subprocess.CompletedProcess(command,0,stdout=setup.json.dumps(config) if "--format" in command else "",stderr="")
installer=setup.Setup(".",runner=runner)
installer.prepare_volume_ownership()
installer.verify_workspace()
self.assertIn("0:0",calls[1])
self.assertEqual(calls[1][-1], 'set -eu; chown -R "$PIPELINES_UID:$PIPELINES_GID" /data /home/pipelines /workspace')
self.assertEqual(calls[2][-1],str(Path(".").resolve()))
self.assertIn('cd "$1"',calls[2][-3])
def test_ownership_migration_never_chowns_host_bind_mounts(self):
calls=[]
def runner(command,**kwargs):
calls.append(command)
return subprocess.CompletedProcess(command,0,stdout='{"services":{"pipelines":{"volumes":[{"type":"bind","target":"/data"}]}}}',stderr="")
with self.assertRaises(ValueError): setup.Setup(".",runner=runner).prepare_volume_ownership()
self.assertEqual(len(calls),1)
self.assertFalse(any("chown" in part for part in calls[0]))
def test_validation_primes_its_own_service_and_passes_model_as_argument(self):
with tempfile.TemporaryDirectory() as directory:
root=Path(directory);(root/".env").write_text("CUSTOM=keep\n")
@@ -264,6 +299,8 @@ fi
out = '{"ntfy":{"health":"healthy","url":"http://192.168.1.20:8090"},"topic":"pipelines"}'
if args[:1] == ["port"]:
out = "127.0.0.1:8081\n"
if args == ["config", "--format", "json"]:
out = setup.json.dumps({"services":{"pipelines":{"volumes":[{"type":"volume","target":target} for target in ["/data","/home/pipelines","/workspace"]]}}})
if fail and (fail in args or (fail=="login" and "exec opencode auth login" in args[-1]) or (fail=="provider-check" and any("provider-check" in arg for arg in args))):
code, out = 9, "private provider data/token"
if fail == "host" and command[0] != "docker" and args[-2:] == ["status", "--json"]: