|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""Build a portable, read-only appdevelopsk.com VPS release bundle. |
| 3 | +
|
| 4 | +This script packages ONLY the exact files allowed by the existing owner-only |
| 5 | +app discovery and privacy-policy publishing scripts. It never touches a VPS, |
| 6 | +changes a GitHub branch, sends events, or requires SSH/network access. |
| 7 | +
|
| 8 | +Usage: |
| 9 | + python3 scripts/build_site_release_bundle.py --output /tmp/appsite-release.zip |
| 10 | +""" |
| 11 | +import argparse |
| 12 | +import hashlib |
| 13 | +import json |
| 14 | +import re |
| 15 | +import shlex |
| 16 | +import sys |
| 17 | +import zipfile |
| 18 | +from pathlib import Path, PurePosixPath |
| 19 | + |
| 20 | +ROOT = Path(__file__).resolve().parents[1] |
| 21 | +APP_PUBLISHER = "scripts/publish_app_discovery.sh" |
| 22 | +POLICY_PUBLISHER = "scripts/publish_stale_policy_pages.sh" |
| 23 | +PRESS = { |
| 24 | + "press/index.html", |
| 25 | + "press/es/index.html", |
| 26 | + "press/pt-br/index.html", |
| 27 | + "press/ja/index.html", |
| 28 | + "press/id/index.html", |
| 29 | +} |
| 30 | +MAX_FILE_BYTES = 5_000_000 |
| 31 | +MAX_TOTAL_BYTES = 25_000_000 |
| 32 | +README = """APP SITE — OWNER-CONTROLLED RELEASE BUNDLE |
| 33 | +
|
| 34 | +This ZIP is source-only. Creating or downloading it does NOT publish a site. |
| 35 | +The root-level site/ directory preserves paths relative to the VPS web root. |
| 36 | +SHA256SUMS.txt verifies the exact bytes included; it is not a deployed SHA. |
| 37 | +
|
| 38 | +PREFERRED RELEASE: |
| 39 | + GitHub Actions -> publish to VPS -> main -> mode=dry-run; review. |
| 40 | + The owner may then authorize a separate mode=apply on the self-hosted VPS |
| 41 | + runner. Do NOT use this bundle to bypass a failed source preflight. |
| 42 | +
|
| 43 | +ALTERNATIVE WHEN THE SELF-HOSTED RUNNER IS UNAVAILABLE: |
| 44 | + 1. Extract this ZIP into a private temporary directory on a trusted computer. |
| 45 | + 2. From that extracted directory, run: |
| 46 | + sha256sum -c SHA256SUMS.txt |
| 47 | + 3. Owner verifies the SSH host/user, web-root path and exact file list. |
| 48 | + 4. Owner uploads only its site/ contents with their relative directories: |
| 49 | + rsync -rlcv --itemize-changes -- site/ USER@VPS:/var/www/html/ |
| 50 | + Do not add --delete. Do not blindly copy files to an unverified host. |
| 51 | + 5. Run source post-release read-only probes: |
| 52 | + bash scripts/check_app_discovery_live.sh |
| 53 | + bash scripts/publish_stale_policy_pages.sh --check-live |
| 54 | + 6. Confirm all five /press/ locale routes return HTTP 200 on |
| 55 | + https://appdevelopsk.com and the expected canonical/hreflang, then |
| 56 | + check the public app catalog and support landing metadata. |
| 57 | +
|
| 58 | +This includes 27 app-discovery documents and 17 approved policy documents |
| 59 | +from current source. It is NOT a complete VPS backup, nginx configuration, |
| 60 | +database migration, browser test, app-store release, or SEO indexing proof. |
| 61 | +""" |
| 62 | + |
| 63 | + |
| 64 | +def shell_array(text, name): |
| 65 | + if name == "files": |
| 66 | + pattern = r"(?m)^files=\(([^)\n]*)\)\s*$" |
| 67 | + elif name == "slugs": |
| 68 | + pattern = r"(?ms)^slugs=\(\s*(.*?)^\)\s*$" |
| 69 | + else: |
| 70 | + raise ValueError("unsupported manifest variable") |
| 71 | + found = re.findall(pattern, text) |
| 72 | + if len(found) != 1: |
| 73 | + raise ValueError("expected exactly one explicit " + name + "=(...) manifest") |
| 74 | + parts = shlex.split(found[0], comments=True) |
| 75 | + if not parts or len(parts) != len(set(parts)): |
| 76 | + raise ValueError(name + " manifest is empty or has duplicate entries") |
| 77 | + return parts |
| 78 | + |
| 79 | + |
| 80 | +def release_manifest(root=ROOT): |
| 81 | + scripts = root / "scripts" |
| 82 | + apps = shell_array((scripts / "publish_app_discovery.sh").read_text(encoding="utf-8"), "files") |
| 83 | + policies = shell_array((scripts / "publish_stale_policy_pages.sh").read_text(encoding="utf-8"), "slugs") |
| 84 | + if len(apps) != 27 or len(policies) != 17: |
| 85 | + raise ValueError("publisher manifest count changed; review before bundling") |
| 86 | + if not PRESS.issubset(set(apps)): |
| 87 | + raise ValueError("one or more of the five press routes are not in publisher manifest") |
| 88 | + if not {"index.html", "apps.html", "sitemap.xml", "robots.txt", |
| 89 | + "support/brain-burst/index.html", "support/debate-me/index.html"}.issubset(apps): |
| 90 | + raise ValueError("critical app discovery/SEO pages missing from publisher manifest") |
| 91 | + if any(not re.fullmatch(r"[a-z0-9-]+", slug) for slug in policies): |
| 92 | + raise ValueError("unsafe privacy-policy slug") |
| 93 | + files = apps + ["privacy-policy/" + slug + "/index.html" for slug in policies] |
| 94 | + if len(files) != len(set(files)): |
| 95 | + raise ValueError("publisher allowlists overlap") |
| 96 | + total = 0 |
| 97 | + for filename in files: |
| 98 | + path = PurePosixPath(filename) |
| 99 | + if (path.is_absolute() or ".." in path.parts or "." in path.parts |
| 100 | + or path.as_posix() != filename or "\\" in filename): |
| 101 | + raise ValueError("unsafe release path: " + filename) |
| 102 | + actual = root / filename |
| 103 | + if (not actual.is_file() or actual.is_symlink() |
| 104 | + or not actual.resolve().is_relative_to(root.resolve())): |
| 105 | + raise ValueError("missing or unsafe source file: " + filename) |
| 106 | + size = actual.stat().st_size |
| 107 | + if size <= 0 or size > MAX_FILE_BYTES: |
| 108 | + raise ValueError("missing, empty or oversized source file: " + filename) |
| 109 | + total += size |
| 110 | + if total > MAX_TOTAL_BYTES: |
| 111 | + raise ValueError("release is too large for the reviewed source-only bundle") |
| 112 | + return files |
| 113 | + |
| 114 | + |
| 115 | +def zip_bytes(root, files, out): |
| 116 | + out.parent.mkdir(parents=True, exist_ok=True) |
| 117 | + checksum_rows = [] |
| 118 | + with zipfile.ZipFile(out, "w", compression=zipfile.ZIP_DEFLATED, |
| 119 | + compresslevel=6) as archive: |
| 120 | + for filename in sorted(files): |
| 121 | + content = (root / filename).read_bytes() |
| 122 | + source = "site/" + filename |
| 123 | + archive.writestr(source, content) |
| 124 | + checksum_rows.append(hashlib.sha256(content).hexdigest() + " " + source) |
| 125 | + archive.writestr("SHA256SUMS.txt", "\n".join(checksum_rows) + "\n") |
| 126 | + archive.writestr("DEPLOY_README.txt", README) |
| 127 | + return hashlib.sha256(out.read_bytes()).hexdigest() |
| 128 | + |
| 129 | + |
| 130 | +def main(): |
| 131 | + parser = argparse.ArgumentParser(description=__doc__) |
| 132 | + parser.add_argument("--output", required=True, type=Path, |
| 133 | + help="Local output .zip path; never a production web root") |
| 134 | + args = parser.parse_args() |
| 135 | + if args.output.suffix.lower() != ".zip": |
| 136 | + parser.error("--output must be a .zip filename") |
| 137 | + output = args.output.resolve() |
| 138 | + if output.is_relative_to(ROOT): |
| 139 | + parser.error("do not create ZIP anywhere inside the public website source tree") |
| 140 | + try: |
| 141 | + files = release_manifest(ROOT) |
| 142 | + digest = zip_bytes(ROOT, files, output) |
| 143 | + except (OSError, ValueError, zipfile.BadZipFile) as exc: |
| 144 | + print(type(exc).__name__ + ": " + str(exc), file=sys.stderr) |
| 145 | + return 1 |
| 146 | + print(json.dumps({ |
| 147 | + "status": "source_bundle_created_not_deployed", |
| 148 | + "output": str(output), |
| 149 | + "sha256": digest, |
| 150 | + "appDiscoveryFiles": 27, |
| 151 | + "policyFiles": 17, |
| 152 | + "totalFiles": len(files), |
| 153 | + "pressRoutes": sorted(PRESS), |
| 154 | + "publishesToVps": False, |
| 155 | + "urlIndexingRequested": False, |
| 156 | + }, indent=2)) |
| 157 | + return 0 |
| 158 | + |
| 159 | + |
| 160 | +if __name__ == "__main__": |
| 161 | + sys.exit(main()) |
0 commit comments