Mount host repositories for Docker execution with host user ownership
This commit is contained in:
@@ -197,6 +197,34 @@ exec pipelines provider-check --model "$1" --yes --json --timeout 90s
|
||||
updated = updated.rstrip("\n")+"\n"+key+address+"\n"
|
||||
path.write_text(updated)
|
||||
|
||||
def configure_workspaces(self):
|
||||
home = str(Path.home().resolve())
|
||||
path = self.directory/".env"
|
||||
values = configure.host_workspaces(self.directory)
|
||||
lines = path.read_text().splitlines(keepends=True)
|
||||
text = "".join(key+"="+values[key]+"\n" if (key:=line.split("=",1)[0]) in values else line for line in lines)
|
||||
for key,value in values.items():
|
||||
if not any(line.startswith(key+"=") for line in lines): text=text.rstrip("\n")+"\n"+key+"="+value+"\n"
|
||||
path.write_text(text)
|
||||
print("Host repositories mounted at their original paths under " + home + "; server runs with host UID/GID. Stage tool/edit permissions still apply.")
|
||||
|
||||
def prepare_volume_ownership(self):
|
||||
# Existing volumes may belong to the old image UID 10001. Change only
|
||||
# ownership on container-managed data/auth volumes, never the host home.
|
||||
resolved = json.loads(self.compose("config", "--format", "json", capture=True).stdout)
|
||||
mounts = resolved.get("services", {}).get("pipelines", {}).get("volumes", [])
|
||||
for target in ("/data", "/home/pipelines", "/workspace"):
|
||||
if not any(mount.get("target") == target and mount.get("type") == "volume" for mount in mounts):
|
||||
raise ValueError("Refusing ownership migration: " + target + " is not a managed Docker volume; no host directory ownership was changed")
|
||||
self.compose("run", "--rm", "--no-deps", "-T", "--user", "0:0", "--entrypoint", "sh", "pipelines",
|
||||
"-c", 'set -eu; chown -R "$PIPELINES_UID:$PIPELINES_GID" /data /home/pipelines /workspace')
|
||||
|
||||
def verify_workspace(self):
|
||||
directory = str(self.directory.resolve())
|
||||
self.compose("exec", "-T", "pipelines", "sh", "-c", 'set -eu; test -d "$1"; test -r "$1"; test -x "$1"; cd "$1"; test "$(pwd -P)" = "$1"',
|
||||
"pipelines-workspace-check", directory, capture=True)
|
||||
print("Verified: Docker server can enter the host installation repository at " + directory)
|
||||
|
||||
def verify(self):
|
||||
# Read the token inside the container; never put it in argv or output.
|
||||
probe = '''set -eu
|
||||
@@ -275,17 +303,21 @@ printf 'header = "Authorization: Bearer %s"\\n' "$(cat "$PIPELINES_NTFY_TOKEN_FI
|
||||
self.compose("version", capture=True)
|
||||
self.settings(args)
|
||||
self.publish_address()
|
||||
self.configure_workspaces()
|
||||
self.update_host_client()
|
||||
# Validate the actual resolved Compose configuration before starting anything.
|
||||
self.compose("config", "--quiet", capture=True)
|
||||
self.compose("up", "-d", "--wait", "--wait-timeout", "60", "ntfy")
|
||||
self.bootstrap_ntfy()
|
||||
self.compose("build", "pipelines")
|
||||
self.compose("stop", "--timeout", "60", "pipelines")
|
||||
self.prepare_volume_ownership()
|
||||
self.compose("run", "--rm", "--no-deps", "-T", "--entrypoint", "pipelines", "pipelines", "skill", "install")
|
||||
self.authenticate(args.relogin)
|
||||
self.validate_provider(args)
|
||||
# Recreate to reload file secrets and environment, without deleting volumes.
|
||||
self.compose("up", "-d", "--force-recreate", "--wait", "--wait-timeout", "60", "pipelines")
|
||||
self.verify_workspace()
|
||||
self.verify()
|
||||
print("Docker setup complete. Use docker compose ps / logs to manage it; no OS user service was registered.")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user