Replace per-extension composer install with unified autoloader#85
Replace per-extension composer install with unified autoloader#85yaronkoren merged 10 commits intomasterfrom
Conversation
Build time (extensions-skins.php): - Skip per-extension 'composer install' for extensions with 'additional steps: composer update' - Create composer.local.json with merge-plugin globs to include all canasta-extension and canasta-skin composer.json files - Run a single 'composer update' at the MediaWiki root to produce a unified vendor/autoload.php - Save a hash of all contributing composer.json files for runtime change detection Runtime (run-all.sh): - Copy user's config/composer.local.json to MW_HOME if present - Compute hash of composer.local.json + all extension/skin composer.json files (resolved through symlinks) - Re-run 'composer update' only when the hash differs from the build-time or last-run hash
Treat a missing or empty-include composer.local.json the same way: preserve the build-time autoloader as-is without running composer update. This handles old Canasta-DockerCompose templates that had empty arrays and gives admins a way to opt out of runtime updates. Add detailed comments documenting the behavior for each state of config/composer.local.json (missing, empty include, non-empty).
Instead of wildcarding extensions/*/composer.json (which picks up all extensions, including ones with broken composer.json like SubPageList), generate composer.local.json with specific entries only for extensions and skins that have "composer update" in their additional steps. User-extension and user-skin wildcards are still included so runtime additions are picked up automatically. The hash computation is also updated to only hash the files referenced in composer.local.json rather than all extension composer.json files.
Set $smwgConfigFileDir to the persistent volume (config/smw/) so smw.json survives container recreates. Automatically run setupStore.php on startup if SMW is installed but smw.json doesn't exist yet, so SMW works without manual intervention.
Use only specific entries for bundled extensions that need composer. Users who add extensions with composer dependencies should manually add entries to config/composer.local.json.
The generated composer.local.json no longer includes wildcards for user-extensions. Users should manually add entries for extensions with composer dependencies.
The composer.local.json now contains specific file paths rather than glob patterns. Rename the variable and log message to reflect this.
update.php triggers setupStore.php via SMW hooks, creating database tables and .smw.json entries. But rebuildData.php (needed for Special:Browse to work with existing content) does not run automatically. Snapshot .smw.json wiki IDs before run_autoupdate, then after it completes, run rebuildData.php for any wikis not in the snapshot (i.e. newly set up). In wiki farm mode, each wiki is checked individually so adding a new wiki triggers setup for just that wiki. SMW stores setup state in .smw.json (dot-prefixed) keyed by wiki ID in the persistent volume at $MW_VOLUME/config/smw/.
|
This looks amazing. I have one question: does CanastaBase specifically need to set $smwgConfigFileDir? Ideally, all the extension-specific stuff would go in Canasta. |
|
Good point, but CanastaDefaultSettings.php exists in this repo. If we put the change in Canasta, we'd have to do something fancy like |
|
Okay, that makes sense. Perhaps ideally there should be a second, Canasta-specific default settings file, but it seems like overkill just for a single line. And obviously SMW is a special case. |
|
🐳 The image based on a54f561a commit has been built with |
|
Okay, this looks great. Just one other question (I think): does the addition of symlinks here mean that the create-symlinks.sh script can/should be simplified? |
|
No. It just needs the canasta-* symlinks early for the bundled extensions. The full create-symlinks.sh is necessary later. |
|
Does that include create-symlinks.sh's handling of "bundled" extensions? (I assume "bundled" here, in both your and create-symlinks' parlance, means the 150+ extensions of Canasta, not just the 20 or so extensions bundled with MediaWiki.) |
|
Yes, bundled extensions includes both. |
|
Oh yeah, that's true, I forgot about the case where someone overrides a bundled extension, then removes their override... just like Claude did. :( |
|
Thank you! |
Summary
composer installinextensions-skins.php; log a message insteadextensions//skins/→canasta-extensions//canasta-skins/so composer.json references work at build timecomposer.local.jsonwith specific entries for bundled extensions that need composer (identified by "composer update" in their additional steps)composer updateto produce a unifiedvendor/autoload.phpcomposer.jsonfiles to.composer-deps-hashcomposer.local.jsonto$MW_ORIGIN_FILES/config/so it is synced to the user'sconfig/volume viarsync --ignore-existingon first container startrun-all.sh, detect changes tocomposer.local.jsonat runtime and re-runcomposer updateonly when needed; users who add extensions with composer dependencies should manually add entries toconfig/composer.local.jsoncomposer.local.jsonis missing or has an empty include array, use the build-time autoloader as-is$smwgConfigFileDirinCanastaDefaultSettings.phpto store.smw.jsonon the persistent volume (config/smw/)rebuildData.phpfor newly-setup SMW wikis: snapshot.smw.jsonwiki IDs beforerun_autoupdate(which triggerssetupStore.phpvia hooks), then runrebuildData.phpfor any new entries; supports wiki farms with per-wiki detectionCloses #84
Merge order: This PR is 1 of 4 — merge first, then CanastaWiki/Canasta#578, then CanastaWiki/Canasta-DockerCompose#91, then CanastaWiki/Canasta-CLI#236.
Test plan
vendor/directories exist undercanasta-extensions/(e.g.canasta-extensions/CirrusSearch/vendor/should not exist)composer.local.jsonexists in the built image with specific extension entries (no wildcards).composer-deps-hashexists in the built imagephp -r "require '/var/www/mediawiki/w/vendor/autoload.php'; echo class_exists('SMW\Setup') ? 'OK' : 'FAIL';"canasta create: verifyconfig/composer.local.jsonis synced from the image on first container startwfLoadExtension('SemanticMediaWiki'); enableSemantics('localhost');and verifysetupStore.phpruns automatically viaupdate.phphooks andrebuildData.phpruns afterwardconfig/smw/.smw.jsonis created on the persistent volume with a key for the wiki IDrebuildData.phpruns only for the new wikiconfig/composer.local.json, restart container, verifycomposer updaterunscomposer updateis skippedconfig/composer.local.json, restart, verify build-time autoloader is used as-is