Route Archipelago through Moscow ingress proxies
This commit is contained in:
parent
52391e802b
commit
f6f8f41649
2 changed files with 81 additions and 0 deletions
12
README.md
12
README.md
|
|
@ -28,6 +28,18 @@ artwork require no remote fonts, scripts or upstream logo redistribution.
|
|||
|
||||
## Remaining pipeline work
|
||||
|
||||
### External ingress
|
||||
|
||||
For the known Moscow Docker Caddy ingress sites, run as root:
|
||||
`python3 deploy/integrate-ingress.py /path/to/conf/Caddyfile`.
|
||||
The helper inserts `/archipelago` and `/archipelago/*` routes into the single
|
||||
`mirror.nw-sys.ru` block, forwarding to terra at `100.64.0.1:80`. It validates
|
||||
inside `caddy-caddy-1`, saves a restricted backup and restores on reload failure.
|
||||
Host paths: south `/app/caddy/conf/Caddyfile`, north
|
||||
`/home/no1_tx/apps/caddy/conf/Caddyfile`, west `/opt/caddy/conf/Caddyfile`.
|
||||
|
||||
### Build and update pipeline
|
||||
|
||||
The existing CLI ISO experiment is not yet a YAML-driven, independently built layer
|
||||
pipeline. Required sequence: strict Layer parser and locks → independent layer
|
||||
build → artifact upload → image composition from registry → ISO from exact image →
|
||||
|
|
|
|||
69
deploy/integrate-ingress.py
Normal file
69
deploy/integrate-ingress.py
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Add the Archipelago route to a known Docker Caddy ingress configuration."""
|
||||
from pathlib import Path
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
config = Path(sys.argv[1])
|
||||
original = config.read_bytes()
|
||||
text = original.decode()
|
||||
sites = list(re.finditer(r'^mirror\.nw-sys\.ru \{\n.*?^\}', text, re.M | re.S))
|
||||
if len(sites) != 1:
|
||||
raise SystemExit('Expected exactly one standalone mirror site block')
|
||||
site = sites[0]
|
||||
block = site.group()
|
||||
if '/archipelago' in block:
|
||||
raise SystemExit('Archipelago route already present; review explicitly')
|
||||
marker = ' handle /archlinux* {'
|
||||
if block.count(marker) != 1 or 'reverse_proxy http://100.64.0.1:80' not in block:
|
||||
raise SystemExit('Unexpected mirror routing; review explicitly')
|
||||
snippet = ''' # BEGIN ARCHIPELAGO ingress
|
||||
handle /archipelago {
|
||||
redir /archipelago/ 308
|
||||
}
|
||||
handle /archipelago/* {
|
||||
reverse_proxy http://100.64.0.1:80
|
||||
}
|
||||
# END ARCHIPELAGO ingress
|
||||
|
||||
'''
|
||||
candidate = (text[:site.start()] + block.replace(marker, snippet + marker)
|
||||
+ text[site.end():]).encode()
|
||||
temporary = config.with_name(f'Caddyfile.archipelago-candidate-{time.time_ns()}')
|
||||
command = ['docker', 'exec', 'caddy-caddy-1', 'caddy']
|
||||
|
||||
def write(data):
|
||||
with config.open('wb') as stream:
|
||||
stream.write(data)
|
||||
stream.flush()
|
||||
os.fsync(stream.fileno())
|
||||
|
||||
def reload():
|
||||
subprocess.run(command + ['reload', '--config', '/etc/caddy/Caddyfile',
|
||||
'--adapter', 'caddyfile'], check=True)
|
||||
|
||||
try:
|
||||
with temporary.open('xb') as stream:
|
||||
os.fchmod(stream.fileno(), 0o600)
|
||||
stream.write(candidate)
|
||||
subprocess.run(command + ['validate', '--config', '/etc/caddy/' + temporary.name,
|
||||
'--adapter', 'caddyfile'], check=True)
|
||||
if config.read_bytes() != original:
|
||||
raise SystemExit('Configuration changed during validation; retry after review')
|
||||
backup = config.with_name(f'Caddyfile.before-archipelago-{time.time_ns()}')
|
||||
shutil.copy2(config, backup)
|
||||
os.chmod(backup, 0o600)
|
||||
try:
|
||||
write(candidate)
|
||||
reload()
|
||||
except Exception:
|
||||
write(original)
|
||||
reload()
|
||||
raise
|
||||
print(f'Integrated ingress; backup: {backup}')
|
||||
finally:
|
||||
temporary.unlink(missing_ok=True)
|
||||
Loading…
Add table
Reference in a new issue