deployer/recipe/symfony.php

129 lines
2.7 KiB
PHP
Raw Normal View History

<?php
/* (c) Anton Medvedev <anton@elfet.ru>
*
* 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
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
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']);
// Assets
set('assets', ['web/css', 'web/images', 'web/js']);
// Environment vars
env('env_vars', 'SYMFONY_ENV=prod');
env('env', 'prod');
2014-07-06 22:28:15 +04:00
// Adding support for the Symfony3 directory structure
set('bin_dir', 'app');
set('var_dir', 'app');
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
env('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
$time = date('Ymdhi.s');
2014-07-06 22:28:15 +04:00
2014-07-08 16:59:34 +04:00
run("find $assets -exec touch -t $time {} ';' &> /dev/null || true");
2015-02-25 12:54:06 +03:00
})->desc('Normalize asset timestamps');
2014-07-06 22:28:15 +04:00
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 () {
run('php {{release_path}}/' . trim(get('bin_dir'), '/') . '/console assetic:dump --env={{env}} --no-debug');
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('php {{release_path}}/' . trim(get('bin_dir'), '/') . '/console cache:warmup --env={{env}} --no-debug');
2014-07-06 22:28:15 +04:00
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('php {{release_path}}/' . trim(get('bin_dir'), '/') . '/console doctrine:migrations:migrate --env={{env}} --no-debug --no-interaction');
2015-02-25 12:54:06 +03:00
})->desc('Migrate database');
2014-07-08 16:59:34 +04:00
/**
* Remove app_dev.php files
*/
2014-07-06 22:28:15 +04:00
task('deploy:clear_controllers', function () {
2014-07-08 16:59:34 +04:00
2015-03-23 09:19:12 +07:00
run("rm -f {{release_path}}/web/app_*.php");
2015-08-18 14:43:27 +02:00
run("rm -f {{release_path}}/web/config.php");
2014-07-06 22:28:15 +04:00
2015-02-25 12:54:06 +03:00
})->setPrivate();
2014-07-08 16:59:34 +04:00
2015-02-25 12:54:06 +03:00
after('deploy:update_code', 'deploy:clear_controllers');
2014-07-08 16:59:34 +04:00
/**
* Main task
*/
2014-07-06 18:30:21 +04:00
task('deploy', [
2014-07-06 22:28:15 +04:00
'deploy:prepare',
2015-02-25 12:54:06 +03:00
'deploy:release',
2014-07-06 18:30:21 +04:00
'deploy:update_code',
2015-02-25 12:54:06 +03:00
'deploy:create_cache_dir',
2014-07-06 22:28:15 +04:00
'deploy:shared',
2015-02-25 12:54:06 +03:00
'deploy:writable',
2014-07-06 22:28:15 +04:00
'deploy:assets',
'deploy:vendors',
'deploy:assetic:dump',
'deploy:cache:warmup',
'deploy:symlink',
'cleanup',
2014-07-08 16:59:34 +04:00
])->desc('Deploy your project');
2014-07-06 18:30:21 +04:00
2015-02-25 12:54:06 +03:00
after('deploy', 'success');