120 lines
3.3 KiB
Plaintext
Raw Normal View History

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.
*/
// Deployer constants
2016-03-11 14:59:34 +01:00
define('DEPLOYER', true);
define('DEPLOYER_BIN', __FILE__);
2016-11-12 17:02:13 +07:00
// Detect deploy.php script
$options = getopt('f::', ['file::']);
$userSpecifiedFile = null;
if (isset($options['f'])) {
$userSpecifiedFile = $options['f'];
2015-06-18 12:41:40 +02:00
} elseif (isset($options['file'])) {
$userSpecifiedFile = $options['file'];
}
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);
}
} else {
$deployFile = ($userSpecifiedFile[0] === '/' ? '' : getcwd() . '/') . $userSpecifiedFile;
}
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++) {
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
// 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());
});
2016-11-12 17:02:13 +07:00
// Require deploy.php file
2016-11-07 20:43:31 +07:00
if (is_readable($deployFile)) {
// Prevent variable leak into deploy.php file
2017-01-27 20:06:31 +07:00
call_user_func(function () use ($deployFile) {
require $deployFile;
});
}
// Run Deployer
2017-03-19 18:15:02 +07:00
$deployer->init();
$console->run($input, $output);