2014-07-06 14:02:23 +04:00
|
|
|
<?php
|
2016-01-11 12:51:59 +07:00
|
|
|
/* (c) Anton Medvedev <anton@medv.io>
|
2014-07-06 14:02:23 +04:00
|
|
|
*
|
|
|
|
* 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;
|
|
|
|
|
2014-07-12 14:23:22 +04:00
|
|
|
require_once __DIR__ . '/common.php';
|
2014-07-06 18:30:21 +04:00
|
|
|
|
2016-06-05 12:58:34 -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
|
2017-08-12 20:31:19 +03:00
|
|
|
set('symfony_env', 'prod');
|
2016-06-05 12:58:34 -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']);
|
|
|
|
|
2016-11-17 23:35:25 +07:00
|
|
|
// 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']);
|
2016-06-05 12:58:34 -04:00
|
|
|
|
|
|
|
// Requires non symfony-core package `kriswallsmith/assetic` to be installed
|
|
|
|
set('dump_assets', false);
|
2015-02-25 12:54:06 +03:00
|
|
|
|
|
|
|
// Environment vars
|
2017-08-12 20:31:19 +03:00
|
|
|
set('env', function () {
|
|
|
|
return [
|
|
|
|
'SYMFONY_ENV' => get('symfony_env')
|
|
|
|
];
|
|
|
|
});
|
2014-07-06 22:28:15 +04:00
|
|
|
|
2015-05-19 09:57:17 +02:00
|
|
|
// Adding support for the Symfony3 directory structure
|
|
|
|
set('bin_dir', 'app');
|
|
|
|
set('var_dir', 'app');
|
|
|
|
|
2016-06-05 12:58:34 -04:00
|
|
|
// Symfony console bin
|
2016-11-05 17:50:18 +07:00
|
|
|
set('bin/console', function () {
|
2016-06-05 12:58:34 -04:00
|
|
|
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 () {
|
2017-08-22 22:27:20 +07:00
|
|
|
$options = '--no-interaction --env={{symfony_env}}';
|
|
|
|
return get('symfony_env') !== 'prod' ? $options : sprintf('%s --no-debug', $options);
|
2016-06-05 12:58:34 -04:00
|
|
|
});
|
|
|
|
|
2018-10-13 16:02:35 +02:00
|
|
|
// Migrations configuration file
|
|
|
|
set('migrations_config', '');
|
|
|
|
|
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');
|
2014-07-07 16:28:15 +04:00
|
|
|
|
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');
|
2014-07-07 16:28:15 +04:00
|
|
|
|
2015-02-25 12:54:06 +03:00
|
|
|
// Create cache dir
|
2015-03-23 09:19:12 +07:00
|
|
|
run('mkdir -p {{cache_dir}}');
|
2014-07-07 16:28:15 +04:00
|
|
|
|
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-07 16:28:15 +04:00
|
|
|
|
|
|
|
|
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
|
|
|
|
2017-10-18 20:21:18 +02: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
|
|
|
|
|
|
|
|
2016-06-05 12:58:34 -04:00
|
|
|
/**
|
|
|
|
* Install assets from public dir of bundles
|
|
|
|
*/
|
|
|
|
task('deploy:assets:install', function () {
|
2017-08-12 20:31:19 +03:00
|
|
|
run('{{bin/php}} {{bin/console}} assets:install {{console_options}} {{release_path}}/web');
|
2016-06-05 12:58:34 -04:00
|
|
|
})->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 () {
|
2016-06-05 12:58:34 -04:00
|
|
|
if (get('dump_assets')) {
|
2017-08-12 20:31:19 +03:00
|
|
|
run('{{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
|
|
|
|
2017-06-29 14:51:31 +02:00
|
|
|
/**
|
|
|
|
* Clear Cache
|
|
|
|
*/
|
|
|
|
task('deploy:cache:clear', function () {
|
2017-08-12 20:31:19 +03:00
|
|
|
run('{{bin/php}} {{bin/console}} cache:clear {{console_options}} --no-warmup');
|
2017-06-29 14:51:31 +02:00
|
|
|
})->desc('Clear cache');
|
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 () {
|
2017-08-12 20:31:19 +03:00
|
|
|
run('{{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 () {
|
2018-10-13 16:02:35 +02:00
|
|
|
$options = '{{console_options}} --allow-no-migration';
|
|
|
|
if (get('migrations_config') !== '') {
|
|
|
|
$options = sprintf('%s --configuration={{release_path}}/{{migrations_config}}', $options);
|
|
|
|
}
|
|
|
|
|
|
|
|
run(sprintf('{{bin/php}} {{bin/console}} doctrine:migrations:migrate %s', $options));
|
2015-02-25 12:54:06 +03:00
|
|
|
})->desc('Migrate database');
|
2014-07-08 16:59:34 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Main task
|
|
|
|
*/
|
2016-04-04 17:01:55 +07:00
|
|
|
task('deploy', [
|
2017-08-12 12:01:27 +03:00
|
|
|
'deploy:info',
|
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',
|
2016-11-19 15:13:32 +07:00
|
|
|
'deploy:clear_paths',
|
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',
|
2016-06-05 12:58:34 -04:00
|
|
|
'deploy:assets:install',
|
2014-07-06 22:28:15 +04:00
|
|
|
'deploy:assetic:dump',
|
2017-06-29 14:51:31 +02:00
|
|
|
'deploy:cache:clear',
|
2014-07-06 22:28:15 +04:00
|
|
|
'deploy:cache:warmup',
|
2016-03-11 17:45:02 +01:00
|
|
|
'deploy:writable',
|
2014-07-06 22:28:15 +04:00
|
|
|
'deploy:symlink',
|
2016-11-05 12:56:53 +07:00
|
|
|
'deploy:unlock',
|
2014-07-07 16:28:15 +04:00
|
|
|
'cleanup',
|
2014-07-08 16:59:34 +04:00
|
|
|
])->desc('Deploy your project');
|
2014-07-06 18:30:21 +04:00
|
|
|
|
2016-06-05 12:58:34 -04:00
|
|
|
// Display success message on completion
|
2015-02-25 12:54:06 +03:00
|
|
|
after('deploy', 'success');
|