Prepare fixed time gateway deployment and record native preflight
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
@@ -88,10 +88,42 @@ def status(payload):
|
||||
|
||||
def deploy(payload):
|
||||
import io
|
||||
import stat
|
||||
import tarfile
|
||||
root = Path('/opt/rust-discovery'); backup = root/'devstate'/('source-upgrade-'+payload['id'])
|
||||
def time_broker_overlay():
|
||||
# Optional fixed public overlay. Never follow an untrusted pathname or
|
||||
# silently omit an installed overlay when recreating the gateway.
|
||||
path = root/'deploy/server.time-broker.compose.yaml'
|
||||
try:
|
||||
initial = path.lstat()
|
||||
except FileNotFoundError:
|
||||
return None
|
||||
require(stat.S_ISREG(initial.st_mode) and initial.st_uid == initial.st_gid == 0
|
||||
and stat.S_IMODE(initial.st_mode) == 0o644 and initial.st_nlink == 1
|
||||
and initial.st_size == 199, 'protected fixed time broker overlay')
|
||||
for parent in path.parents:
|
||||
item = parent.lstat()
|
||||
require(stat.S_ISDIR(item.st_mode) and item.st_uid == 0 and not item.st_mode & 0o022,
|
||||
'protected time broker overlay ancestry')
|
||||
fd = os.open(path, os.O_RDONLY | os.O_CLOEXEC | os.O_NOFOLLOW)
|
||||
try:
|
||||
before = os.fstat(fd)
|
||||
raw = os.pread(fd, 4097, 0)
|
||||
identity = lambda item: (item.st_dev,item.st_ino,item.st_uid,item.st_gid,item.st_mode,
|
||||
item.st_nlink,item.st_size,item.st_mtime_ns,item.st_ctime_ns)
|
||||
require(identity(initial) == identity(before) == identity(os.fstat(fd)) == identity(path.lstat())
|
||||
and len(raw) == 199 and hashlib.sha256(raw).hexdigest()
|
||||
== 'dbd08faea8f58c032562d822f4191c719f9a6828b00d6c368fc2596155a9a314',
|
||||
'exact original time broker overlay bytes')
|
||||
return identity(before)
|
||||
finally:
|
||||
os.close(fd)
|
||||
overlay = time_broker_overlay() # Deny before any UI/tag/migration effect.
|
||||
record = json.loads((backup/'source.json').read_text())
|
||||
built=json.loads((backup/'build-result.json').read_text())
|
||||
require(not (backup/'time-gateway-deploy-intent.json').exists(),
|
||||
'stage reserved by fixed time gateway deployment; read its original case')
|
||||
require(built['exit_code'] == 0, 'build must pass')
|
||||
require(all(hashlib.sha256((root/name).read_bytes()).hexdigest() == sha for name,sha in record['files'].items()), 'source drift')
|
||||
require(not (backup/'deploy-result.json').exists(), 'deployment already recorded')
|
||||
@@ -127,6 +159,9 @@ def deploy(payload):
|
||||
with os.fdopen(fd, 'wb') as f: f.write(data); f.flush(); os.fsync(f.fileno()); os.fchmod(f.fileno(), 0o644)
|
||||
os.replace(next_path, dest)
|
||||
cmd = ['docker','compose','--env-file',str(root/'devstate/.env'),'-f',str(root/'deploy/server.compose.yaml')]
|
||||
if overlay is not None:
|
||||
cmd += ['-f',str(root/'deploy/server.time-broker.compose.yaml')]
|
||||
require(time_broker_overlay() == overlay, 'same optional time broker overlay before tag')
|
||||
if 'image_tag' in record:
|
||||
inspected=subprocess.run(['docker','image','inspect',record['image_tag'],'--format','{{.Id}}'],capture_output=True,check=True,timeout=10).stdout.decode().strip()
|
||||
require(inspected==built['image_id'] and inspected.startswith('sha256:'),'fixed qualified image required')
|
||||
@@ -134,8 +169,10 @@ def deploy(payload):
|
||||
# concurrently finishing source build cannot alter running services.
|
||||
subprocess.run(['docker','tag',inspected,'rust-discovery-server:local'],capture_output=True,check=True,timeout=10)
|
||||
# Existing migration image runs without rebuild; preserves PG volume/PKI.
|
||||
require(time_broker_overlay() == overlay, 'same optional time broker overlay before migration')
|
||||
migrate = subprocess.run(cmd+['run','--rm','--no-deps','migrate'], capture_output=True, timeout=25)
|
||||
require(migrate.returncode == 0, 'migration failed')
|
||||
require(time_broker_overlay() == overlay, 'same optional time broker overlay before recreate')
|
||||
result = subprocess.run(cmd+['up','-d','--no-deps','api','gateway'], capture_output=True, timeout=25)
|
||||
outcome = dict(deployed=result.returncode == 0, existing_state_preserved=True, approvals_created=False)
|
||||
(backup/'deploy-result.json').write_text(json.dumps(outcome)); (backup/'deploy-result.json').chmod(0o600)
|
||||
|
||||
Reference in New Issue
Block a user