Created
July 25, 2022 16:42
-
-
Save stephan-strate/2f410549015e99a41293b5e2761d388b to your computer and use it in GitHub Desktop.
Zero-downtime deployer grav recipe
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
<?php | |
namespace Deployer; | |
require_once 'recipe/common.php'; | |
add('recipes', ['grav']); | |
add('shared_dirs', [ | |
'user/accounts', | |
'user/config', | |
'user/data', | |
'user/pages', | |
'user/assets', | |
'backup', | |
'logs', | |
]); | |
add('writable_dirs', [ | |
'cache', | |
'logs', | |
'tmp', | |
'backup', | |
'images', | |
'assets', | |
'user/accounts', | |
'user/data', | |
]); | |
/** | |
* Run grav related command. | |
* | |
* @param string $executable The grav executable (grav, gpm, plugin). | |
* @param string $command The grav related command (with cli options if any). | |
* @param string $path Base path the executable lives in (defaults to release_path) | |
* @return callable A function that can be used as a task. | |
*/ | |
function bin(string $executable, string $command, string $path = '{{release_path}}'): callable | |
{ | |
return function () use ($path, $executable, $command) { | |
if (test("[ -d $path ]")) { | |
within($path, function () use ($executable, $command) { | |
$bin = "bin/$executable"; | |
if (test("[ -f $bin ]")) { | |
run("{{bin/php}} $bin $command"); | |
} else { | |
warning("$bin not found, skipping."); | |
} | |
}); | |
} | |
}; | |
} | |
function grav($command, $path = '{{release_path}}') | |
{ | |
return bin('grav', $command, $path); | |
} | |
desc('Create backup from Grav content'); | |
task('grav:backup', grav('backup', '{{current_path}}')); | |
desc('Removes extraneous files and folders from Grav'); | |
task('grav:clean', grav('clean')); | |
desc('Install Grav dependencies listed in .dependencies'); | |
task('grav:install', grav('install')); | |
desc('Scan contents for security vulnerabilities'); | |
task('grav:security', grav('security')); | |
set('grav_repository', 'https://github.com/getgrav/grav.git'); | |
set('grav_version', function () { | |
return getenv('GRAV_VERSION') ?: 'master'; | |
}); | |
desc('Download Grav'); | |
task('grav:download', function () { | |
run('{{bin/git}} clone --branch {{grav_version}} --depth 1 {{grav_repository}} {{release_path}}'); | |
// remove all git related files | |
run('rm -rf {{release_path}}/.git'); | |
// remove user folder as we want to replace it | |
run('rm -rf {{release_path}}/user'); | |
}); | |
task('deploy:prepare', [ | |
'deploy:info', | |
'deploy:setup', | |
'deploy:lock', | |
'deploy:release', | |
]); | |
task('deploy', [ | |
'grav:backup', | |
'deploy:prepare', | |
'grav:download', | |
'deploy:update_code', | |
'deploy:shared', | |
'deploy:writable', | |
'deploy:vendors', | |
'grav:install', | |
'grav:clean', | |
'grav:security', | |
'deploy:publish', | |
]); | |
after('deploy:failed', 'deploy:unlock'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment