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
|
|
|
|
2017-03-22 23:53:23 +07:00
|
|
|
require __DIR__ . '/config/current.php';
|
2017-03-14 20:16:54 +07:00
|
|
|
require __DIR__ . '/config/dump.php';
|
2017-06-22 14:18:34 +07:00
|
|
|
require __DIR__ . '/config/hosts.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/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
|
|
|
|
2017-03-14 20:16:54 +07:00
|
|
|
use Deployer\Task\Context;
|
2016-11-05 12:22:56 +07:00
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
|
2017-03-14 20:16:54 +07:00
|
|
|
/**
|
|
|
|
* Facts
|
|
|
|
*/
|
|
|
|
|
|
|
|
set('hostname', function () {
|
|
|
|
return Context::get()->getHost()->getHostname();
|
|
|
|
});
|
|
|
|
|
2017-08-16 11:46:05 +03:00
|
|
|
set('user', function () {
|
|
|
|
try {
|
|
|
|
return runLocally('git config --get user.name');
|
|
|
|
} catch (\Throwable $exception) {
|
2018-07-24 15:16:39 +02:00
|
|
|
if (false !== getenv('CI')) {
|
|
|
|
return 'Continuous Integration';
|
|
|
|
}
|
|
|
|
|
2017-08-16 11:46:05 +03:00
|
|
|
return 'no_user';
|
|
|
|
}
|
|
|
|
});
|
2017-03-14 20:16:54 +07:00
|
|
|
|
2017-08-17 08:54:43 +03:00
|
|
|
set('target', function () {
|
|
|
|
return input()->getArgument('stage') ?: get('hostname');
|
|
|
|
});
|
|
|
|
|
2016-11-05 17:50:18 +07:00
|
|
|
/**
|
|
|
|
* Configuration
|
|
|
|
*/
|
|
|
|
|
2016-11-05 15:44:09 +07:00
|
|
|
set('keep_releases', 5);
|
2019-08-06 20:52:41 +02:00
|
|
|
// By setting this to true, deployer will avoid unnecessary new release by checking the remote git HEAD without cloning the repo.
|
|
|
|
set('check_remote_head', false);
|
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
|
|
|
|
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?
|
2019-03-31 15:11:54 +02:00
|
|
|
set('writable_recursive', true); // Common for all modes
|
2016-11-17 23:18:16 +07:00
|
|
|
set('writable_chmod_mode', '0755'); // For chmod mode
|
2019-03-31 15:11:54 +02:00
|
|
|
set('writable_chmod_recursive', true); // For chmod mode only (if is boolean, it has priority over `writable_recursive`)
|
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
|
|
|
|
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
|
|
|
|
2016-11-05 17:50:18 +07:00
|
|
|
set('composer_action', 'install');
|
2019-02-19 16:50:11 +03:00
|
|
|
set('composer_options', '{{composer_action}} --verbose --prefer-dist --no-progress --no-interaction --no-dev --optimize-autoloader --no-suggest');
|
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.
|
|
|
|
*/
|
|
|
|
set('current_path', function () {
|
2017-08-12 18:06:21 +03:00
|
|
|
$link = run("readlink {{deploy_path}}/current");
|
2016-11-10 12:25:06 +07:00
|
|
|
return substr($link, 0, 1) === '/' ? $link : get('deploy_path') . '/' . $link;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
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/composer', function () {
|
2016-04-04 16:22:00 +07:00
|
|
|
if (commandExist('composer')) {
|
2017-06-12 13:01:25 +02:00
|
|
|
$composer = locateBinaryPath('composer');
|
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}}");
|
2017-02-18 15:45:26 +01:00
|
|
|
$composer = '{{release_path}}/composer.phar';
|
2016-04-04 16:22:00 +07:00
|
|
|
}
|
|
|
|
|
2017-02-18 15:45:26 +01:00
|
|
|
return '{{bin/php}} ' . $composer;
|
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
|
|
|
|
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
|
|
|
|
|
|
|
|
2015-02-25 12:55:56 +03:00
|
|
|
/**
|
|
|
|
* Success message
|
|
|
|
*/
|
|
|
|
task('success', function () {
|
2017-08-11 17:39:36 +03:00
|
|
|
writeln('<info>Successfully deployed!</info>');
|
|
|
|
})
|
|
|
|
->local()
|
|
|
|
->shallow()
|
|
|
|
->setPrivate();
|
2016-11-13 18:21:18 +07:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deploy failure
|
|
|
|
*/
|
|
|
|
task('deploy:failed', function () {
|
|
|
|
})->setPrivate();
|
2017-01-17 09:48:02 +07:00
|
|
|
|
2017-03-21 16:18:50 +07:00
|
|
|
fail('deploy', 'deploy:failed');
|