Skip to content

Warm the composer cache for reference solutions at build time - #339

Merged
AydinHassan merged 4 commits into
masterfrom
reference-packages
Oct 27, 2026
Merged

AydinHassan merged 4 commits into
masterfrom
reference-packages

Conversation

@AydinHassan

@AydinHassan AydinHassan commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Third task of #336, changed from installing packages into the image to warming the composer cache.

  • New ReferencePackages::warm(): for each reference solution with a composer.json it runs composer install in the sandbox. That keeps a committed composer.lock or writes one, and fills the shared cache. It then deletes the solution's vendor/, so an old one can't stop the cache filling.
  • PrepareSolutionListener still installs on each verify. It tries offline first (COMPOSER_DISABLE_NETWORK=1, about 0.4s for dependency-heaven), and downloads only if the cache misses. So a workshop run from a clone, where nothing called warm(), still works.
  • DirectorySolution no longer excludes composer.lock, so the lock is copied with the reference solution.
  • New warm-cache command. Workshops run it from composer post-install-cmd and post-update-cmd, so a clone, create-project or workshop-manager install warms the cache.

Tested from an empty cache: learn-you-php and php8-appreciate pass on Docker and host, and php8-appreciate's committed lock is unchanged.

phpschool.io calls warm() in build-runtime-images once this is merged, because composer doesn't run a dependency's scripts. learn-you-php and php8-appreciate add the composer scripts once this is merged.

Also tried a fresh clone of learn-you-php with an empty composer home and no warm(): dependency-heaven verifies on the host.

ReferencePackages installs each reference solution's packages once, keeping or writing its composer.lock and filling the shared cache. The verify then installs them with COMPOSER_DISABLE_NETWORK, so it never downloads. composer.lock is now copied with the reference solution.
A workshop can run without anything calling ReferencePackages, eg. from a clone, so the verify must still work then.
composer install/update warms them, and a verify downloads on a cache miss.
@AydinHassan
AydinHassan merged commit 2d7c133 into master Oct 27, 2026
4 checks passed
@AydinHassan
AydinHassan deleted the reference-packages branch October 27, 2026 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant