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'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-25 16:08:21 +07:00
|
|
|
$method = new ReflectionMethod('Deployer\Deployer', 'run');
|
|
|
|
if (!$method->isStatic()) {
|
|
|
|
die(
|
2017-03-25 16:09:18 +07:00
|
|
|
'You need to update Deployer to the latest version:' . PHP_EOL .
|
2017-03-25 16:08:21 +07:00
|
|
|
PHP_EOL .
|
2017-03-25 16:10:31 +07:00
|
|
|
' dep self-update' . PHP_EOL .
|
2017-03-25 16:08:21 +07:00
|
|
|
PHP_EOL .
|
|
|
|
'Or use composer installed version:' . PHP_EOL .
|
|
|
|
PHP_EOL .
|
|
|
|
' php vendor/bin/dep' . PHP_EOL .
|
|
|
|
PHP_EOL
|
|
|
|
|
|
|
|
);
|
2014-07-07 17:44:06 +04:00
|
|
|
}
|
|
|
|
|
2017-03-25 16:08:21 +07:00
|
|
|
\Deployer\Deployer::run($version, $deployFile);
|