51 lines
2.0 KiB
Python
51 lines
2.0 KiB
Python
"""Explicit operator bootstrap/start; preserves credentials and persistent volumes."""
|
|
from pathlib import Path
|
|
import json
|
|
import ssl
|
|
import subprocess
|
|
import sys
|
|
import time
|
|
import urllib.request
|
|
from urllib.error import HTTPError,URLError
|
|
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0,str(ROOT/'scripts'))
|
|
from bao_operator import request
|
|
|
|
|
|
def run(*args):subprocess.run(args,cwd=ROOT,check=True)
|
|
|
|
|
|
def main():
|
|
run(sys.executable,'scripts/bootstrap.py')
|
|
run('docker','compose','config','--quiet')
|
|
run('docker','compose','build','api1')
|
|
# Coordinated cold start also reloads native TLS and copied secret files.
|
|
# A parent and its shared-network sidecar must restart in dependency order.
|
|
run('docker','compose','stop','--timeout','5')
|
|
run('docker','compose','up','-d','db','openbao','s3','cache','broker')
|
|
for _ in range(40):
|
|
try:initialized=request('sys/init')['initialized'];break
|
|
except (URLError,OSError):time.sleep(.5)
|
|
else:raise RuntimeError('OpenBao did not become reachable')
|
|
if not initialized:run(sys.executable,'scripts/bao_operator.py','init')
|
|
run(sys.executable,'scripts/bao_operator.py','unseal')
|
|
run(sys.executable,'scripts/database_operator.py')
|
|
run(sys.executable,'scripts/bao_operator.py','provision')
|
|
run('docker','compose','run','--rm','storage-init')
|
|
run('docker','compose','up','-d')
|
|
# Compose may recreate Bao when its dependency image changed.
|
|
run(sys.executable,'scripts/bao_operator.py','unseal')
|
|
ctx=ssl.create_default_context(cafile=str(ROOT/'secrets/trust/ca.crt'))
|
|
for _ in range(90):
|
|
try:
|
|
with urllib.request.urlopen('https://127.0.0.1:8443/health/ready',context=ctx,timeout=3) as r:
|
|
if r.status==200:break
|
|
except (URLError,OSError):pass
|
|
time.sleep(1)
|
|
else:raise RuntimeError('Verified HTTPS readiness failed')
|
|
print('Stack ready on verified HTTPS; local operator shares remain outside containers/Git')
|
|
|
|
|
|
if __name__=='__main__':main()
|