2014-07-12 14:23:22 +04:00
|
|
|
<?php
|
2016-01-11 14:00:45 +07:00
|
|
|
namespace Deployer;
|
2016-11-13 21:56:50 +07:00
|
|
|
|
2020-04-25 23:00:08 +03:00
|
|
|
require __DIR__ . '/deploy/check_remote.php';
|
|
|
|
require __DIR__ . '/deploy/cleanup.php';
|
|
|
|
require __DIR__ . '/deploy/clear_paths.php';
|
|
|
|
require __DIR__ . '/deploy/copy_dirs.php';
|
2017-08-12 11:56:35 +03:00
|
|
|
require __DIR__ . '/deploy/info.php';
|
2016-11-19 15:16:25 +07:00
|
|
|
require __DIR__ . '/deploy/lock.php';
|
2020-10-11 00:08:50 +02:00
|
|
|
require __DIR__ . '/deploy/push.php';
|
2016-11-19 15:16:25 +07:00
|
|
|
require __DIR__ . '/deploy/release.php';
|
2020-04-25 23:00:08 +03:00
|
|
|
require __DIR__ . '/deploy/rollback.php';
|
|
|
|
require __DIR__ . '/deploy/setup.php';
|
2016-11-19 15:16:25 +07:00
|
|
|
require __DIR__ . '/deploy/shared.php';
|
2020-10-09 02:24:09 +02:00
|
|
|
require __DIR__ . '/deploy/status.php';
|
2016-11-19 15:16:25 +07:00
|
|
|
require __DIR__ . '/deploy/symlink.php';
|
2020-04-25 23:00:08 +03:00
|
|
|
require __DIR__ . '/deploy/update_code.php';
|
|
|
|
require __DIR__ . '/deploy/vendors.php';
|
|
|
|
require __DIR__ . '/deploy/writable.php';
|
2016-01-11 14:00:45 +07:00
|
|
|
|
2020-07-07 22:16:18 +03:00
|
|
|
require __DIR__ . '/provision/provision.php';
|
|
|
|
|
2020-04-25 23:00:08 +03:00
|
|
|
use Deployer\Exception\RunException;
|
2016-11-05 12:22:56 +07:00
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
2020-04-25 23:00:08 +03:00
|
|
|
use Symfony\Component\Console\Output\Output;
|
2016-11-05 12:22:56 +07:00
|
|
|
|
2017-03-14 20:16:54 +07:00
|
|
|
/**
|
|
|
|
* Facts
|
|
|
|
*/
|
|
|
|
|
2017-08-16 11:46:05 +03:00
|
|
|
set('user', function () {
|
2020-04-25 23:00:08 +03:00
|
|
|
if (getenv('CI') !== false) {
|
|
|
|
return 'ci';
|
|
|
|
}
|
|
|
|
|
2017-08-16 11:46:05 +03:00
|
|
|
try {
|
|
|
|
return runLocally('git config --get user.name');
|
2020-04-25 23:00:08 +03:00
|
|
|
} catch (RunException $exception) {
|
|
|
|
try {
|
|
|
|
return runLocally('whoami');
|
|
|
|
} catch (RunException $exception) {
|
|
|
|
return 'no_user';
|
2018-07-24 15:16:39 +02:00
|
|
|
}
|
2017-08-16 11:46:05 +03:00
|
|
|
}
|
|
|
|
});
|
2017-03-14 20:16:54 +07:00
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2020-04-20 22:53:24 +02:00
|
|
|
set('clear_paths', []); // Relative path from release_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
|
|
|
|
2017-03-26 13:16:12 +07:00
|
|
|
set('cleanup_use_sudo', false); // Using sudo in cleanup commands?
|
|
|
|
|
2017-03-13 15:13:34 +07:00
|
|
|
set('use_relative_symlink', function () {
|
2017-04-02 12:58:53 +07:00
|
|
|
return commandSupportsOption('ln', '--relative');
|
2017-03-13 15:13:34 +07:00
|
|
|
});
|
|
|
|
set('use_atomic_symlink', function () {
|
2017-04-02 12:58:53 +07:00
|
|
|
return commandSupportsOption('mv', '--no-target-directory');
|
2017-03-13 15:13:34 +07:00
|
|
|
});
|
2016-06-05 12:58:34 -04:00
|
|
|
|
2017-08-12 20:31:19 +03:00
|
|
|
set('env', []); // Run command environment (for example, SYMFONY_ENV=prod)
|
2016-06-05 12:58:34 -04:00
|
|
|
|
2016-11-10 12:25:06 +07:00
|
|
|
/**
|
|
|
|
* Return current release path.
|
|
|
|
*/
|
2020-10-09 01:35:42 +02:00
|
|
|
set('current_path', '{{deploy_path}}/current');
|
2016-11-10 12:25:06 +07:00
|
|
|
|
2016-04-04 16:22:00 +07:00
|
|
|
/**
|
2017-08-22 22:27:20 +07:00
|
|
|
* Custom bins
|
2016-04-04 16:22:00 +07:00
|
|
|
*/
|
2016-11-05 17:50:18 +07:00
|
|
|
set('bin/php', function () {
|
2017-06-12 13:01:25 +02:00
|
|
|
return locateBinaryPath('php');
|
2016-04-04 16:22:00 +07:00
|
|
|
});
|
2016-11-19 15:13:32 +07:00
|
|
|
|
2016-11-05 17:50:18 +07:00
|
|
|
set('bin/git', function () {
|
2017-06-12 13:01:25 +02:00
|
|
|
return locateBinaryPath('git');
|
2016-04-04 16:22:00 +07:00
|
|
|
});
|
2016-11-19 15:13:32 +07:00
|
|
|
|
2016-11-05 17:50:18 +07:00
|
|
|
set('bin/symlink', function () {
|
2017-03-13 15:13:34 +07:00
|
|
|
return get('use_relative_symlink') ? 'ln -nfs --relative' : 'ln -nfs';
|
2016-11-05 13:40:12 +07:00
|
|
|
});
|
2015-02-24 17:13:10 +03:00
|
|
|
|
2020-10-02 00:11:13 +02:00
|
|
|
// Path to a file which will store temp script with sudo password.
|
|
|
|
// Defaults to `.dep/sudo_pass`. This script is only temporary and will be deleted after
|
|
|
|
// sudo command executed.
|
2020-04-25 23:00:08 +03:00
|
|
|
set('sudo_askpass', function () {
|
|
|
|
if (test('[ -d {{deploy_path}}/.dep ]')) {
|
|
|
|
return '{{deploy_path}}/.dep/sudo_pass';
|
|
|
|
} else {
|
|
|
|
return '/tmp/dep_sudo_pass';
|
|
|
|
}
|
|
|
|
});
|
2017-03-14 20:16:54 +07:00
|
|
|
|
2015-02-24 17:13:10 +03:00
|
|
|
/**
|
2017-03-18 23:27:55 +07:00
|
|
|
* Default options
|
2015-02-24 17:13:10 +03:00
|
|
|
*/
|
2017-07-03 16:16:54 +09:00
|
|
|
option('tag', null, InputOption::VALUE_REQUIRED, 'Tag to deploy');
|
|
|
|
option('revision', null, InputOption::VALUE_REQUIRED, 'Revision to deploy');
|
|
|
|
option('branch', null, InputOption::VALUE_REQUIRED, 'Branch to deploy');
|
2015-01-03 00:04:00 +03:00
|
|
|
|
|
|
|
|
2020-04-25 23:00:08 +03:00
|
|
|
task('deploy:prepare', [
|
|
|
|
'deploy:info',
|
|
|
|
'deploy:setup',
|
|
|
|
'deploy:lock',
|
|
|
|
'deploy:release',
|
|
|
|
'deploy:update_code',
|
2020-10-07 23:55:41 +02:00
|
|
|
'deploy:shared',
|
2020-10-08 00:45:12 +02:00
|
|
|
'deploy:writable',
|
2020-04-25 23:00:08 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
task('deploy:publish', [
|
|
|
|
'deploy:symlink',
|
|
|
|
'deploy:unlock',
|
|
|
|
'deploy:cleanup',
|
|
|
|
'deploy:success',
|
|
|
|
]);
|
|
|
|
|
2015-02-25 12:55:56 +03:00
|
|
|
/**
|
|
|
|
* Success message
|
|
|
|
*/
|
2020-04-25 23:00:08 +03:00
|
|
|
task('deploy:success', function () {
|
2020-07-26 22:35:08 +03:00
|
|
|
info('successfully deployed!');
|
2017-08-11 17:39:36 +03:00
|
|
|
})
|
|
|
|
->shallow()
|
2020-04-25 23:00:08 +03:00
|
|
|
->hidden();
|
2016-11-13 18:21:18 +07:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deploy failure
|
|
|
|
*/
|
|
|
|
task('deploy:failed', function () {
|
2020-04-25 23:00:08 +03:00
|
|
|
})->hidden();
|
2017-01-17 09:48:02 +07:00
|
|
|
|
2017-03-21 16:18:50 +07:00
|
|
|
fail('deploy', 'deploy:failed');
|
2020-04-25 23:00:08 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Follow latest application logs.
|
|
|
|
*/
|
|
|
|
desc('Follow latest application logs.');
|
|
|
|
task('logs', function () {
|
|
|
|
if (!has('log_files')) {
|
|
|
|
warning("Please, specify \"log_files\" option.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (output()->getVerbosity() === Output::VERBOSITY_NORMAL) {
|
|
|
|
output()->setVerbosity(Output::VERBOSITY_VERBOSE);
|
|
|
|
}
|
2020-10-09 01:35:42 +02:00
|
|
|
cd('{{current_path}}');
|
2020-04-25 23:00:08 +03:00
|
|
|
run('tail -f {{log_files}}');
|
|
|
|
});
|