What will you do after you deploy?
A key part of Platform.sh’s benefit comes from its integrated build and deploy hooks. Deploying a new version of your site or application rarely means simply dumping what’s in Git onto a server anymore. Platform.sh was built from the ground up to let you execute whatever commands you need to “build” your application — turning what’s in Git into what’s actually on the server — and then to “deploy” the application — cleanup tasks like database migrations that should be run before the site is opened to visitors again.
There’s a caveat there, however. Some deploy tasks need to block the site from new visitors until they complete; think updating the database schema, for instance. Others may not really need exclusive access to the site, but they still get it. That keeps the site unresponsive for critical seconds until those tasks complete.
So, let’s fix that. We’ve now added a third hook,
post_deploy. It works pretty much as you’d expect. You can do all the same things in it that you can do with a
deploy hook, but it runs after the site is reopened to the world to accept new requests. Any tasks that don’t need exclusive access to the database can be moved there, keeping the site up and responsive as much as possible while allowing for more robust and flexible automated tasks.
For example, the following configuration would run any pending database updates as part of the
deploy hook but then import new content in the
post_deploy hook. The new content will become available as soon as possible but the site will still be up and running while it’s being updated. Once the import is done we’ll also clear the cache a second time to ensure the new content is visible to the next request.
hooks: deploy: | set -e update_db.php clear_cache.php post_deploy: | set -e migrate_content.php import/ clear_cache.php
What’s “safe” to move to the
post_deploy hook? That’s up to you. What does or does not need an exclusive database lock will vary by site. Sometimes a cache clear is safe to do post-open, other times not. You get to make that determination for your application.
See the hook documentation for more information, and enjoy faster deploy tasks.