SPB Git

Repository Public BSD-3-Clause

README.md 7.2 KB

# package-builder — orix-package

macOS command-line tool that generates signing keys, assembles and signs .orixmap region packages from component files, verifies and inspects them, and generates the static distribution catalog. Depends only on Packages/ORIXMapPackage (the format has a single implementation, shared with the app) and ORIXGeoCore.

Targets: PackageBuilderKit (library: PMTilesHeader, SigningKeys, CatalogGenerator, CommandLineTool, Fixtures) and the executable orix-package. No argument-parsing dependency. Specifications: docs/ORIXMAP_FORMAT.md, docs/CATALOG_API.md.

# Commands

sh
cd Infrastructure/package-builder && swift build -c release      # .build/release/orix-package

# 1. Key (once per key; development keys go under data/dev-signing/, which is git-ignored)
orix-package keygen --out data/dev-signing --label "development (not for production)"
#    → orixmap-<keyid>.key (mode 600), .pub, .trust.json; prints the Swift and JSON snippets for the app trust store

# 2. Build + sign (zoom range and bounds are read from the PMTiles v3 header; --bbox overrides the bounds)
orix-package build --region ca-qc-montreal --name-en "Greater Montréal" --name-fr "Grand Montréal" \
  --data-version 2026.11.24 --data-timestamp 2026-11-24T00:00:00Z \
  --map data/build/montreal.pmtiles --search data/build/montreal/search.sqlite \
  --routing data/build/routing/montreal.orixgraph \
  --licences Infrastructure/package-builder/licences-osm.json \
  --key data/dev-signing/orixmap-<keyid>.key --out data/package-builder/ca-qc-montreal-2026.11.24.orixmap
#    optional: --terrain f.pmtiles  --bbox minLon,minLat,maxLon,maxLat  --languages en,fr  --name es="…"
#              --search-format N --routing-format N (component format versions, default 1)  --min-app-version 1.0
#              --builder tile-builder=0.3.1 (repeatable)  --build-date 2026-11-25T08:00:00Z
#    key: --key <file> or environment variable ORIX_PACKAGE_SIGNING_KEY_FILE=<file>

# 3. Check
orix-package verify  file.orixmap --trust data/dev-signing/orixmap-<keyid>.trust.json    # or the .pub file
orix-package inspect file.orixmap [--trust …] [--json]     # header, manifest, component table; --json = signed manifest bytes

# 4. Publish into a distribution directory and (re)generate catalog.json, regions/<id>.json, regions/<id>/versions.json
orix-package publish file.orixmap --dir <dist> --trust <trust>
orix-package catalog --dir <dist> --trust <trust>                                   # regenerate after manual changes
orix-package catalog --dir <dist> --trust <trust> --latest ca-qc-montreal=2026.11.10  # rollback of "latest" (kept in pins.json)
orix-package catalog --dir <dist> --trust <trust> --unpin ca-qc-montreal

# Development helpers
orix-package install file.orixmap --store <dir> --trust <trust>   # what the phone does (RegionStore), on this Mac
orix-package fixture --kind pmtiles|blob --size <bytes> --out <file>   # synthetic test data, not a map
./bench.sh <key> <trust> <work dir>                               # the measurements below

Exit status: 0 success, 1 failure (message on stderr), 2 usage.

Private key handling: the file must be a regular file (symbolic links refused), owned by the current user, with no group/other permission (chmod 600); anything else is refused before reading. keygen creates the directory with mode 700 and the key with O_EXCL and mode 600, and never overwrites. Expected location on the build node: ~/.config/orix-maps/signing/. The production key does not exist yet: it is to be generated on the build node. The key under data/dev-signing/ is a development key (id 92853604e9033917) — do not put it in a release trust store.

build checks: PMTiles magic PMTiles + version 3 for --map and --terrain, every header section inside the file (overflow-safe), min_zoom ≤ max_zoom ≤ 30, tile type MVT for --map; then everything PackageManifest.validate checks. It hashes each component, lays the file out, signs, writes to a temporary file and renames; while copying it re-hashes each component and fails if a file changed since it was hashed.

catalog fully verifies every package under files/, refuses misplaced or unexpected files, and writes versions.json → <id>.json → catalog.json (last), each atomically. See docs/CATALOG_API.md §7 for the publication and rollback procedure, and docs/ORIXMAP_FORMAT.md §5.1 for key rotation.

# End-to-end run on real components (2026-11-25)

Components produced by the other builders were present in data/build/ when this was run: montreal.pmtiles (96 370 599 B, zoom 0–15), montreal/search.sqlite (40 460 288 B), routing/montreal.orixgraph (99 315 712 B). They were taken as they were at 03:33 (their builders may still be iterating; component format versions were recorded as 1 for search and routing, the default — to be confirmed by their owners).

Step Result
build 236 150 784 B, overhead 4 185 B, 0.19 s
/usr/bin/time -l orix-package verify 0.081 s, max RSS 9.27 MB, peak footprint 3.87 MB
inspect --trust signature valid, layout valid, preamble 1 521 B
/usr/bin/time -l orix-package install 0.133 s, max RSS 13.4 MB, peak footprint 5.93 MB; installed files identical to the sources (cmp)
publish data/package-builder/dist/ with catalog.json, regions/ca-qc-montreal.json, regions/ca-qc-montreal/versions.json, files/…

Left in place (git-ignored): data/package-builder/ca-qc-montreal-2026.11.24.orixmap and data/package-builder/dist/, a ready-to-serve development distribution signed with the development key.

Synthetic measurements (./bench.sh, same machine: Mac17,6, M5 Max, release build, warm cache):

Package build verify (3 runs) install (3 runs) peak footprint verify / install
50 MB 0.04 s 0.018 / 0.018 / 0.018 s 0.053 / 0.048 / 0.046 s 3.87 MB / 5.9 MB
300 MB 0.23 s 0.105 / 0.106 / 0.106 s 0.157 / 0.153 / 0.153 s 3.87 MB / 5.9 MB

# Tests

swift test — 8 tests in 3 suites, all passing (2026-11-25): PMTiles header reader (valid archive, every rejection, 20 000 random inputs), signing keys (modes, loose permissions, symbolic links, garbage), and the command driven in-process end to end (keygen → fixture → build → verify → inspect → install; bad inputs; publish → catalog → rollback pin → unpin → corrupted / misplaced / stray artefacts → region withdrawal).

# Known limits / Not done

  • catalog re-verifies (re-hashes) every published package on each run: linear in the size of the distribution.
  • Only the PMTiles header is read: directories, metadata and tiles are not validated. The search and routing components are opaque to the builder (no check of the SQLite schema or of the graph magic).
  • --search-format / --routing-format are given by the caller; nothing reads them from the files.
  • fixture files are structurally valid but empty of map content (zero tiles).
  • No production key, no deployment to the node, no upload: publish works on a local directory.
  • Keys are raw base64 files; no hardware token / Secure Enclave / passphrase.
  • File headers are left to the repository header tool (docs/CONVENTIONS.md).
Files main
Menu

Theme