deployer/recipe/laravel.php

205 lines
5.6 KiB
PHP
Raw Normal View History

2015-05-18 11:26:59 +07:00
<?php
2016-01-11 12:51:59 +07:00
/* (c) Anton Medvedev <anton@medv.io>
2015-05-18 11:26:59 +07:00
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/*
* This recipe supports Laravel 5.1+, for older versions, please read the documentation https://github.com/deployphp/docs
*/
2015-05-18 11:26:59 +07:00
2016-01-11 14:00:45 +07:00
namespace Deployer;
2015-05-18 11:26:59 +07:00
require_once __DIR__ . '/common.php';
// Laravel shared dirs
set('shared_dirs', [
2017-02-14 17:32:00 +02:00
'storage',
]);
2015-05-18 11:26:59 +07:00
// Laravel shared file
set('shared_files', [
2017-02-14 17:32:00 +02:00
'.env',
]);
2015-05-18 11:26:59 +07:00
// Laravel writable dirs
set('writable_dirs', [
'bootstrap/cache',
'storage',
'storage/app',
'storage/app/public',
'storage/framework',
'storage/framework/cache',
'storage/framework/sessions',
'storage/framework/views',
'storage/logs',
]);
2015-05-18 11:26:59 +07:00
set('laravel_version', function () {
$result = run('cd {{release_path}} && {{bin/php}} artisan --version');
preg_match_all('/(\d+\.?)+/', $result, $matches);
$version = $matches[0][0] ?? 5.5;
return $version;
});
/**
* Helper tasks
*/
desc('Disable maintenance mode');
task('artisan:up', function () {
$output = run('if [ -f {{deploy_path}}/current/artisan ]; then {{bin/php}} {{deploy_path}}/current/artisan up; fi');
2016-10-11 14:50:17 +02:00
writeln('<info>' . $output . '</info>');
});
desc('Enable maintenance mode');
task('artisan:down', function () {
$output = run('if [ -f {{deploy_path}}/current/artisan ]; then {{bin/php}} {{deploy_path}}/current/artisan down; fi');
2016-11-19 15:13:32 +07:00
writeln('<info>' . $output . '</info>');
});
desc('Execute artisan migrate');
task('artisan:migrate', function () {
2016-11-19 15:13:32 +07:00
run('{{bin/php}} {{release_path}}/artisan migrate --force');
})->once();
desc('Execute artisan migrate:fresh');
task('artisan:migrate:fresh', function () {
run('{{bin/php}} {{release_path}}/artisan migrate:fresh --force');
});
desc('Execute artisan migrate:rollback');
task('artisan:migrate:rollback', function () {
2016-10-11 14:50:17 +02:00
$output = run('{{bin/php}} {{release_path}}/artisan migrate:rollback --force');
writeln('<info>' . $output . '</info>');
});
desc('Execute artisan migrate:status');
task('artisan:migrate:status', function () {
2016-10-11 14:50:17 +02:00
$output = run('{{bin/php}} {{release_path}}/artisan migrate:status');
writeln('<info>' . $output . '</info>');
});
desc('Execute artisan db:seed');
task('artisan:db:seed', function () {
2016-10-11 14:50:17 +02:00
$output = run('{{bin/php}} {{release_path}}/artisan db:seed --force');
writeln('<info>' . $output . '</info>');
});
desc('Execute artisan cache:clear');
task('artisan:cache:clear', function () {
2016-11-19 15:13:32 +07:00
run('{{bin/php}} {{release_path}}/artisan cache:clear');
});
desc('Execute artisan config:cache');
task('artisan:config:cache', function () {
2016-11-19 15:13:32 +07:00
run('{{bin/php}} {{release_path}}/artisan config:cache');
});
desc('Execute artisan route:cache');
task('artisan:route:cache', function () {
2016-11-19 15:13:32 +07:00
run('{{bin/php}} {{release_path}}/artisan route:cache');
});
desc('Execute artisan view:cache');
task('artisan:view:cache', function () {
$needsVersion = 5.6;
$currentVersion = get('laravel_version');
if (version_compare($currentVersion, $needsVersion, '>=')) {
run('{{bin/php}} {{release_path}}/artisan view:cache');
} else {
run('{{bin/php}} {{release_path}}/artisan view:clear');
}
});
2016-11-25 14:58:13 +07:00
desc('Execute artisan optimize');
task('artisan:optimize', function () {
$deprecatedVersion = 5.5;
$readdedInVersion = 5.7;
$currentVersion = get('laravel_version');
if (
version_compare($currentVersion, $deprecatedVersion, '<') ||
version_compare($currentVersion, $readdedInVersion, '>=')
) {
run('{{bin/php}} {{release_path}}/artisan optimize');
}
2016-11-25 14:58:13 +07:00
});
desc('Execute artisan optimize:clear');
task('artisan:optimize:clear', function () {
$needsVersion = 5.7;
$currentVersion = get('laravel_version');
if (version_compare($currentVersion, $needsVersion, '>=')) {
run('{{bin/php}} {{release_path}}/artisan optimize:clear');
}
});
2017-02-13 11:32:21 +02:00
desc('Execute artisan queue:restart');
task('artisan:queue:restart', function () {
run('{{bin/php}} {{release_path}}/artisan queue:restart');
});
desc('Execute artisan horizon:terminate');
task('artisan:horizon:terminate', function () {
run('{{bin/php}} {{release_path}}/artisan horizon:terminate');
});
2017-04-07 10:27:29 +02:00
desc('Execute artisan storage:link');
task('artisan:storage:link', function () {
$needsVersion = 5.3;
$currentVersion = get('laravel_version');
if (version_compare($currentVersion, $needsVersion, '>=')) {
run('{{bin/php}} {{release_path}}/artisan storage:link');
}
2017-04-07 10:27:29 +02:00
});
/**
* Task deploy:public_disk support the public disk.
* To run this task automatically, please add below line to your deploy.php file
*
* before('deploy:symlink', 'deploy:public_disk');
*
* @see https://laravel.com/docs/5.2/filesystem#configuration
*/
desc('Make symlink for public disk');
task('deploy:public_disk', function () {
// Remove from source.
run('if [ -d $(echo {{release_path}}/public/storage) ]; then rm -rf {{release_path}}/public/storage; fi');
// Create shared dir if it does not exist.
run('mkdir -p {{deploy_path}}/shared/storage/app/public');
// Symlink shared dir to release dir
2016-11-05 13:40:12 +07:00
run('{{bin/symlink}} {{deploy_path}}/shared/storage/app/public {{release_path}}/public/storage');
});
2015-05-18 11:26:59 +07:00
/**
* Main task
*/
desc('Deploy your project');
task('deploy', [
2017-08-12 12:01:27 +03:00
'deploy:info',
2015-05-18 11:26:59 +07:00
'deploy:prepare',
2016-11-05 12:56:53 +07:00
'deploy:lock',
2015-05-18 11:26:59 +07:00
'deploy:release',
'deploy:update_code',
'deploy:shared',
'deploy:vendors',
'deploy:writable',
2017-04-07 10:51:13 +02:00
'artisan:storage:link',
'artisan:view:cache',
'artisan:config:cache',
2016-11-25 14:58:13 +07:00
'artisan:optimize',
'deploy:symlink',
'deploy:unlock',
'cleanup',
]);
2015-05-18 11:26:59 +07:00
after('deploy', 'success');