forked from unimatrix/web
Publish shared styling from active website build instead of stale snapshot
This commit is contained in:
parent
c3d2b9e2d0
commit
c91a1a14f3
4 changed files with 158 additions and 1 deletions
7
website/docs/SHARED-DESIGN-BUILD-ROUTE-20261129.md
Normal file
7
website/docs/SHARED-DESIGN-BUILD-ROUTE-20261129.md
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# Shared stylesheet publication correction — 29 November 2026
|
||||
|
||||
Live release c3d2b9e was deployed, but public CSS verification correctly refused completion: nginx's cookbook snippet contained an exact /realm-design.css alias to an older static snapshot. That override explains why fresh website builds could retain old shared menu styling on CP, Staff and public pages.
|
||||
|
||||
The canonical website build now emits its exact compiled shared CSS into dist/shared-chrome/realm-design.css. The guarded publish-shared-design-route.py updates only that verified legacy route to follow the active current release. Cookbook routes remain unchanged. A named legacy fallback preserves CSS when rolling back to an older release without the new artifact. The tool verifies active commit and compiled input bytes, defaults to a hashed plan, requires the same plan for apply, backs up the exact configuration and restores it if nginx validation or reload fails. No account, native application or plugin code is changed by route publication.
|
||||
|
||||
Validation and actual publication evidence must be recorded separately. Do not run the broader native presentation publisher for this single-route correction.
|
||||
103
website/ops/publish-shared-design-route.py
Normal file
103
website/ops/publish-shared-design-route.py
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
"""Move the verified legacy shared CSS override onto the active built artifact."""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
CURRENT = Path('/home/dunerealms/apps/dunerealms/current')
|
||||
TARGET = Path('/etc/nginx/snippets/dunerealms-cookbook-e40883ba.conf')
|
||||
LEGACY = '/var/www/dunerealms-cookbook-e40883ba/realm-design.css'
|
||||
ROUTE = '''location = /realm-design.css {
|
||||
root /home/dunerealms/apps/dunerealms/current/dist/shared-chrome;
|
||||
try_files $uri @dunerealms_shared_design_legacy;
|
||||
default_type text/css;
|
||||
add_header Cache-Control "no-cache" always;
|
||||
}
|
||||
location @dunerealms_shared_design_legacy {
|
||||
root /var/www/dunerealms-cookbook-e40883ba;
|
||||
try_files /realm-design.css =404;
|
||||
default_type text/css;
|
||||
add_header Cache-Control "no-cache" always;
|
||||
}'''
|
||||
|
||||
|
||||
def route_content(old):
|
||||
matches = list(re.finditer(r'location\s*=\s*/realm-design\.css\s*\{[^{}]*\}', old))
|
||||
if len(matches) == 1 and ROUTE in old:
|
||||
return old
|
||||
if len(matches) != 1 or '@dunerealms_shared_design_legacy' in old:
|
||||
raise ValueError('Shared design route is not the verified legacy override')
|
||||
match = matches[0]
|
||||
if not re.search(r'alias\s+' + re.escape(LEGACY) + r'\s*;', match.group()):
|
||||
raise ValueError('Unexpected shared design alias; no changes made')
|
||||
return old[:match.start()] + ROUTE + old[match.end():]
|
||||
|
||||
|
||||
def replace_config(target, content, backup, run=subprocess.run):
|
||||
before = target.read_bytes()
|
||||
if before == content.encode():
|
||||
return False
|
||||
backup.parent.mkdir(parents=True, exist_ok=True, mode=0o700)
|
||||
if not backup.exists():
|
||||
shutil.copy2(target, backup)
|
||||
stat = target.stat()
|
||||
temporary = target.with_name(target.name + '.shared-design-new')
|
||||
try:
|
||||
temporary.write_text(content)
|
||||
os.chmod(temporary, stat.st_mode & 0o777)
|
||||
if hasattr(os, 'chown'):
|
||||
os.chown(temporary, stat.st_uid, stat.st_gid)
|
||||
os.replace(temporary, target)
|
||||
run(['nginx', '-t'], check=True, capture_output=True)
|
||||
run(['systemctl', 'reload', 'nginx'], check=True, capture_output=True)
|
||||
except Exception:
|
||||
target.write_bytes(before)
|
||||
os.chmod(target, stat.st_mode & 0o777)
|
||||
run(['nginx', '-t'], check=False, capture_output=True)
|
||||
run(['systemctl', 'reload', 'nginx'], check=False, capture_output=True)
|
||||
raise
|
||||
finally:
|
||||
temporary.unlink(missing_ok=True)
|
||||
return True
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--expected-release', required=True)
|
||||
parser.add_argument('--apply', action='store_true')
|
||||
parser.add_argument('--plan-hash')
|
||||
args = parser.parse_args()
|
||||
if not re.fullmatch('[a-f0-9]{40}', args.expected_release):
|
||||
raise ValueError('Exact release commit required')
|
||||
release = CURRENT.resolve(strict=True)
|
||||
if release.name != 'ci-' + args.expected_release:
|
||||
raise ValueError('Active release changed')
|
||||
artifact = release / 'dist/shared-chrome/realm-design.css'
|
||||
inputs = ['web/realm-design.css', 'scripts/homepage-header.css',
|
||||
'scripts/osticket-presentation.css', 'scripts/mybb-presentation.css',
|
||||
'scripts/shared-footer.css']
|
||||
expected = b''.join((release / name).read_bytes() for name in inputs)
|
||||
if artifact.read_bytes() != expected:
|
||||
raise ValueError('Built shared CSS differs from reviewed release inputs')
|
||||
old = TARGET.read_text()
|
||||
new = route_content(old)
|
||||
digest = lambda value: hashlib.sha256(value).hexdigest()
|
||||
plan = {'release': args.expected_release, 'target': str(TARGET),
|
||||
'before': digest(old.encode()), 'after': digest(new.encode()),
|
||||
'artifactSHA256': digest(expected), 'rollbackFallback': LEGACY}
|
||||
plan_hash = digest(json.dumps(plan, sort_keys=True).encode())
|
||||
print(json.dumps({**plan, 'planHash': plan_hash, 'applied': False}))
|
||||
if args.apply:
|
||||
if os.getuid() != 0 or args.plan_hash != plan_hash:
|
||||
raise ValueError('Root and matching reviewed plan hash required')
|
||||
backup = Path('/home/dunerealms/backups/shared-design-route-' + args.expected_release) / TARGET.name
|
||||
changed = replace_config(TARGET, new, backup)
|
||||
print(json.dumps({'applied': True, 'changed': changed, 'backup': str(backup)}))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
46
website/ops/test_shared_design_route.py
Normal file
46
website/ops/test_shared_design_route.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import importlib.util
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
spec = importlib.util.spec_from_file_location('route', Path(__file__).with_name('publish-shared-design-route.py'))
|
||||
route = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(route)
|
||||
|
||||
|
||||
class SharedDesignRouteTests(unittest.TestCase):
|
||||
def test_preserves_cookbook_routes_and_is_idempotent(self):
|
||||
other = 'location = /cookbook.html { alias /var/www/old/cookbook.html; }\n'
|
||||
old = other + 'location = /realm-design.css { alias ' + route.LEGACY + '; default_type text/css; }\n'
|
||||
new = route.route_content(old)
|
||||
self.assertTrue(new.startswith(other))
|
||||
self.assertIn('current/dist/shared-chrome', new)
|
||||
self.assertIn('try_files $uri @dunerealms_shared_design_legacy;', new)
|
||||
self.assertEqual(route.route_content(new), new)
|
||||
|
||||
def test_refuses_unknown_or_duplicate_alias(self):
|
||||
for old in ['', 'location = /realm-design.css { alias /unexpected.css; }',
|
||||
('location = /realm-design.css { alias ' + route.LEGACY + '; }') * 2]:
|
||||
with self.assertRaises(ValueError):
|
||||
route.route_content(old)
|
||||
|
||||
def test_failed_validation_or_reload_restores_exact_config_and_backup(self):
|
||||
for failure in (1, 2):
|
||||
with self.subTest(failure=failure), tempfile.TemporaryDirectory() as tmp:
|
||||
target = Path(tmp) / 'nginx.conf'
|
||||
target.write_bytes(b'original\n')
|
||||
backup = Path(tmp) / 'backup' / 'nginx.conf'
|
||||
calls = []
|
||||
def run(argv, **kwargs):
|
||||
calls.append(argv)
|
||||
if len(calls) == failure:
|
||||
raise subprocess.CalledProcessError(1, argv)
|
||||
with self.assertRaises(subprocess.CalledProcessError):
|
||||
route.replace_config(target, 'changed\n', backup, run)
|
||||
self.assertEqual(target.read_bytes(), b'original\n')
|
||||
self.assertEqual(backup.read_bytes(), b'original\n')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
@ -70,8 +70,9 @@ packageDeploymentScripts(path.join(dist,'deployment'),buildCommit||null);
|
|||
// nginx follows the atomically promoted current release, so no stale host copy
|
||||
// can retain an old Alpha version, navigation badge or rates page.
|
||||
const shared=path.join(dist,'shared-chrome');mkdirSync(shared,{recursive:true});
|
||||
for(const name of ['portal-navigation.js','portal-navigation.css','release.json','menu-new-items.json','rates-and-charges.html','bank-rates.css']){
|
||||
for(const name of ['portal-navigation.js','portal-navigation.css','realm-design.css','release.json','menu-new-items.json','rates-and-charges.html','bank-rates.css']){
|
||||
let content=readFileSync(path.join(web,name));
|
||||
if(name==='realm-design.css')content=sharedRealmCSS;
|
||||
if(name==='portal-navigation.js')content=Buffer.from(SHARED_FOOTER_SCRIPT+withRealmSwitch(withCanonicalMenu(withMenuBadges(cleanLegacyChromeScript(content.toString('utf8')))))+sharedRealmRuntime);
|
||||
if(name==='portal-navigation.css')content=Buffer.concat([content,Buffer.from(HOUSE_STYLE_CSS+REALM_SWITCH_CSS+readFileSync(path.join(web,"realm-comfort.css"),"utf8"))]);
|
||||
if(name.endsWith('.html'))content=Buffer.from(preparePublicHtml(content.toString('utf8'),name));
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff