Files
dj/integration-work/deploy_gpu1_idle_fix.py
T

29 lines
1.4 KiB
Python

import pathlib,json,hashlib,subprocess,time
root=pathlib.Path('/home/ps/huobao-gpu-selection')
folder=pathlib.Path(json.loads((root/'idle-baseline-fix-current.json').read_text())['directory'])
manifest=json.loads((folder/'manifest.json').read_text())
# Verify every source before changing either live bind mount.
for m in manifest.values():
assert hashlib.sha256(pathlib.Path(m['path']).read_bytes()).hexdigest()==m['before']
assert hashlib.sha256(pathlib.Path(m['candidate']).read_bytes()).hexdigest()==m['after']
for short,m in manifest.items():
p=pathlib.Path(m['path']);p.write_bytes(pathlib.Path(m['candidate']).read_bytes())
try:
subprocess.run(['docker','restart','--timeout','60',m['name']],check=True,stdout=subprocess.DEVNULL)
code='''import asyncio,app,json
async def main():
p=await app.select_provider('gpu1_8189',True,True)
print(json.dumps({'ready':True,'provider':p.id,'url':p.base_url}))
asyncio.run(main())'''
for attempt in range(10):
r=subprocess.run(['docker','exec',m['name'],'python','-c',code],capture_output=True,text=True)
if r.returncode==0:break
time.sleep(1)
if r.returncode:raise RuntimeError(r.stderr[-1200:])
print(short,r.stdout.strip())
except Exception:
p.write_bytes((folder/(short+'.before.py')).read_bytes())
subprocess.run(['docker','restart','--timeout','60',m['name']],check=True,stdout=subprocess.DEVNULL)
raise
print('BACKUP',str(folder))