05ae530442
Install current verified harness releases inside Docker, preserve persistent accounts and settings, and provide separate interactive and pipeline model defaults with terminal onboarding and fuzzy pickers. Add Docker-aware authoring transport, Pi stage execution, bounded workflow controls, reliable final-result readback and usage settlement, and finite short-lived CLI pipe draining. Keep dated installation evidence and packaged authoring guidance consistent. Verified with a real Docker installation, both harness stages and interactive authors, the built-in plan/implement/review starter, independent host race/vet checks, installer tests, and packaged skill tests. Generated release receipts stay ignored in clean checkouts.
91 lines
4.3 KiB
Python
91 lines
4.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Create local Compose settings without overwriting settings or credentials."""
|
|
import argparse
|
|
import os
|
|
from pathlib import Path
|
|
from urllib.parse import urlparse
|
|
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
|
|
|
|
|
|
def host_timezone():
|
|
candidates = [os.environ.get("TZ", "")]
|
|
link = str(Path("/etc/localtime").resolve())
|
|
if "/zoneinfo/" in link:
|
|
candidates.append(link.split("/zoneinfo/", 1)[1])
|
|
path = Path("/etc/timezone")
|
|
if path.exists():
|
|
candidates.append(path.read_text().strip())
|
|
for candidate in candidates:
|
|
if not candidate:
|
|
continue
|
|
try:
|
|
ZoneInfo(candidate)
|
|
return candidate
|
|
except (ZoneInfoNotFoundError, ValueError):
|
|
continue
|
|
raise ValueError("Cannot detect the host timezone; provide --timezone explicitly")
|
|
|
|
def host_workspaces(directory):
|
|
raw_home = os.environ.get("HOME") or os.environ.get("USERPROFILE") or str(Path.home())
|
|
home = str(Path.home().resolve())
|
|
repository = str(Path(directory).resolve())
|
|
# Reject both the raw and canonical resolved HOME so a platform's home alias
|
|
# (/home/pipelines on Linux; /System/Volumes/Data/home/pipelines on macOS)
|
|
# cannot bypass the reserved-path guard. Managed Docker volumes are separate
|
|
# and are not weakened by these cheap path comparisons.
|
|
candidates = {raw_home, home, str(Path(raw_home).resolve()), repository}
|
|
for value in candidates:
|
|
if any(char in value for char in "\r\n\x00$#'\"\\") or value in ("/", "/data", "/workspace", "/home/pipelines", "/System/Volumes/Data/home/pipelines"):
|
|
raise ValueError("Host home/checkout cannot be mounted safely at its original path; configure a repository bind mount explicitly")
|
|
if home == repository or str(Path(raw_home).resolve()) == 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)
|
|
url = urlparse(ntfy_url)
|
|
if (url.scheme not in ("http", "https") or not url.hostname or url.username
|
|
or url.password or url.query or url.fragment or url.path not in ("", "/")):
|
|
raise ValueError("--ntfy-url must be an HTTP(S) base URL without credentials or a topic")
|
|
timezone = timezone or host_timezone()
|
|
ZoneInfo(timezone)
|
|
for value in (ntfy_url, bind_address, timezone):
|
|
if any(char in value for char in "\r\n\x00$#'\" "):
|
|
raise ValueError("Unsafe configuration value")
|
|
if not 1 <= port <= 65535:
|
|
raise ValueError("Invalid pipeline port")
|
|
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"
|
|
# Empty until ntfy has issued a token. Never replace an existing credential.
|
|
try:
|
|
fd = os.open(token, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
|
|
os.close(fd)
|
|
except FileExistsError:
|
|
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")
|
|
for key, value in workspace_values.items(): file.write(key+"="+value+"\n")
|
|
return timezone
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--ntfy-url", required=True)
|
|
parser.add_argument("--bind-address", default="0.0.0.0")
|
|
parser.add_argument("--timezone")
|
|
parser.add_argument("--port", type=int, default=8081)
|
|
args = parser.parse_args()
|
|
try:
|
|
zone = configure(Path(__file__).resolve().parents[1], args.ntfy_url,
|
|
args.bind_address, args.timezone, args.port)
|
|
except (ValueError, ZoneInfoNotFoundError) as error:
|
|
parser.error(str(error))
|
|
print(f"Created .env with timezone {zone}. Configure the ntfy token before starting pipelines.")
|