deployer/recipe/symfony.php
2016-11-03 23:47:16 +01:00

127 lines
2.9 KiB
PHP

<?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.
*/
require_once __DIR__ . '/common.php';
/**
* Symfony Configuration
*/
// Symfony shared dirs
set('shared_dirs', ['app/logs']);
// Symfony shared files
set('shared_files', ['app/config/parameters.yml']);
// Symfony writable dirs
set('writable_dirs', ['app/cache', 'app/logs']);
// Assets
set('assets', ['web/css', 'web/images', 'web/js']);
// Default true - BC for Symfony < 3.0
set('dump_assets', true);
// Environment vars
env('env_vars', 'SYMFONY_ENV=prod');
env('env', 'prod');
// Adding support for the Symfony3 directory structure
set('bin_dir', 'app');
set('var_dir', 'app');
/**
* Create cache dir
*/
task('deploy:create_cache_dir', function () {
// Set cache dir
env('cache_dir', '{{release_path}}/' . trim(get('var_dir'), '/') . '/cache');
// Remove cache dir if it exist
run('if [ -d "{{cache_dir}}" ]; then rm -rf {{cache_dir}}; fi');
// Create cache dir
run('mkdir -p {{cache_dir}}');
// Set rights
run("chmod -R g+w {{cache_dir}}");
})->desc('Create cache dir');
/**
* Normalize asset timestamps
*/
task('deploy:assets', function () {
$assets = implode(' ', array_map(function ($asset) {
return "{{release_path}}/$asset";
}, get('assets')));
$time = date('YmdHi.s');
run("find $assets -exec touch -t $time {} ';' &> /dev/null || true");
})->desc('Normalize asset timestamps');
/**
* Dump all assets to the filesystem
*/
task('deploy:assetic:dump', function () {
if (!get('dump_assets')) {
return;
}
run('{{bin/php}} {{release_path}}/' . trim(get('bin_dir'), '/') . '/console assetic:dump --env={{env}} --no-debug');
})->desc('Dump assets');
/**
* Warm up cache
*/
task('deploy:cache:warmup', function () {
run('{{bin/php}} {{release_path}}/' . trim(get('bin_dir'), '/') . '/console cache:warmup --env={{env}} --no-debug');
})->desc('Warm up cache');
/**
* Migrate database
*/
task('database:migrate', function () {
run('{{bin/php}} {{release_path}}/' . trim(get('bin_dir'), '/') . '/console doctrine:migrations:migrate --env={{env}} --no-debug --no-interaction --allow-no-migration');
})->desc('Migrate database');
/**
* Remove app_dev.php files
*/
task('deploy:clear_controllers', function () {
run("rm -f {{release_path}}/web/app_*.php");
run("rm -f {{release_path}}/web/config.php");
})->setPrivate();
after('deploy:update_code', 'deploy:clear_controllers');
/**
* Main task
*/
task('deploy', [
'deploy:prepare',
'deploy:release',
'deploy:update_code',
'deploy:create_cache_dir',
'deploy:shared',
'deploy:assets',
'deploy:vendors',
'deploy:assetic:dump',
'deploy:cache:warmup',
'deploy:writable',
'deploy:symlink',
'cleanup',
])->desc('Deploy your project');
after('deploy', 'success');