Files
dj/integration-work/deploy_gpu_normalizers.py
T

23 lines
1.7 KiB
Python

import pathlib,json,sys,datetime
sys.path.insert(0,'/home/ps/huobao-gpu-selection')
from docker_worker_ops import api,inspect,clone,write_json
root=pathlib.Path('/home/ps/huobao-gpu-selection');stamp=datetime.datetime.now().strftime('%Y%m%d-%H%M%S')
for name in ('canvas-h3-prompt-normalizer-healthy-20261026','huobao-vdn-normalizer'):
candidate=root/(name+'.candidate.py');compile(candidate.read_text(),str(candidate),'exec')
source=inspect(name)
if any(m['Source']==str(candidate) and m['Destination']=='/app/app.py' for m in source['Mounts']):
print('Already deployed:',name);continue
write_json(root/(name+'.before-routing.json'),source)
cfg=clone(source,name)
cfg['Labels'].update(source['Config'].get('Labels') or {})
# Keep existing credentials, immutable root and exact existing network membership.
for dest,src in [('/app/app.py',candidate),('/app/huobao-extra-providers.json',root/'extra-providers.json')]:
assert src.exists()
cfg['HostConfig']['Binds']=[b for b in cfg['HostConfig'].get('Binds',[]) if b.split(':')[1]!=dest]+[str(src)+':'+dest+':ro']
cfg['NetworkingConfig']={'EndpointsConfig':{network:{'Aliases':[a for a in (info.get('Aliases') or []) if a not in (source['Id'],source['Id'][:12])]} for network,info in source['NetworkSettings']['Networks'].items()}}
write_json(root/(name+'.create-routing.json'),cfg)
api('POST','/containers/'+name+'/stop?t=20');api('POST','/containers/'+name+'/rename?name='+name+'-before-gpu-routing-'+stamp)
created=api('POST','/containers/create?name='+name,cfg);api('POST','/containers/'+name+'/start')
print('Recreated routing service with exact original networks/security:',name,'user',cfg['User'],'readonly',cfg['HostConfig']['ReadonlyRootfs'])
write_json(root/'routing-normalizers-deployed.json',{'at':stamp})