Files
dj/integration-work/prepare_8189_huobao.py

42 lines
3.6 KiB
Python

"""Prepare an isolated node extension for the existing 8189 UI; no restart here."""
import pathlib,json,sys,shutil,os,hashlib,secrets
sys.path.insert(0,'/home/ps/huobao-gpu-selection')
from docker_worker_ops import inspect,clone,replace_bind,write_json,set_env
root=pathlib.Path('/home/ps/huobao-gpu-selection');work=root/'panel-8189'
assert not work.exists(),'Inspect existing prepared work before rerunning'
work.mkdir(mode=0o700)
old=inspect('comfyui-manju');source=inspect('huobao-comfy-gpu1')
write_json(work/'before.json',old)
current_nodes=pathlib.Path(next(m['Source'] for m in old['Mounts'] if m['Destination']=='/app/custom_nodes'))
source_nodes=pathlib.Path(next(m['Source'] for m in source['Mounts'] if m['Destination']=='/app/custom_nodes'))
shutil.copytree(current_nodes,work/'custom_nodes',copy_function=os.link,symlinks=True)
shutil.copytree(source_nodes/'ComfyUI-H3CaptionPipeline',work/'custom_nodes/ComfyUI-H3CaptionPipeline',symlinks=True)
allow=pathlib.Path(next(m['Source'] for m in old['Mounts'] if m['Destination']=='/recovery/allowed_node_classes.json'))
allowed=json.loads(allow.read_text())
extra=['H3CaptionPipeline','H3CaptionChunkSource','H3CaptionBlendChunk','H3CaptionFinalize','H3InpaintConditioningCache','H3CaptionWarmup','H3TextRegionVerifier','H3STTNRepair','H3GenerationModelStage']
allowed['required_classes']=sorted(set(allowed['required_classes'])|set(extra))
allowed['reason']+='; Huobao user requested direct 8189 queue: existing reviewed H3CaptionPipeline classes only'
(work/'allowed_node_classes.json').write_text(json.dumps(allowed));(work/'allowed_node_classes.json').chmod(0o644)
(work/'control').mkdir(mode=0o700)
token=secrets.token_hex(32);(work/'control/canary.token').write_text(token);(work/'control/canary.token').chmod(0o600)
(work/'control/control.json').write_text(json.dumps({'schema':1,'maintenance':True}))
cfg=clone(old,'comfyui-manju')
replace_bind(cfg,'/app/custom_nodes',work/'custom_nodes')
replace_bind(cfg,'/recovery/allowed_node_classes.json',work/'allowed_node_classes.json')
cfg['Cmd'].insert(cfg['Cmd'].index('--extra-model-paths-config'),'ComfyUI-H3CaptionPipeline')
if '--reserve-vram' not in cfg['Cmd']:cfg['Cmd']+=['--reserve-vram','8']
for dest in ('/app/h3-sttn','/app/h3-speech-validator','/run/h3-shared-vision'):
m=next(m for m in source['Mounts'] if m['Destination']==dest)
cfg['HostConfig']['Binds'].append(m['Source']+':'+dest+':ro')
cfg['HostConfig']['Binds'] += [str(work/'control')+':/run/huobao-8189-control:ro',str(work/'history.json')+':/run/huobao-8189-history.json:ro']
def env(k,v):
set_env(cfg,k,v)
if not any(x.startswith(k+'=') for x in cfg['Cmd']):cfg['Cmd'].insert(cfg['Cmd'].index('/opt/conda/bin/python3'),k+'='+v)
for k,v in {'H3_WORKER_CONTROL_FILE':'/run/huobao-8189-control/control.json','H3_CANARY_TOKEN_FILE':'/run/huobao-8189-control/canary.token','H3_VISION_SOCKET':'/run/h3-shared-vision/vision.sock','H3_HISTORY_SNAPSHOT':'/run/huobao-8189-history.json','H3_HISTORY_SOURCE_CONTAINER_ID':old['Id']}.items():env(k,v)
cfg['NetworkingConfig']={'EndpointsConfig':{n:{'Aliases':d.get('Aliases') or []} for n,d in old['NetworkSettings']['Networks'].items()}}
assert cfg['HostConfig']['DeviceRequests']==old['HostConfig']['DeviceRequests']
assert cfg['HostConfig']['PortBindings']==old['HostConfig']['PortBindings']
assert set(cfg['NetworkingConfig']['EndpointsConfig'])==set(old['NetworkSettings']['Networks'])
write_json(work/'create.json',cfg)
print(json.dumps({'prepared':str(work),'gpu':'1','existing_port':8189,'added_classes':extra,'existing_classes':len(allowed['required_classes'])-len(extra),'restart_performed':False}))