I’ve inherited range of Magento 2 continuous delivery pipelines. Most suffering
from excessive downtime during deployments. Ideally, downtime should only be
needed when there is a need for running
setup:upgrade. Here is an example of
deployment steps developed by a prominent Adobe partner who will rename
The entire process leaves the site inaccessible for about 8 minutes, deploying
to 4-5 nodes. Executing
setup:upgrade accounts for 30 seconds of the downtime.
The pipeline puts the site in maintenance mode before pushing code to the nodes
because code was going directly into the document root. There is also no reason
for taking the site down when stopping the crons in our case. In the event of a
rollback we are left repeating the entire process.
Anistrano is an Anisble port of Capistrano. This particular pipeline was already using Ansible for deployment tasks making Anistrano a great fit. The Anistrano docs provide a great primer on the main workflow. I recommend reading the docs if you are unfamiliar with Capistrano or Anistrano.
I set out building a quick POC for experimenting with Anistrano and Magento2. Ansitrano natively solves issues with the existing CD job.
Here’s the workflow I originally envisioned:
setup:db:status. We’ll use the output of the command for determining if the site should be placed in maintenance mode and running
php-fpm. This clears opcache and prevents potential issues from swapping the symlinked document root when
validate_timestampsis disabled (it should be on production servers).
setup:upgradeif the schema requires update. Otherwise, we flush the cache.
This limits downtime to about 45s when
setup:upgrade. The downtime is just a
few seconds when not updating the schema. You can find the Ansitrano tasks used
in this POC on GitHub