So I was chatting with @OptikWebCreative and @paulhibbitts about upgrading Grav, and best practices for doing so (also requirements, ideally). I’m sure we’ve discussed Fabric at some point in the past, and I’ve used it for a complete deployment workflow from testing to staging to production.
A PHP-alternative to Fabric is Deployer, which in many ways work the same just not with Python. I mocked up a simple example of how to upgrade a number of Grav installations (see bottom of post).
All it requires is that you install Deployer (composer require deployer/deployer
), define your sites (can be local or servers, they are local in the example), then execute tasks through php dep TASK
. The currently defined tasks are upgrade:backup
for creating a backup for each installation, upgrade:core
to upgrade Grav itself, and upgrade:plugins
to upgrade all plugins.
A “master”-task, upgrade
, runs them all and its all based on Grav’s CLI commands. Note that user-inputs are ignored (see the -y
-flag) to force upgrades to be done without asking you Yes/No for each one. Script:
<?php
/* Uses Deployer (https://github.com/deployphp/deployer), install instructions:
* https://github.com/andreybolonin/docs/blob/master/getting-started.md.
* Or simply `composer require deployer/deployer`.
*/
namespace Deployer;
require 'vendor/autoload.php';
// Configuration
set('default_stage', 'production');
// Servers
localServer('site1')
->stage('production')
->set('deploy_path', 'C:\caddy\multiupgrade\grav-skeleton-site1');
localServer('site2')
->stage('production')
->set('deploy_path', 'C:\caddy\multiupgrade\grav-skeleton-site2');
localServer('site3')
->stage('production')
->set('deploy_path', 'C:\caddy\multiupgrade\grav-skeleton-site3');
localServer('site4')
->stage('production')
->set('deploy_path', 'C:\caddy\multiupgrade\grav-skeleton-site4');
task('upgrade', [
'upgrade:backup',
'upgrade:core',
'upgrade:plugins'
]);
desc('Backup Grav installations');
task('upgrade:backup', function () {
$backup = run('php bin/grav backup');
writeln($backup);
});
desc('Upgrade Grav Core');
task('upgrade:core', function () {
$self_upgrade = run('php bin/gpm self-upgrade -y');
writeln($self_upgrade);
});
desc('Upgrade Grav Plugins');
task('upgrade:plugins', function () {
$upgrade = run('php bin/gpm update -y');
writeln($upgrade);
});