[SSO] 32 oauth2-proxy переведены под compose: генератор oauth2-compose.py выгрузил 11 файлов из живого состояния, секреты — в /root/.env-out (600), в Git только ${VAR}. Все 32 службы подняты и отвечают, вне compose — 0. check_sso_providers теперь ловит контейнеры вне compose
This commit is contained in:
1 parent
f5a27d3824
commit
2ba5b81a2a
26 files changed
+991
-406
No files matched your search
@@ -46,6 +46,29 @@ def problems(p):
|
||||
return out
|
||||
|
||||
|
||||
def outside_compose():
|
||||
"""oauth2-proxy без compose = конфигурация не сохранена, потеряется при пересоздании."""
|
||||
out = []
|
||||
try:
|
||||
cts = subprocess.run("pct list | awk 'NR>1{print $1}'", shell=True,
|
||||
capture_output=True, text=True, timeout=30).stdout.split()
|
||||
except Exception:
|
||||
return out
|
||||
for ct in cts:
|
||||
names = subprocess.run("pct exec %s -- docker ps --format '{{.Names}}'" % ct,
|
||||
shell=True, capture_output=True, text=True, timeout=30).stdout.split()
|
||||
for n in names:
|
||||
if not n.startswith("oauth2-proxy"):
|
||||
continue
|
||||
proj = subprocess.run(
|
||||
"pct exec %s -- docker inspect %s --format "
|
||||
"'{{index .Config.Labels \"com.docker.compose.project\"}}'" % (ct, n),
|
||||
shell=True, capture_output=True, text=True, timeout=30).stdout.strip()
|
||||
if not proj or proj == "<no value>":
|
||||
out.append("CT%s %s" % (ct, n))
|
||||
return out
|
||||
|
||||
|
||||
def main():
|
||||
fix = "--fix" in sys.argv
|
||||
d = api("/providers/oauth2/?page_size=100")
|
||||
@@ -92,7 +115,15 @@ def main():
|
||||
elif issuer:
|
||||
print(" ✓ oauth2-proxy issuer: %s" % issuer)
|
||||
|
||||
return 1 if bad else 0
|
||||
lost = outside_compose()
|
||||
if lost:
|
||||
print(" ⛔ oauth2-proxy вне compose (конфиг потеряется): %d" % len(lost))
|
||||
for x in lost[:10]:
|
||||
print(" %s" % x)
|
||||
else:
|
||||
print(" ✓ все oauth2-proxy под compose")
|
||||
|
||||
return 1 if (bad or lost) else 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Executable
+76
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Выгружает все oauth2-proxy в compose-файлы репозитория.
|
||||
|
||||
Зачем: 43 контейнера созданы `docker run` — конфигурация нигде не сохранена.
|
||||
При пересоздании (обновление образа, перезагрузка) настройки теряются.
|
||||
|
||||
Правила:
|
||||
* где `deploy/ctNNN/docker-compose.yml` ещё нет — пишем туда;
|
||||
* где уже есть — пишем отдельный `oauth2-proxy.compose.yml`
|
||||
(так уже сделано для ct118 и ct119);
|
||||
* секреты в Git не попадают: в compose ${VAR}, значения — в /root/.env-out.
|
||||
|
||||
Запуск: python3 ops/scripts/oauth2-compose.py [--dry]
|
||||
"""
|
||||
import importlib.util
|
||||
import os
|
||||
import sys
|
||||
|
||||
REPO = "/root/buryan-infra"
|
||||
D2C = os.path.join(REPO, "ops", "scripts", "docker-to-compose.py")
|
||||
|
||||
spec = importlib.util.spec_from_file_location("d2c", D2C)
|
||||
d2c = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(d2c)
|
||||
|
||||
|
||||
def main():
|
||||
dry = "--dry" in sys.argv
|
||||
import subprocess
|
||||
cts = subprocess.run("pct list | awk 'NR>1{print $1}'", shell=True,
|
||||
capture_output=True, text=True).stdout.split()
|
||||
total = 0
|
||||
written = []
|
||||
for ct in cts:
|
||||
try:
|
||||
services, volumes, envfile, networks = d2c.build(ct)
|
||||
except Exception as e:
|
||||
print("CT%s: ошибка %s" % (ct, str(e)[:60]))
|
||||
continue
|
||||
# берём только oauth2-proxy
|
||||
services = {k: v for k, v in services.items() if k.startswith("oauth2-proxy")}
|
||||
if not services:
|
||||
continue
|
||||
d = os.path.join(REPO, "deploy", "ct" + ct)
|
||||
main_file = os.path.join(d, "docker-compose.yml")
|
||||
target = main_file if not os.path.exists(main_file) else os.path.join(
|
||||
d, "oauth2-proxy.compose.yml")
|
||||
body = ("# Сгенерировано oauth2-compose.py по живому состоянию (10.11.2026).\n"
|
||||
"# Секреты — в .env на CT (права 600), в Git не попадают.\n"
|
||||
"# Проверка: docker compose -f %s config\n\n"
|
||||
% os.path.basename(target)) + d2c.yaml_dump(services, volumes, networks)
|
||||
print("%-8s %-2d служб -> %s" % ("CT" + ct, len(services),
|
||||
os.path.relpath(target, REPO)))
|
||||
written.append((ct, target, len(services), len(envfile)))
|
||||
total += len(services)
|
||||
if dry:
|
||||
continue
|
||||
os.makedirs(d, exist_ok=True)
|
||||
with open(target, "w", encoding="utf-8") as f:
|
||||
f.write(body)
|
||||
with open(os.path.join(d, "oauth2-env.example"), "w", encoding="utf-8") as f:
|
||||
f.write("# Значения положить в .env на CT%s (chmod 600)\n" % ct)
|
||||
for k in sorted(envfile):
|
||||
f.write("%s=\n" % k)
|
||||
os.makedirs("/root/.env-out", exist_ok=True)
|
||||
envpath = "/root/.env-out/ct%s.env" % ct
|
||||
with open(envpath, "w", encoding="utf-8") as f:
|
||||
for k in sorted(envfile):
|
||||
f.write('%s="%s"\n' % (k, envfile[k]))
|
||||
os.chmod(envpath, 0o600)
|
||||
print("\nвсего служб:", total, "| файлов:", len(written))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in new issue
Block a user