#!/usr/bin/env python3 """Atlas-side immutable transfer. Upload only; activation is a separate operation.""" import argparse import os from pathlib import Path import subprocess import tarfile from release import load, safe_name, require parser=argparse.ArgumentParser(description=__doc__) parser.add_argument('bundle') parser.add_argument('--identity',required=True) parser.add_argument('--host',default='85.190.124.132') args=parser.parse_args() require(args.host=='85.190.124.132','Production transfer host must be web1') bundle=Path(args.bundle).resolve() release=safe_name(load(bundle/'authorization.json')['release_id']) command=['ssh','-F','/dev/null','-i',args.identity,'-o','IdentitiesOnly=yes','-o','HostKeyAlgorithms=ssh-ed25519', '-o','StrictHostKeyChecking=yes','-o','UpdateHostKeys=no','plotdirector-deploy@'+args.host,'upload '+release] process=subprocess.Popen(command,stdin=subprocess.PIPE) try: with tarfile.open(fileobj=process.stdin,mode='w|',format=tarfile.USTAR_FORMAT) as tar: for name in ('authorization.json','authorization.sig','package.tar'): path=bundle/name require(path.is_file() and not path.is_symlink(),'Invalid transfer input') entry=tarfile.TarInfo(name);entry.size=path.stat().st_size;entry.mode=0o600 with path.open('rb') as stream:tar.addfile(entry,stream) process.stdin.close() raise SystemExit(process.wait()) finally: if process.poll() is None:process.kill();process.wait()