feat(tasks): track authenticated native progress until final reply
Renew broker idle waits only for encrypted current-task progress, keep an absolute deadline and binding/session/worker fences, and retain original-message reply deduplication. Add guarded prepare-update staging that reuses the active broker key material and application configuration. Validation: 216 passed, 2 skipped; guarded update and long-task routing covered with synthetic Docker configuration and loopback WebSocket tests. Real ECS build and acceptance remain pending.
This commit is contained in:
@@ -355,6 +355,58 @@ def prepare(args):
|
||||
print("PREPARED: "+str(output)+" (services unchanged; private files must not be shared)")
|
||||
|
||||
|
||||
def prepare_update(args):
|
||||
"""Stage an already-active broker update without generating credentials."""
|
||||
root=Path(args.plan).resolve()
|
||||
parent=load_plan(root)
|
||||
check(root,parent,baseline=False)
|
||||
built=json.loads((root/'candidate.json').read_text(encoding='utf-8'))
|
||||
roles={name:service(parent['project'],name) for name in parent['roles']}
|
||||
if any(roles[name]['image'] != built['image'] for name in ('connector','router')):
|
||||
raise DeployError('update requires both services on the confirmed parent candidate; inspect state first')
|
||||
output=Path(args.output)
|
||||
source=Path(args.source_root).resolve()
|
||||
deployment=Path(parent['deployment_root']).resolve()
|
||||
if (not output.is_absolute() or output.exists() or output.is_symlink()
|
||||
or output.resolve()==deployment or deployment in output.resolve().parents
|
||||
or any(c in str(output) for c in ('\n','\r','$'))):
|
||||
raise DeployError('update output must be a new absolute directory outside the live deployment')
|
||||
if not (source/'relay/connector.py').is_file():
|
||||
raise DeployError('missing update source')
|
||||
output=output.resolve()
|
||||
output.mkdir(mode=0o700)
|
||||
os.chmod(output,0o700)
|
||||
plan=json.loads(json.dumps(parent))
|
||||
plan_id=secrets.token_hex(8)
|
||||
plan.update(plan_id=plan_id,candidate_image='hainuo-relay:broker-update-'+plan_id,
|
||||
roles=roles,base_image=built['image'],parent_plan=str(root),update_preserves_credentials=True)
|
||||
# Copy identical server key material; never rotate/reinitialize while updating code.
|
||||
shutil.copyfile(root/'credential-keyring.json',output/'credential-keyring.json')
|
||||
os.chmod(output/'credential-keyring.json',0o600)
|
||||
if os.name!='nt':os.chown(output/'credential-keyring.json',10001,10001)
|
||||
overlay=json.loads((root/'compose.broker.json').read_text(encoding='utf-8'))
|
||||
for name in ('connector','router'):overlay['services'][name]['image']=plan['candidate_image']
|
||||
for mount in overlay['services']['connector']['volumes']:
|
||||
if mount['target']=='/run/hainuo-credentials/keyring.json':
|
||||
mount['source']=str(output/'credential-keyring.json')
|
||||
write_json(output/'compose.broker.json',overlay)
|
||||
write_json(output/'compose.rollback.json',{'services':{name:{'image':roles[name]['image']}
|
||||
for name in ('connector','router','longconn','enrollment-signer')}})
|
||||
payload=output/'build';payload.mkdir(mode=0o700)
|
||||
for path in (source/'relay').rglob('*'):
|
||||
if path.is_symlink():raise DeployError('symlink in update source')
|
||||
if path.is_file() and path.suffix in {'.py','.js','.css','.html'} and '__pycache__' not in path.parts:
|
||||
target=payload/path.relative_to(source);target.parent.mkdir(parents=True,exist_ok=True)
|
||||
shutil.copyfile(path,target);os.chmod(target,0o644)
|
||||
shutil.copyfile(root/'build/Dockerfile',payload/'Dockerfile')
|
||||
plan['payload_hashes']={str(p.relative_to(output)):digest(p) for p in payload.rglob('*') if p.is_file()}
|
||||
plan['prepared_hashes']={name:digest(output/name) for name in
|
||||
('credential-keyring.json','compose.broker.json','compose.rollback.json')}
|
||||
write_json(output/'plan.json',plan)
|
||||
check(output,plan)
|
||||
print('UPDATE PREPARED: existing credential key material and permissions preserved; no services restarted')
|
||||
|
||||
|
||||
def load_plan(root):
|
||||
plan = json.loads((root/"plan.json").read_text(encoding="utf-8"))
|
||||
if plan.get("format") != 1 or not re.fullmatch(r"[a-f0-9]{16}",plan.get("plan_id","")):
|
||||
@@ -568,6 +620,10 @@ def main():
|
||||
prep.add_argument("--profiles",required=True)
|
||||
prep.add_argument("--output",required=True)
|
||||
prep.add_argument("--connector-container",default="hainuo-relay-connector-1")
|
||||
update = sub.add_parser("prepare-update")
|
||||
update.add_argument("--plan",required=True)
|
||||
update.add_argument("--source-root",default=str(Path(__file__).resolve().parents[1]))
|
||||
update.add_argument("--output",required=True)
|
||||
for name in ("repair-router","state","diagnose","check","build","activate","rollback"):
|
||||
cmd = sub.add_parser(name)
|
||||
cmd.add_argument("--plan",required=True)
|
||||
@@ -583,6 +639,9 @@ def main():
|
||||
if args.action == "prepare":
|
||||
prepare(args)
|
||||
return
|
||||
if args.action == "prepare-update":
|
||||
prepare_update(args)
|
||||
return
|
||||
root = Path(args.plan).resolve()
|
||||
plan = load_plan(root)
|
||||
if args.action == "repair-router":
|
||||
|
||||
Reference in New Issue
Block a user