deployer/recipe/symfony.php

146 lines
3.4 KiB
PHP
Raw Normal View History

<?php
2016-01-11 12:51:59 +07:00
/* (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.
*/
2014-07-06 22:28:15 +04:00
2016-01-11 14:00:45 +07:00
namespace Deployer;
require_once __DIR__ . '/common.php';
2014-07-06 18:30:21 +04:00
2014-07-08 16:59:34 +04:00
/**
2015-02-25 12:54:06 +03:00
* Symfony Configuration
2014-07-08 16:59:34 +04:00
*/
2014-07-06 22:28:15 +04:00
2016-11-05 17:50:18 +07:00
// Symfony build set
set('env', 'prod');
2015-02-25 12:54:06 +03:00
// Symfony shared dirs
set('shared_dirs', ['app/logs']);
2014-07-06 18:30:21 +04:00
2015-02-25 12:54:06 +03:00
// Symfony shared files
set('shared_files', ['app/config/parameters.yml']);
2014-07-06 18:30:21 +04:00
2015-02-25 12:54:06 +03:00
// Symfony writable dirs
set('writable_dirs', ['app/cache', 'app/logs']);
// Clear paths
set('clear_paths', ['web/app_*.php', 'web/config.php']);
2015-02-25 12:54:06 +03:00
// Assets
set('assets', ['web/css', 'web/images', 'web/js']);
// Requires non symfony-core package `kriswallsmith/assetic` to be installed
set('dump_assets', false);
2015-02-25 12:54:06 +03:00
// Environment vars
2016-11-05 17:50:18 +07:00
set('env_vars', 'SYMFONY_ENV={{env}}');
2014-07-06 22:28:15 +04:00
// Adding support for the Symfony3 directory structure
set('bin_dir', 'app');
set('var_dir', 'app');
// Symfony console bin
2016-11-05 17:50:18 +07:00
set('bin/console', function () {
return sprintf('{{release_path}}/%s/console', trim(get('bin_dir'), '/'));
});
// Symfony console opts
2016-11-05 17:50:18 +07:00
set('console_options', function () {
$options = '--no-interaction --env={{env}}';
2016-11-05 17:50:18 +07:00
return get('env') !== 'prod' ? $options : sprintf('%s --no-debug', $options);
});
2014-07-06 18:30:21 +04:00
2014-07-08 16:59:34 +04:00
/**
2015-02-25 12:54:06 +03:00
* Create cache dir
2014-07-08 16:59:34 +04:00
*/
2015-02-25 12:54:06 +03:00
task('deploy:create_cache_dir', function () {
// Set cache dir
2016-11-05 17:50:18 +07:00
set('cache_dir', '{{release_path}}/' . trim(get('var_dir'), '/') . '/cache');
2015-02-25 12:54:06 +03:00
// Remove cache dir if it exist
2015-03-23 09:19:12 +07:00
run('if [ -d "{{cache_dir}}" ]; then rm -rf {{cache_dir}}; fi');
2015-02-25 12:54:06 +03:00
// Create cache dir
2015-03-23 09:19:12 +07:00
run('mkdir -p {{cache_dir}}');
2015-02-25 12:54:06 +03:00
// Set rights
2015-03-23 09:19:12 +07:00
run("chmod -R g+w {{cache_dir}}");
2015-02-25 12:54:06 +03:00
})->desc('Create cache dir');
2014-07-08 16:59:34 +04:00
/**
* Normalize asset timestamps
*/
2014-07-06 22:28:15 +04:00
task('deploy:assets', function () {
2015-02-25 12:54:06 +03:00
$assets = implode(' ', array_map(function ($asset) {
2015-03-23 09:19:12 +07:00
return "{{release_path}}/$asset";
2015-02-25 12:54:06 +03:00
}, get('assets')));
2014-07-06 22:28:15 +04:00
run(sprintf('find %s -exec touch -t %s {} \';\' &> /dev/null || true', $assets, date('Ymdhi.s')));
2015-02-25 12:54:06 +03:00
})->desc('Normalize asset timestamps');
2014-07-06 22:28:15 +04:00
/**
* Install assets from public dir of bundles
*/
task('deploy:assets:install', function () {
run('{{env_vars}} {{bin/php}} {{bin/console}} assets:install {{console_options}} {{release_path}}/web');
})->desc('Install bundle assets');
2014-07-08 16:59:34 +04:00
/**
* Dump all assets to the filesystem
*/
2014-07-06 22:28:15 +04:00
task('deploy:assetic:dump', function () {
if (get('dump_assets')) {
run('{{env_vars}} {{bin/php}} {{bin/console}} assetic:dump {{console_options}}');
2015-12-18 01:50:07 +01:00
}
2015-02-25 12:54:06 +03:00
})->desc('Dump assets');
2014-07-06 22:28:15 +04:00
2014-07-08 16:59:34 +04:00
/**
* Warm up cache
*/
2014-07-06 22:28:15 +04:00
task('deploy:cache:warmup', function () {
run('{{env_vars}} {{bin/php}} {{bin/console}} cache:warmup {{console_options}}');
2015-02-25 12:54:06 +03:00
})->desc('Warm up cache');
2014-07-08 16:59:34 +04:00
/**
* Migrate database
*/
2014-07-06 22:28:15 +04:00
task('database:migrate', function () {
run('{{env_vars}} {{bin/php}} {{bin/console}} doctrine:migrations:migrate {{console_options}} --allow-no-migration');
2015-02-25 12:54:06 +03:00
})->desc('Migrate database');
2014-07-08 16:59:34 +04:00
/**
* Main task
*/
task('deploy', [
2014-07-06 22:28:15 +04:00
'deploy:prepare',
2016-11-05 12:56:53 +07:00
'deploy:lock',
2015-02-25 12:54:06 +03:00
'deploy:release',
2014-07-06 18:30:21 +04:00
'deploy:update_code',
'deploy:clean',
2015-02-25 12:54:06 +03:00
'deploy:create_cache_dir',
2014-07-06 22:28:15 +04:00
'deploy:shared',
'deploy:assets',
'deploy:vendors',
'deploy:assets:install',
2014-07-06 22:28:15 +04:00
'deploy:assetic:dump',
'deploy:cache:warmup',
'deploy:writable',
2014-07-06 22:28:15 +04:00
'deploy:symlink',
2016-11-05 12:56:53 +07:00
'deploy:unlock',
'cleanup',
2014-07-08 16:59:34 +04:00
])->desc('Deploy your project');
2014-07-06 18:30:21 +04:00
// Display success message on completion
2015-02-25 12:54:06 +03:00
after('deploy', 'success');