2016-11-19 15:13:32 +07:00
|
|
|
<?php
|
|
|
|
/* (c) Anton Medvedev <anton@medv.io>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Deployer;
|
|
|
|
|
|
|
|
desc('Cleaning up old releases');
|
|
|
|
task('cleanup', function () {
|
|
|
|
$releases = get('releases_list');
|
|
|
|
$keep = get('keep_releases');
|
2017-03-26 13:16:12 +07:00
|
|
|
$sudo = get('cleanup_use_sudo') ? 'sudo' : '';
|
2018-05-03 13:31:58 +02:00
|
|
|
$runOpts = [];
|
|
|
|
if ($sudo) {
|
|
|
|
$runOpts['tty'] = get('cleanup_tty', false);
|
|
|
|
}
|
2016-11-19 15:13:32 +07:00
|
|
|
|
|
|
|
if ($keep === -1) {
|
|
|
|
// Keep unlimited releases.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-04 13:00:01 +07:00
|
|
|
while ($keep > 0) {
|
2016-11-19 15:13:32 +07:00
|
|
|
array_shift($releases);
|
|
|
|
--$keep;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($releases as $release) {
|
2018-05-03 13:31:58 +02:00
|
|
|
run("$sudo rm -rf {{deploy_path}}/releases/$release", $runOpts);
|
2016-11-19 15:13:32 +07:00
|
|
|
}
|
|
|
|
|
2017-03-26 13:16:12 +07:00
|
|
|
run("cd {{deploy_path}} && if [ -e release ]; then $sudo rm release; fi");
|
|
|
|
run("cd {{deploy_path}} && if [ -h release ]; then $sudo rm release; fi");
|
2016-11-19 15:13:32 +07:00
|
|
|
});
|