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
|
|
|
|
2021-10-09 17:54:16 +02:00
|
|
|
require __DIR__ . '/provision.php';
|
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';
|
|
|
|
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-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
|
|
|
|
2020-10-25 16:00:05 +01:00
|
|
|
add('recipes', ['common']);
|
|
|
|
|
2020-10-11 16:35:59 +02:00
|
|
|
// Name of current user who is running deploy.
|
|
|
|
// If not set will try automatically get git user name,
|
|
|
|
// otherwise output of `whoami` command.
|
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
|
|
|
|
2020-10-11 16:35:59 +02:00
|
|
|
// Number of releases to preserve in releases folder.
|
2021-09-23 02:09:55 +02:00
|
|
|
set('keep_releases', 10);
|
2016-11-05 17:50:18 +07:00
|
|
|
|
2020-10-11 16:35:59 +02:00
|
|
|
// Repository to deploy.
|
|
|
|
set('repository', '');
|
2016-11-05 17:50:18 +07:00
|
|
|
|
2020-10-11 16:35:59 +02:00
|
|
|
// List of dirs what will be shared between releases.
|
|
|
|
// Each release will have symlink to those dirs stored in {{deploy_path}}/shared dir.
|
|
|
|
// ```php
|
|
|
|
// set('shared_dirs', ['storage']);
|
|
|
|
// ```
|
2015-02-15 15:28:44 +03:00
|
|
|
set('shared_dirs', []);
|
2020-10-11 16:35:59 +02:00
|
|
|
|
|
|
|
// List of files what will be shared between releases.
|
|
|
|
// Each release will have symlink to those files stored in {{deploy_path}}/shared dir.
|
|
|
|
// ```php
|
|
|
|
// set('shared_files', ['.env']);
|
|
|
|
// ```
|
2015-02-15 15:28:44 +03:00
|
|
|
set('shared_files', []);
|
2016-11-05 17:50:18 +07:00
|
|
|
|
2020-10-11 16:35:59 +02:00
|
|
|
// List of dirs to copy between releases.
|
|
|
|
// For example you can copy `node_modules` to speedup npm install.
|
2015-07-05 14:53:49 +02:00
|
|
|
set('copy_dirs', []);
|
2016-11-05 17:50:18 +07:00
|
|
|
|
2020-10-11 16:35:59 +02:00
|
|
|
// List of paths to remove from {{release_path}}.
|
|
|
|
set('clear_paths', []);
|
2016-06-05 12:58:34 -04:00
|
|
|
|
2020-10-11 16:35:59 +02:00
|
|
|
// Use sudo for deploy:clear_path task?
|
|
|
|
set('clear_use_sudo', false);
|
2017-03-26 13:16:12 +07:00
|
|
|
|
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
|
|
|
|
2021-08-31 20:15:06 +02:00
|
|
|
// Default timeout for `run()` and `runLocally()` functions.
|
|
|
|
//
|
2020-11-05 19:43:04 +01:00
|
|
|
// Set to `null` to disable timeout.
|
|
|
|
set('default_timeout', 300);
|
|
|
|
|
2020-10-11 16:04:44 +02:00
|
|
|
/**
|
|
|
|
* Remote environment variables.
|
|
|
|
* ```php
|
|
|
|
* set('env', [
|
|
|
|
* 'KEY' => 'something',
|
|
|
|
* ]);
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* It is possible to override it per `run()` call.
|
|
|
|
*
|
|
|
|
* ```php
|
|
|
|
* run('echo $KEY', ['env' => ['KEY' => 'over']]
|
|
|
|
* ```
|
|
|
|
*/
|
|
|
|
set('env', []);
|
2016-06-05 12:58:34 -04:00
|
|
|
|
2020-10-11 16:23:40 +02:00
|
|
|
/**
|
|
|
|
* Path to `.env` file which will be used as environment variables for each command per `run()`.
|
|
|
|
*
|
|
|
|
* ```php
|
|
|
|
* set('dotenv', '{{current_path}}/.env');
|
|
|
|
* ```
|
|
|
|
*/
|
|
|
|
set('dotenv', false);
|
|
|
|
|
2016-11-10 12:25:06 +07:00
|
|
|
/**
|
2020-10-11 16:35:59 +02:00
|
|
|
* Return current release path. Default to {{deploy_path}}/`current`.
|
|
|
|
* ```php
|
|
|
|
* set('current_path', '/var/public_html');
|
|
|
|
* ```
|
2016-11-10 12:25:06 +07:00
|
|
|
*/
|
2020-10-09 01:35:42 +02:00
|
|
|
set('current_path', '{{deploy_path}}/current');
|
2016-11-10 12:25:06 +07:00
|
|
|
|
2020-10-11 16:35:59 +02:00
|
|
|
// Custom php bin of remote host.
|
2016-11-05 17:50:18 +07:00
|
|
|
set('bin/php', function () {
|
2021-10-11 22:05:45 +02:00
|
|
|
if (has('php_version')) {
|
|
|
|
return '/usr/bin/php{{php_version}}';
|
|
|
|
}
|
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
|
|
|
|
2020-10-11 16:35:59 +02:00
|
|
|
// Custom git bin of remote host.
|
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
|
|
|
|
2020-10-11 16:35:59 +02:00
|
|
|
// Custom ln bin of remote host.
|
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
|
|
|
|
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
|
|
|
|
2021-09-24 00:11:45 +02:00
|
|
|
// The deploy target: a branch, a tag or a revision.
|
|
|
|
set('target', function () {
|
|
|
|
$target = '';
|
|
|
|
$branch = get('branch');
|
|
|
|
if (!empty($branch)) {
|
|
|
|
$target = $branch;
|
|
|
|
}
|
|
|
|
if (input()->hasOption('tag') && !empty(input()->getOption('tag'))) {
|
|
|
|
$target = input()->getOption('tag');
|
|
|
|
}
|
|
|
|
if (input()->hasOption('revision') && !empty(input()->getOption('revision'))) {
|
|
|
|
$target = input()->getOption('revision');
|
|
|
|
}
|
|
|
|
if (empty($target)) {
|
|
|
|
$target = "HEAD";
|
|
|
|
}
|
|
|
|
return $target;
|
|
|
|
});
|
|
|
|
|
2021-10-11 22:06:35 +02:00
|
|
|
desc('Prepare a new release');
|
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
|
|
|
]);
|
|
|
|
|
2021-10-11 22:06:35 +02:00
|
|
|
desc('Publish the release');
|
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
|
|
|
/**
|
2020-10-11 16:35:59 +02:00
|
|
|
* Prints success message
|
2015-02-25 12:55:56 +03:00
|
|
|
*/
|
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
|
|
|
|
|
|
|
|
|
|
|
/**
|
2020-10-11 16:35:59 +02:00
|
|
|
* Hook on deploy failure.
|
2016-11-13 18:21:18 +07:00
|
|
|
*/
|
|
|
|
task('deploy:failed', function () {
|
2020-04-25 23:00:08 +03:00
|
|
|
})->hidden();
|
2017-01-17 09:48:02 +07:00
|
|
|
|
2021-03-14 08:44:14 +01:00
|
|
|
fail('deploy', 'deploy:failed');
|
2020-04-25 23:00:08 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Follow latest application logs.
|
|
|
|
*/
|
2021-10-11 22:06:22 +02:00
|
|
|
desc('Show application logs');
|
|
|
|
task('logs:app', function () {
|
2020-04-25 23:00:08 +03:00
|
|
|
if (!has('log_files')) {
|
|
|
|
warning("Please, specify \"log_files\" option.");
|
|
|
|
return;
|
|
|
|
}
|
2020-10-09 01:35:42 +02:00
|
|
|
cd('{{current_path}}');
|
2020-04-25 23:00:08 +03:00
|
|
|
run('tail -f {{log_files}}');
|
2021-10-11 22:06:22 +02:00
|
|
|
})->verbose();
|