Реализовать уровень 3: приватное S3, вложения и сохранность при отказах

This commit is contained in:
2026-10-30 17:33:07 +03:00
parent 2e5f5bfe1b
commit 4f85fb96a6
30 changed files with 592 additions and 27 deletions
+22
View File
@@ -0,0 +1,22 @@
"""Restart/failover hooks scoped to lab4; never remove volumes."""
import json
import os
from pathlib import Path
import subprocess
import sys
root=Path(__file__).resolve().parents[1]
base=['docker','compose','--project-directory',str(root),'-p','lyakhonov-lab4']
def compose(*args):
return subprocess.check_output(base+list(args),text=True).strip()
mode=sys.argv[1]
if mode=='restart':
compose('restart','api','db','redis','s3','lb')
elif mode=='stop-one':
target=os.environ['TARGET_INSTANCE_ID']
for cid in compose('ps','-q','api').splitlines():
info=json.loads(subprocess.check_output(['docker','inspect',cid],text=True))[0]
if target.startswith(info['Config']['Hostname']+'-'):
subprocess.check_call(['docker','stop','--time','1',cid],stdout=subprocess.DEVNULL)
break
else: raise SystemExit('No matching lab4 API instance')
else: raise SystemExit('unknown action')
+5
View File
@@ -13,3 +13,8 @@ if not url_file.exists():
password = password_file.read_text(encoding='utf-8').strip()
url_file.write_text(f'postgresql://messenger:{password}@db:5432/messenger', encoding='utf-8')
print('Локальные секреты готовы; значения не выводятся.')
for name in ('s3_root_user', 's3_root_password', 's3_access_key', 's3_secret_key'):
target = folder / name
if not target.exists():
target.write_text(secrets.token_hex(24), encoding='utf-8')
+2
View File
@@ -0,0 +1,2 @@
@echo off␍
python "%~dp0actions.py" restart␍
+3
View File
@@ -0,0 +1,3 @@
#!/bin/sh
set -eu
exec python3 "$(dirname "$0")/actions.py" restart
+2
View File
@@ -0,0 +1,2 @@
@echo off␍
python "%~dp0actions.py" stop-one␍
+3
View File
@@ -0,0 +1,3 @@
#!/bin/sh
set -eu
exec python3 "$(dirname "$0")/actions.py" stop-one