feat: deploy platform inventory and signed APT retry client compatibility
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
@@ -77,11 +77,35 @@ def status(payload):
|
||||
|
||||
|
||||
def deploy(payload):
|
||||
import io
|
||||
import tarfile
|
||||
root = Path('/opt/rust-discovery'); backup = root/'devstate'/('source-upgrade-'+payload['id'])
|
||||
record = json.loads((backup/'source.json').read_text())
|
||||
require(json.loads((backup/'build-result.json').read_text())['exit_code'] == 0, 'build must pass')
|
||||
require(all(hashlib.sha256((root/name).read_bytes()).hexdigest() == sha for name,sha in record['files'].items()), 'source drift')
|
||||
require(not (backup/'deploy-result.json').exists(), 'deployment already recorded')
|
||||
raw = base64.b64decode(payload['web_tar'], validate=True)
|
||||
require(hashlib.sha256(raw).hexdigest() == payload['web_sha256'], 'reviewed web archive hash')
|
||||
# Publish immutable hashed assets before index, keeping the bind-mounted
|
||||
# dist directory inode. Retain old files; no recursive deletion.
|
||||
with tarfile.open(fileobj=io.BytesIO(raw), mode='r:') as archive:
|
||||
members = sorted(archive.getmembers(), key=lambda m: m.name == 'index.html')
|
||||
require(any(m.name == 'index.html' for m in members), 'built UI index required')
|
||||
for member in members:
|
||||
name = member.name
|
||||
require(member.isfile() and not Path(name).is_absolute() and '..' not in Path(name).parts and
|
||||
(name == 'index.html' or name.startswith('assets/') and name.endswith(('.js','.css'))), 'built web path allowlist')
|
||||
data = archive.extractfile(member).read(); require(len(data) < 2*1024*1024, 'web file limit')
|
||||
dest = root/'web/dist'/name
|
||||
require(not dest.is_symlink() and not dest.parent.is_symlink(), 'web symlink')
|
||||
dest.parent.mkdir(mode=0o755, parents=True, exist_ok=True)
|
||||
if dest.exists():
|
||||
retained = backup/'web'/name; retained.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
|
||||
with retained.open('xb') as f: f.write(dest.read_bytes()); f.flush(); os.fsync(f.fileno())
|
||||
next_path = dest.with_name(dest.name+'.upgrade-next')
|
||||
fd = os.open(next_path, os.O_WRONLY|os.O_CREAT|os.O_EXCL|os.O_NOFOLLOW, 0o644)
|
||||
with os.fdopen(fd, 'wb') as f: f.write(data); f.flush(); os.fsync(f.fileno()); os.fchmod(f.fileno(), 0o644)
|
||||
os.replace(next_path, dest)
|
||||
cmd = ['docker','compose','--env-file',str(root/'devstate/.env'),'-f',str(root/'deploy/server.compose.yaml')]
|
||||
# Existing migration image runs without rebuild; preserves PG volume/PKI.
|
||||
migrate = subprocess.run(cmd+['run','--rm','--no-deps','migrate'], capture_output=True, timeout=25)
|
||||
@@ -115,7 +139,16 @@ def main():
|
||||
target = cloud.contract.protected_json(cloud.ROOT/'devstate/remote-vm.json')['identity']
|
||||
gate = cloud.bootstrap.rpc('server.conf', cloud.server, dict(kind='gate', tenant_id=cloud.TENANT, agent_id=target['agent_id']))
|
||||
require(gate['unresolved'] == 0, 'unresolved cloud job; no server switch')
|
||||
result = cloud.bootstrap.rpc('server.conf', status if args.action == 'status' else deploy, dict(id=ident))
|
||||
payload = dict(id=ident)
|
||||
if args.action == 'deploy':
|
||||
stream = io.BytesIO()
|
||||
with tarfile.open(fileobj=stream, mode='w:') as archive:
|
||||
for p in sorted((cloud.ROOT/'web/dist').rglob('*')):
|
||||
if p.is_file():
|
||||
require(not p.is_symlink(), 'built UI symlink')
|
||||
archive.add(p, arcname=str(p.relative_to(cloud.ROOT/'web/dist')), recursive=False)
|
||||
data = stream.getvalue(); payload.update(web_tar=base64.b64encode(data).decode(), web_sha256=hashlib.sha256(data).hexdigest())
|
||||
result = cloud.bootstrap.rpc('server.conf', status if args.action == 'status' else deploy, payload)
|
||||
print(result)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user