2014-07-12 14:23:22 +04:00
|
|
|
<?php
|
2016-01-11 12:51:59 +07:00
|
|
|
/* (c) Anton Medvedev <anton@medv.io>
|
2014-07-12 14:23:22 +04:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2016-01-11 14:00:45 +07:00
|
|
|
namespace Deployer;
|
2016-11-13 21:56:50 +07:00
|
|
|
|
2016-11-19 15:16:25 +07:00
|
|
|
require __DIR__ . '/deploy/config.php';
|
|
|
|
require __DIR__ . '/deploy/prepare.php';
|
|
|
|
require __DIR__ . '/deploy/lock.php';
|
|
|
|
require __DIR__ . '/deploy/release.php';
|
|
|
|
require __DIR__ . '/deploy/update_code.php';
|
|
|
|
require __DIR__ . '/deploy/clear_paths.php';
|
|
|
|
require __DIR__ . '/deploy/shared.php';
|
|
|
|
require __DIR__ . '/deploy/writable.php';
|
|
|
|
require __DIR__ . '/deploy/vendors.php';
|
|
|
|
require __DIR__ . '/deploy/symlink.php';
|
|
|
|
require __DIR__ . '/deploy/cleanup.php';
|
|
|
|
require __DIR__ . '/deploy/copy_dirs.php';
|
|
|
|
require __DIR__ . '/deploy/rollback.php';
|
2016-01-11 14:00:45 +07:00
|
|
|
|
2016-11-05 12:22:56 +07:00
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
|
2016-11-05 17:50:18 +07:00
|
|
|
/**
|
|
|
|
* Configuration
|
|
|
|
*/
|
|
|
|
|
2016-11-05 15:44:09 +07:00
|
|
|
set('keep_releases', 5);
|
2016-11-05 17:50:18 +07:00
|
|
|
|
2016-11-05 17:58:06 +07:00
|
|
|
set('repository', ''); // Repository to deploy.
|
2016-11-05 17:50:18 +07:00
|
|
|
set('branch', ''); // Branch to deploy.
|
|
|
|
|
2015-02-15 15:28:44 +03:00
|
|
|
set('shared_dirs', []);
|
|
|
|
set('shared_files', []);
|
2016-11-05 17:50:18 +07:00
|
|
|
|
2015-07-05 14:53:49 +02:00
|
|
|
set('copy_dirs', []);
|
2016-11-05 17:50:18 +07:00
|
|
|
|
2015-02-15 23:24:08 +03:00
|
|
|
set('writable_dirs', []);
|
2016-11-17 23:18:16 +07:00
|
|
|
set('writable_mode', 'acl'); // chmod, chown, chgrp or acl.
|
2016-11-07 20:08:38 +07:00
|
|
|
set('writable_use_sudo', false); // Using sudo in writable commands?
|
2016-11-17 23:18:16 +07:00
|
|
|
set('writable_chmod_mode', '0755'); // For chmod mode
|
2017-01-24 08:08:58 +01:00
|
|
|
set('writable_chmod_recursive', true); // For chmod mode
|
2016-11-05 17:50:18 +07:00
|
|
|
|
|
|
|
set('http_user', false);
|
2016-11-17 23:18:16 +07:00
|
|
|
set('http_group', false);
|
2016-11-05 17:50:18 +07:00
|
|
|
|
2015-09-08 11:48:07 +07:00
|
|
|
set('clear_paths', []); // Relative path from deploy_path
|
2016-11-10 12:25:06 +07:00
|
|
|
set('clear_use_sudo', false); // Using sudo in clean commands?
|
2016-06-05 12:58:34 -04:00
|
|
|
|
2016-11-05 17:50:18 +07:00
|
|
|
set('use_relative_symlink', true);
|
2016-06-05 12:58:34 -04:00
|
|
|
|
2016-11-05 17:50:18 +07:00
|
|
|
set('composer_action', 'install');
|
|
|
|
set('composer_options', '{{composer_action}} --verbose --prefer-dist --no-progress --no-interaction --no-dev --optimize-autoloader');
|
2016-06-05 12:58:34 -04:00
|
|
|
|
2016-11-05 17:50:18 +07:00
|
|
|
set('env_vars', ''); // Variable assignment before cmds (for example, SYMFONY_ENV={{set}})
|
2016-06-05 12:58:34 -04:00
|
|
|
|
2016-11-05 17:50:18 +07:00
|
|
|
set('git_cache', function () { //whether to use git cache - faster cloning by borrowing objects from existing clones.
|
2016-04-19 10:24:46 +07:00
|
|
|
$gitVersion = run('{{bin/git}} version');
|
2015-08-24 08:37:18 +07:00
|
|
|
$regs = [];
|
|
|
|
if (preg_match('/((\d+\.?)+)/', $gitVersion, $regs)) {
|
|
|
|
$version = $regs[1];
|
|
|
|
} else {
|
|
|
|
$version = "1.0.0";
|
|
|
|
}
|
|
|
|
return version_compare($version, '2.3', '>=');
|
2015-06-16 11:31:49 +02:00
|
|
|
});
|
2016-11-05 17:50:18 +07:00
|
|
|
|
2016-11-10 12:25:06 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return current release path.
|
|
|
|
*/
|
|
|
|
set('current_path', function () {
|
|
|
|
$link = run("readlink {{deploy_path}}/current")->toString();
|
|
|
|
return substr($link, 0, 1) === '/' ? $link : get('deploy_path') . '/' . $link;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-04-04 16:22:00 +07:00
|
|
|
/**
|
|
|
|
* Custom bins.
|
|
|
|
*/
|
2016-11-05 17:50:18 +07:00
|
|
|
set('bin/php', function () {
|
2016-04-04 16:22:00 +07:00
|
|
|
return run('which php')->toString();
|
|
|
|
});
|
2016-11-19 15:13:32 +07:00
|
|
|
|
2016-11-05 17:50:18 +07:00
|
|
|
set('bin/git', function () {
|
2016-04-04 16:22:00 +07:00
|
|
|
return run('which git')->toString();
|
|
|
|
});
|
2016-11-19 15:13:32 +07:00
|
|
|
|
2016-11-05 17:50:18 +07:00
|
|
|
set('bin/composer', function () {
|
2016-04-04 16:22:00 +07:00
|
|
|
if (commandExist('composer')) {
|
2017-01-27 21:42:18 +01:00
|
|
|
$composer = '{{bin/php}} ' . run('which composer')->toString();
|
2016-04-04 16:22:00 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($composer)) {
|
2016-04-12 03:06:44 +02:00
|
|
|
run("cd {{release_path}} && curl -sS https://getcomposer.org/installer | {{bin/php}}");
|
2016-04-11 11:18:16 +02:00
|
|
|
$composer = '{{bin/php}} {{release_path}}/composer.phar';
|
2016-04-04 16:22:00 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return $composer;
|
|
|
|
});
|
2016-11-19 15:13:32 +07:00
|
|
|
|
2016-11-05 17:50:18 +07:00
|
|
|
set('bin/symlink', function () {
|
|
|
|
if (get('use_relative_symlink')) {
|
2016-11-07 12:47:29 +07:00
|
|
|
// Check if target system supports relative symlink.
|
2016-11-05 15:42:44 +07:00
|
|
|
if (run('if [[ "$(man ln)" =~ "--relative" ]]; then echo "true"; fi')->toBool()) {
|
2016-11-05 13:40:12 +07:00
|
|
|
return 'ln -nfs --relative';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 'ln -nfs';
|
|
|
|
});
|
2015-02-24 17:13:10 +03:00
|
|
|
|
|
|
|
/**
|
2015-02-24 18:47:48 +03:00
|
|
|
* Default arguments and options.
|
2015-02-24 17:13:10 +03:00
|
|
|
*/
|
2016-11-12 18:16:50 +07:00
|
|
|
argument('stage', InputArgument::OPTIONAL, 'Run tasks only on this server or group of servers');
|
|
|
|
option('tag', null, InputOption::VALUE_OPTIONAL, 'Tag to deploy');
|
|
|
|
option('revision', null, InputOption::VALUE_OPTIONAL, 'Revision to deploy');
|
|
|
|
option('branch', null, InputOption::VALUE_OPTIONAL, 'Branch to deploy');
|
2015-01-03 00:04:00 +03:00
|
|
|
|
2016-11-19 15:13:32 +07:00
|
|
|
/**
|
|
|
|
* Tasks
|
|
|
|
*/
|
2016-11-11 14:22:55 +07:00
|
|
|
desc('Show current release');
|
2015-01-03 00:04:00 +03:00
|
|
|
task('current', function () {
|
2016-11-09 22:03:04 +07:00
|
|
|
writeln('Current release: ' . basename(get('current_path')));
|
2016-11-11 14:17:43 +07:00
|
|
|
});
|
2015-01-03 00:04:00 +03:00
|
|
|
|
|
|
|
|
2015-02-25 12:55:56 +03:00
|
|
|
/**
|
|
|
|
* Success message
|
|
|
|
*/
|
|
|
|
task('success', function () {
|
2016-11-12 17:41:29 +07:00
|
|
|
Deployer::setDefault('terminate_message', '<info>Successfully deployed!</info>');
|
|
|
|
})->once()->setPrivate();
|
2016-11-13 18:21:18 +07:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deploy failure
|
|
|
|
*/
|
|
|
|
task('deploy:failed', function () {
|
|
|
|
})->setPrivate();
|
2017-01-17 09:48:02 +07:00
|
|
|
|
2016-11-13 18:21:18 +07:00
|
|
|
onFailure('deploy', 'deploy:failed');
|