Preserve installed release metadata and receiver assignments

This commit is contained in:
parkel committed 2026-11-24 02:07:23 +01:00
1 parent 8f5f9ef510
commit 09672ef18e
4 files changed
+44 -12

No files matched your search

+14
View File
@@ -206,6 +206,19 @@ def check_destination(settings):
raise InstallError("Choose a dedicated mail or DNS receiver.")
if "mail" in settings["roles"] and settings["tls"] == "provided":
certificate(settings, "mail")
for role in settings["roles"]:
unit = engine.SYSTEMD / f"coulobre-{role}-apply@.service"
state_file = NODE_STATE / f"{role}.json"
if unit.is_file() and (
not state_file.is_file()
or json.loads(state_file.read_text())["complete"]
):
engine.run(
engine.BINDIR / "coulobre-node-setup",
"check-receiver",
role,
label=f"Check the existing {role} service",
)
else:
standalone_plan(settings)
if (
@@ -279,6 +292,7 @@ def install_on_node(settings):
settings["scope"],
key,
*settings["domains"],
"--keep-domains",
)
else:
command = ("authorize-panel", name, key)
+13 -4
View File
@@ -288,7 +288,9 @@ def authorize_panel(role, key_path):
write_new_file(destination, entry, mode=0o644)
def authorize_scoped_panel(role, panel, key_path, domains):
def authorize_scoped_panel(
role, panel, key_path, domains, *, keep_domains=False
):
account = scoped_account(role.name, panel)
key = one_public_key(key_path)
if not key.startswith("ssh-ed25519 "):
@@ -335,8 +337,10 @@ def authorize_scoped_panel(role, panel, key_path, domains):
check_ssh_receiver(role, account)
entry = f'command="{role.relay}",restrict {key}\n'
contents = json.dumps(sorted(domains)) + "\n"
if path.exists():
scoped_domains(path)
if path.exists() and scoped_domains(path) != domains and keep_domains:
raise ValueError(
"Use the existing domain assignment when reenrolling a panel."
)
put_file(destination, entry)
replace_configuration(path, contents, mode=0o600)
return account
@@ -594,6 +598,7 @@ def main(argv=None):
action.add_argument("panel")
action.add_argument("public_key", type=Path)
action.add_argument("domains", nargs="+")
action.add_argument("--keep-domains", action="store_true")
if command in {"begin-maintenance", "finish-maintenance"}:
action.add_argument("inventory", type=Path)
if command == "enrol-panel":
@@ -625,7 +630,11 @@ def main(argv=None):
print(f"Authorized the panel key for the {role.name} receiver.")
elif args.command == "authorize-scoped-panel":
account = authorize_scoped_panel(
role, args.panel, args.public_key, args.domains
role,
args.panel,
args.public_key,
args.domains,
keep_domains=args.keep_domains,
)
print(
f"Authorized {account}. Use --scope {args.panel} on the panel."
+12 -1
View File
@@ -360,6 +360,16 @@ def run_deployment(payload, status):
raise DeploymentError(
f"The {name} receiver did not pass its installation check."
)
if name == "mail":
changes[name].update(
mail_hostname=mail_host, tls=tls, certificate=chain, key=key
)
for option in (
"COULOBRE_MAIL_IMAP_HOST",
"COULOBRE_MAIL_SUBMISSION_HOST",
):
if not re.search(rf"(?m)^[ \t]*{option}[ \t]*=", env):
env = env.rstrip("\n") + f"\n{option}={mail_host}\n"
installation["plan"][name] = changes[name]
flag = ROLE_FLAGS[name]
env = re.sub(rf"(?m)^[ \t]*{flag}[ \t]*=[^\n]*\n?", "", env)
@@ -425,7 +435,8 @@ def handle(peer):
"Resolve the panel update before installing a host."
)
report(status, "running", "Preparing the selected release.")
send(peer, accepted=True)
with suppress(OSError):
send(peer, accepted=True)
peer.close()
try:
run_deployment(payload, status)
+5 -7
View File
@@ -14,9 +14,8 @@ from check_core_release import ROOT, git_files, verify_release
def build_package(source, wheel, ref, output):
verify_release(source, wheel, ref)
project = tomllib.loads(git_files(ref)["pyproject.toml"].decode())[
"project"
]
tracked = git_files(ref)
project = tomllib.loads(tracked["pyproject.toml"].decode())["project"]
version = project["version"].replace("rc", "~rc")
epoch = subprocess.check_output(
["git", "show", "-s", "--format=%ct", ref], cwd=ROOT, text=True
@@ -31,10 +30,9 @@ def build_package(source, wheel, ref, output):
with tarfile.open(source, "r:gz") as archive:
prefix = source.name.removesuffix(".tar.gz")
for member in archive:
if member.isfile():
destination = source_dir / member.name.removeprefix(
f"{prefix}/"
)
name = member.name.removeprefix(f"{prefix}/")
if member.isfile() and name in tracked:
destination = source_dir / name
destination.parent.mkdir(parents=True, exist_ok=True)
destination.write_bytes(archive.extractfile(member).read())
destination.chmod(0o755 if member.mode & 0o111 else 0o644)