Mount host repositories for Docker execution with host user ownership
This commit is contained in:
@@ -25,6 +25,12 @@ def host_timezone():
|
||||
continue
|
||||
raise ValueError("Cannot detect the host timezone; provide --timezone explicitly")
|
||||
|
||||
def host_workspaces(directory):
|
||||
home, repository = str(Path.home().resolve()), str(Path(directory).resolve())
|
||||
if any(any(char in value for char in "\r\n\x00$#'\"\\") or value in ("/", "/data", "/workspace", "/home/pipelines") for value in [home, repository]) or home == repository:
|
||||
raise ValueError("Host home/checkout cannot be mounted safely at its original path; configure a repository bind mount explicitly")
|
||||
return {"PIPELINES_HOST_HOME": "'"+home+"'", "PIPELINES_HOST_REPOSITORY": "'"+repository+"'", "PIPELINES_UID": str(os.getuid()), "PIPELINES_GID": str(os.getgid())}
|
||||
|
||||
|
||||
def configure(directory, ntfy_url, bind_address, timezone=None, port=8081):
|
||||
directory = Path(directory)
|
||||
@@ -42,6 +48,7 @@ def configure(directory, ntfy_url, bind_address, timezone=None, port=8081):
|
||||
settings = directory / ".env"
|
||||
if settings.exists():
|
||||
raise ValueError(".env exists; edit it rather than overwrite existing settings")
|
||||
workspace_values = host_workspaces(directory)
|
||||
secrets = directory / "secrets"
|
||||
secrets.mkdir(mode=0o700, exist_ok=True)
|
||||
token = secrets / "ntfy-token.txt"
|
||||
@@ -53,7 +60,8 @@ def configure(directory, ntfy_url, bind_address, timezone=None, port=8081):
|
||||
pass
|
||||
with settings.open("x") as file:
|
||||
file.write(f"TZ={timezone}\nNTFY_BASE_URL={ntfy_url.rstrip('/')}\n"
|
||||
f"NTFY_BIND_ADDRESS={bind_address}\nPIPELINES_PORT={port}\n")
|
||||
f"NTFY_BIND_ADDRESS={bind_address}\nPIPELINES_PORT={port}\n")
|
||||
for key, value in workspace_values.items(): file.write(key+"="+value+"\n")
|
||||
return timezone
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user