Repository navigation
Fix flatpack:build after a deploy into a new release directory - #4
Merged
Merged
Conversation
With zero-downtime deploys the app moves to a new path while storage is shared, so the compiled content (which holds absolute paths) comes with it. Stache::clear() forgets each store's saved keys but not the ones it has in memory, so in flatpack:build every file looked like a duplicate of itself at its old path, nothing was built, and the cleared store was then persisted. flatpack:build now clears the keys in memory too, and a build that throws discards what it buffered, leaving the last good build in place. A refresh of content built for another path builds everything instead, and flatpack:status says when that's needed. The parity suite moves the app and builds, then moves it again and refreshes. bin/parity lets Composer update every package when installing a Statamic version: the skeleton pins laravel/pail to a release that needs Laravel 12, which Statamic 5.11 can't use.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With zero-downtime deploys (Forge's release directories, Envoyer, Deployer), each deploy puts the app at a new path while
storageis shared. Flatpack's compiled content lives instorageand holds absolute paths, so it arrives at the new path pointing at the old one.What went wrong
flatpack:buildrunsStache::clear()and thenStache::warm()in one process. Statamic'sKeys::clear()forgets each store's saved keys but leaves the keys it already has in memory. Those still pointed at the old path, so during the warm every file was a "duplicate" of itself at its old path. No collections were found, the build threwCall to a member function sites() on null, and the cleared store was written out on shutdown. The result: a failed deploy and a live site with no entries until someone rebuilt from scratch.Reproduced on Statamic 6.40 with a 9,000-entry site: build, copy the app to a new directory, build again → error, 0 entries. Affects 1.0.0 and 1.1.0.
What changes
flatpack:buildclears each store's keys in memory after clearing the Stache (plain stores first, since finding a collection's or taxonomy's stores reads those).flatpack:refresh, and Refresh in the Control Panel, build everything when the content was compiled for another path. Before, refresh threw. The path is recorded at build time; for builds from before this change it's worked out from the saved collection paths.flatpack:statusshows "built for another path" when that's the case.Checks
bin/paritypasses locally on Statamic 6 (latest), 5 (latest) and 5.11.0. One of five local runs on 5.11.0 failed the first new scenario and I couldn't reproduce it in three more, so watch that job.Also in here
bin/paritynow lets Composer update every package when installing a Statamic version. The Statamic 5 skeleton pinslaravel/pailto a release that needs Laravel 12, which Statamic 5.11 can't use, so the "Statamic 5 (earliest supported)" job has been failing to install on every branch, main included.Not covered
A site that deploys to a new path and runs neither
flatpack:buildnorflatpack:refreshkeeps serving the old build, with entry paths pointing at the previous release. Reads work; saves from the Control Panel would write to the old release. The deploy docs already say to runflatpack:buildon every deploy.Until this is released
Deleting the store before building avoids the failure, at the cost of an empty store while the build runs:
rm -rf storage/statamic/flatpack && php please flatpack:build.