Publish the reviewed accumulated runtime, scheduler, profile, UI, native recipes and historical maintenance evidence. Includes Qwen GPU ASR correction and shared Anna/atelier ownership. Validated with 784 local tests, Python/JSON parsing and eight JavaScript syntax checks. Live GPU acceptance and full fresh-host restore limits remain documented.
82 lines
7.7 KiB
Python
82 lines
7.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Athena-host scoped image overlay; explicit Go and regular fresh GUI drain required."""
|
|
import argparse,hashlib,importlib.util,json,shutil,subprocess,time
|
|
from pathlib import Path
|
|
ROOT=Path('/opt/athena-deck-dev/qwen-anna-gpu-activation');BASE=Path('/opt/athena-deck-dev/runtime');STATE=BASE/'state';CANON=Path('/opt/athena-deck-dev/source')
|
|
FILES=['tts_worker.py','tts_runtime.py','tts_test.py','profiles.py','backup.py','endpoint.py','profiles-ui.js','tts-ui.js']
|
|
IMAGE='athena-deck-standalone:qwen-anna-existing-gpu'
|
|
SETTINGS=['profiles.json','endpoint.json','audio-policy.json','cpu-partition.json','reasoning-budget.json']
|
|
def inspect():return json.loads(subprocess.check_output(['docker','inspect','athena-deck-dev'],text=True))[0]
|
|
def digest(path):return hashlib.sha256(path.read_bytes()).hexdigest()
|
|
def run(args,**kwargs):return subprocess.run(list(map(str,args)),check=True,**kwargs)
|
|
def mounts(config):
|
|
out=['--mount','type=bind,src='+str(STATE)+',dst=/var/lib/deck']
|
|
for p in dict.fromkeys([config.get('strata_storage'),*config.get('strata_storage_mounts',[]),*config.get('external_model_roots',[])]):
|
|
if not p:continue
|
|
path=Path(p);assert path.is_absolute() and path.is_dir() and not {'vpn','vpn.auth','OpenVPN-KIT','GluetunVPN'}&set(path.parts)
|
|
out+=['--mount','type=bind,src='+p+',dst='+p+',readonly']
|
|
return out
|
|
|
|
def prepare():
|
|
info=inspect();config=json.loads((BASE/'installation.json').read_text());app=ROOT/'image/app';assert all((app/n).is_file() for n in FILES)
|
|
tag=info['Config']['Image'];assert subprocess.check_output(['docker','image','inspect','--format','{{.Id}}',tag],text=True).strip()==info['Image']
|
|
(ROOT/'image/Dockerfile').write_text('FROM '+tag+'\nUSER root\nCOPY app/ /app/\nUSER 65534:65534\n')
|
|
with (ROOT/'build.log').open('w') as f:run(['docker','build','--network','none','--pull=false','-t',IMAGE,ROOT/'image'],stdout=f,stderr=subprocess.STDOUT,timeout=180)
|
|
tmp=ROOT/'test-tmp';tmp.mkdir(exist_ok=True);tmp.chmod(0o777)
|
|
probe='from server import Server;from pathlib import Path;import tempfile\nwith tempfile.TemporaryDirectory() as d:\n s=Server(0,state_dir=Path(d));s.endpoint.close();s.video.close();s.dashboard.close();s.server_close()\nprint("Full isolated Server constructor passed")'
|
|
run(['docker','run','--rm','--network','none','--read-only','--user','65534:65534','--memory','512m','--pids-limit','256','--cap-drop','ALL','-e','NVIDIA_VISIBLE_DEVICES=void','-e','DECK_REQUIRE_SETUP=0','-e','DECK_NETWORK_MODE=disabled','-e','TMPDIR=/test-tmp','--mount','type=bind,src='+str(tmp)+',dst=/test-tmp','--entrypoint','python3',IMAGE,'-B','-c',probe],timeout=45)
|
|
before=ROOT/'source-before';before.mkdir(exist_ok=True)
|
|
for n in FILES:shutil.copy2(CANON/n,before/n)
|
|
data=dict(phase='prepared',image_before=tag,image_id_before=info['Image'],started_before=info['State']['StartedAt'],config=config,baseline={n:digest(CANON/n) for n in FILES},settings={n:(STATE/n).read_text() for n in SETTINGS})
|
|
path=ROOT/'activation.json';path.write_text(json.dumps(data,indent=2));path.chmod(0o600)
|
|
assert inspect()['Image']==info['Image'] and inspect()['State']['StartedAt']==info['State']['StartedAt'];print('Image and full constructor prepared; production unchanged',flush=True)
|
|
|
|
def apply():
|
|
data=json.loads((ROOT/'activation.json').read_text());assert data['phase']=='prepared'
|
|
d=json.loads((ROOT/'drained.json').read_text());assert time.time()-d['checked_at']<60 and d['state']=='stopped' and type(d['active_requests']) is int and d['active_requests']==0
|
|
assert all(type(d['scheduler'][k]) is int and d['scheduler'][k]==0 for k in ('active_requests','waiting_requests','tts_waiting_requests')) and d['scheduler']['switching'] is False
|
|
assert inspect()['Image']==data['image_id_before'];assert all(digest(CANON/n)==h for n,h in data['baseline'].items())
|
|
assert all((STATE/n).read_text()==text for n,text in data['settings'].items() if n!='endpoint.json')
|
|
old_profiles=json.loads(data['settings']['profiles.json']);old_endpoint=json.loads(data['settings']['endpoint.json']);assert old_endpoint['autostart'] is True
|
|
run(['docker','stop','--timeout','45','athena-deck-dev']);activated=False
|
|
try:
|
|
assert not subprocess.check_output(['nvidia-smi','--query-compute-apps=pid','--format=csv,noheader,nounits'],text=True).strip()
|
|
code="""from pathlib import Path
|
|
from catalog import Catalog
|
|
from profiles import Profiles
|
|
r=Path('/var/lib/deck');s=Profiles(r/'profiles.json',Catalog(r/'models'));old=next(p for p in s.rows if p['id']=='16387088f1ac4a5bae8ca037932f9f58')
|
|
assert not any(p.get('api_id')=='qwen-anna-gpu-3060' for p in s.rows)
|
|
p=s.save(dict(id=None,revision=0,name='Qwen 1.7B Anna GPU 3060',api_id='qwen-anna-gpu-3060',kind='audio',model_id=old['model_id'],parameters={'speed':1,'tts_voice':'Anna'}));print('Saved Anna profile '+p['id'])
|
|
"""
|
|
common=['docker','run','--rm','--network','none','--user','65534:65534','--cap-drop','ALL',*mounts(data['config'])]
|
|
run([*common,'-e','NVIDIA_VISIBLE_DEVICES=void','--entrypoint','python3',IMAGE,'-B','-c',code],timeout=30)
|
|
run([*common,'--gpus','device=GPU-4834d9d7-5b61-3004-1fb3-4ae49d482d4b','--memory','12g','--pids-limit','1024','-e','NVIDIA_DRIVER_CAPABILITIES=compute,utility','--mount','type=bind,src='+str(ROOT/'scripts')+',dst=/accept,readonly','--entrypoint','python3',IMAGE,'-B','/accept/check.py'],timeout=240)
|
|
now=json.loads((STATE/'profiles.json').read_text());extra=[p for p in now if p.get('api_id')=='qwen-anna-gpu-3060'];assert len(extra)==1
|
|
assert [p for p in now if p['id']!=extra[0]['id']]==old_profiles
|
|
assert all((STATE/n).read_text()==data['settings'][n] for n in SETTINGS if n not in ('profiles.json','endpoint.json'))
|
|
# Restore the original endpoint publication/autostart exactly; no default voice change.
|
|
(STATE/'endpoint.json').write_text(data['settings']['endpoint.json'])
|
|
for n in FILES:shutil.copy2(ROOT/'image/app'/n,CANON/n)
|
|
spec=importlib.util.spec_from_file_location('deck_install',CANON/'deploy/install.py');installer=importlib.util.module_from_spec(spec);spec.loader.exec_module(installer)
|
|
config=dict(data['config'],image=IMAGE,previous_image=data['image_before'])
|
|
run(['docker','rm','athena-deck-dev']);installer.launch(config);installer.ready(config);installer.write_manifest(BASE,config)
|
|
activated=True;data.update(phase='activated and GPU tested; restore chat model',profile=extra[0],finished_at=time.time());(ROOT/'activation.json').write_text(json.dumps(data,indent=2));print(json.dumps(dict(activated=True,profile=extra[0]['name'],api_id=extra[0]['api_id'],standard_voice_unchanged=True)),flush=True)
|
|
finally:
|
|
if not activated:
|
|
current=json.loads((STATE/'profiles.json').read_text());assert [p for p in current if p.get('api_id')!='qwen-anna-gpu-3060']==old_profiles
|
|
(STATE/'profiles.json').write_text(data['settings']['profiles.json']);(STATE/'endpoint.json').write_text(data['settings']['endpoint.json'])
|
|
# Before image replacement the original stopped container is retained.
|
|
for n in FILES:shutil.copy2(ROOT/'source-before'/n,CANON/n)
|
|
try:live=inspect()
|
|
except subprocess.CalledProcessError:live=None
|
|
if live is None:
|
|
spec=importlib.util.spec_from_file_location('deck_restore',CANON/'deploy/install.py');assert spec and spec.loader
|
|
installer=importlib.util.module_from_spec(spec);spec.loader.exec_module(installer)
|
|
installer.launch(data['config']);installer.ready(data['config']);installer.write_manifest(BASE,data['config'])
|
|
elif not live['State']['Running']:run(['docker','start','athena-deck-dev'])
|
|
print('Activation failed; original settings/container restored. Verify health.',flush=True)
|
|
|
|
if __name__=='__main__':
|
|
p=argparse.ArgumentParser();p.add_argument('operation',choices=['prepare','apply']);p.add_argument('--go',action='store_true');a=p.parse_args();assert a.go,'Current explicit Michael Go required'
|
|
prepare() if a.operation=='prepare' else apply()
|