2014-07-04 12:15:38 +04:00
|
|
|
#!/usr/bin/env php
|
2013-07-11 15:47:09 +04:00
|
|
|
<?php
|
2016-01-11 12:51:59 +07:00
|
|
|
/* (c) Anton Medvedev <anton@medv.io>
|
2013-07-11 15:47:09 +04:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2016-04-04 16:22:00 +07:00
|
|
|
// Deployer constants
|
2016-03-11 14:59:34 +01:00
|
|
|
define('DEPLOYER', true);
|
2016-04-04 16:22:00 +07:00
|
|
|
define('DEPLOYER_BIN', __FILE__);
|
2016-03-11 12:01:59 +01:00
|
|
|
|
2016-11-12 17:02:13 +07:00
|
|
|
// Detect deploy.php script
|
2014-11-29 22:11:11 +03:00
|
|
|
$options = getopt('f::', ['file::']);
|
|
|
|
$userSpecifiedFile = null;
|
2014-07-07 17:44:06 +04:00
|
|
|
|
2014-11-29 22:11:11 +03:00
|
|
|
if (isset($options['f'])) {
|
2015-02-12 19:52:28 -05:00
|
|
|
$userSpecifiedFile = $options['f'];
|
2015-06-18 12:41:40 +02:00
|
|
|
} elseif (isset($options['file'])) {
|
2015-02-12 19:52:28 -05:00
|
|
|
$userSpecifiedFile = $options['file'];
|
2014-11-29 22:11:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($userSpecifiedFile)) {
|
|
|
|
$deployFile = getcwd() . '/deploy.php';
|
2016-11-07 20:43:31 +07:00
|
|
|
|
2017-01-27 20:06:31 +07:00
|
|
|
if (!is_readable($deployFile)) {
|
2016-11-07 20:43:31 +07:00
|
|
|
$currentDir = getcwd();
|
|
|
|
$count = 0;
|
|
|
|
do {
|
|
|
|
$currentDir = dirname($currentDir);
|
|
|
|
$deployFile = $currentDir . '/deploy.php';
|
|
|
|
$count++;
|
|
|
|
} while (!is_readable($deployFile) && $count < 100);
|
|
|
|
}
|
2014-11-29 22:11:11 +03:00
|
|
|
} else {
|
2015-02-12 19:52:28 -05:00
|
|
|
$deployFile = ($userSpecifiedFile[0] === '/' ? '' : getcwd() . '/') . $userSpecifiedFile;
|
2014-11-29 22:11:11 +03:00
|
|
|
}
|
2014-07-04 13:39:57 +04:00
|
|
|
|
2016-11-12 17:02:13 +07:00
|
|
|
$deployFilePath = dirname($deployFile);
|
|
|
|
|
|
|
|
// Detect source location
|
|
|
|
|
|
|
|
$autoload = [
|
|
|
|
$deployFilePath . '/vendor/autoload.php',
|
|
|
|
__DIR__ . '/../../../autoload.php',
|
|
|
|
__DIR__ . '/../vendor/autoload.php'
|
|
|
|
];
|
|
|
|
|
|
|
|
$includes = [
|
|
|
|
$deployFilePath . '/vendor/deployer/deployer',
|
|
|
|
__DIR__ . '/../../../deployer/deployer',
|
|
|
|
__DIR__ . '/../'
|
|
|
|
];
|
|
|
|
|
|
|
|
$loaded = false;
|
|
|
|
$includePath = false;
|
|
|
|
|
|
|
|
for ($i = 0; $i < count($autoload); $i++) {
|
2016-11-12 18:16:50 +07:00
|
|
|
if (file_exists($autoload[$i]) && file_exists($includes[$i])) {
|
2016-11-12 17:02:13 +07:00
|
|
|
require $autoload[$i];
|
|
|
|
$includePath = $includes[$i];
|
|
|
|
$loaded = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$loaded) {
|
|
|
|
die(
|
|
|
|
'You need to set up the project dependencies using the following commands:' . PHP_EOL .
|
|
|
|
'wget http://getcomposer.org/composer.phar' . PHP_EOL .
|
|
|
|
'php composer.phar install' . PHP_EOL
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup include path
|
|
|
|
set_include_path($includePath . PATH_SEPARATOR . get_include_path());
|
|
|
|
|
|
|
|
// Detect version
|
|
|
|
$version = 'master';
|
|
|
|
|
|
|
|
$composerLockFile = $deployFilePath . '/composer.lock';
|
|
|
|
if (is_readable($composerLockFile)) {
|
|
|
|
$lock = json_decode(file_get_contents($composerLockFile), true);
|
|
|
|
foreach ($lock['packages'] as $package) {
|
|
|
|
if ($package['name'] === 'deployer/deployer') {
|
|
|
|
$version = $package['version'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach ($lock['packages-dev'] as $package) {
|
|
|
|
if ($package['name'] === 'deployer/deployer') {
|
|
|
|
$version = $package['version'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init Deployer
|
|
|
|
$console = new \Deployer\Console\Application('Deployer', $version);
|
|
|
|
$input = new \Symfony\Component\Console\Input\ArgvInput();
|
|
|
|
$output = new \Symfony\Component\Console\Output\ConsoleOutput();
|
2017-03-19 18:15:02 +07:00
|
|
|
$deployer = new \Deployer\Deployer($console);
|
2016-11-12 17:02:13 +07:00
|
|
|
|
2017-03-10 11:55:26 +01:00
|
|
|
// Pretty-print uncaught exceptions in symfony-console
|
2017-03-22 23:25:35 +07:00
|
|
|
set_exception_handler(function ($e) use ($input, $output) {
|
|
|
|
$io = new \Symfony\Component\Console\Style\SymfonyStyle($input, $output);
|
|
|
|
$io->block($e->getMessage(), get_class($e), 'fg=white;bg=red', ' ', true);
|
|
|
|
$io->block($e->getTraceAsString());
|
|
|
|
});
|
2017-03-10 11:55:26 +01:00
|
|
|
|
2016-11-12 17:02:13 +07:00
|
|
|
// Require deploy.php file
|
2016-11-07 20:43:31 +07:00
|
|
|
if (is_readable($deployFile)) {
|
2017-01-11 19:27:59 +01:00
|
|
|
// Prevent variable leak into deploy.php file
|
2017-01-27 20:06:31 +07:00
|
|
|
call_user_func(function () use ($deployFile) {
|
2017-01-11 19:27:59 +01:00
|
|
|
require $deployFile;
|
|
|
|
});
|
2014-07-07 17:44:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run Deployer
|
2017-03-19 18:15:02 +07:00
|
|
|
$deployer->init();
|
|
|
|
$console->run($input, $output);
|