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.
|
|
|
|
*/
|
|
|
|
|
2021-10-13 20:06:24 +02:00
|
|
|
// Detect deploy.php location
|
2020-04-25 23:00:08 +03:00
|
|
|
$deployFile = null;
|
2020-10-15 22:12:17 +02:00
|
|
|
foreach ($argv as $i => $arg) {
|
|
|
|
if (preg_match('/^(-f|--file)$/', $arg, $match) && $i + 1 < count($argv)) {
|
|
|
|
$deployFile = $argv[$i + 1];
|
2022-01-10 18:09:42 +01:00
|
|
|
break;
|
2020-10-15 22:12:17 +02:00
|
|
|
}
|
2022-01-10 18:09:42 +01:00
|
|
|
if (preg_match('/^--file=(?<file>.+)$/', $arg, $match)) {
|
2020-10-15 22:12:17 +02:00
|
|
|
$deployFile = $match['file'];
|
2022-01-10 18:09:42 +01:00
|
|
|
break;
|
2020-10-15 22:12:17 +02:00
|
|
|
}
|
2022-01-10 18:09:42 +01:00
|
|
|
if (preg_match('/^-f=?(?<file>.+)$/', $arg, $match)) {
|
|
|
|
$deployFile = $match['file'];
|
|
|
|
break;
|
2020-10-15 22:12:17 +02:00
|
|
|
}
|
2019-08-13 18:00:03 +02:00
|
|
|
}
|
2022-01-10 18:09:42 +01:00
|
|
|
if (!empty($deployFile)) {
|
|
|
|
$deployFile = realpath($deployFile);
|
|
|
|
}
|
2021-10-13 20:06:24 +02:00
|
|
|
$lookUp = function (string $name): ?string {
|
2020-10-15 22:12:17 +02:00
|
|
|
$dir = getcwd();
|
|
|
|
for ($i = 0; $i < 10; $i++) {
|
|
|
|
$path = "$dir/$name";
|
|
|
|
if (is_readable($path)) {
|
|
|
|
return $path;
|
|
|
|
}
|
|
|
|
$dir = dirname($dir);
|
2016-11-07 20:43:31 +07:00
|
|
|
}
|
2022-01-30 13:34:02 +08:00
|
|
|
return '';
|
2020-10-15 22:12:17 +02:00
|
|
|
};
|
|
|
|
if (empty($deployFile)) {
|
|
|
|
$deployFile = $lookUp('deploy.php');
|
|
|
|
}
|
|
|
|
if (empty($deployFile)) {
|
|
|
|
$deployFile = $lookUp('deploy.yaml');
|
2014-11-29 22:11:11 +03:00
|
|
|
}
|
2021-10-21 21:14:30 +02:00
|
|
|
if (empty($deployFile)) {
|
|
|
|
$deployFile = $lookUp('deploy.yml');
|
|
|
|
}
|
2014-07-04 13:39:57 +04:00
|
|
|
|
2021-10-13 20:06:24 +02:00
|
|
|
// Detect autoload location
|
2016-11-12 17:02:13 +07:00
|
|
|
$autoload = [
|
2021-10-13 20:06:24 +02:00
|
|
|
__DIR__ . '/../vendor/autoload.php', // The dep located at "deployer.phar/bin" or in development.
|
|
|
|
__DIR__ . '/../../../autoload.php', // The dep located at "vendor/deployer/deployer/bin".
|
2021-10-18 18:10:01 +02:00
|
|
|
__DIR__ . '/../autoload.php', // The dep located at "vendor/bin".
|
2016-11-12 17:02:13 +07:00
|
|
|
];
|
|
|
|
$includes = [
|
2021-10-13 20:06:24 +02:00
|
|
|
__DIR__ . '/..',
|
2016-11-12 17:02:13 +07:00
|
|
|
__DIR__ . '/../../../deployer/deployer',
|
2021-10-18 18:10:01 +02:00
|
|
|
__DIR__ . '/../deployer/deployer',
|
2016-11-12 17:02:13 +07:00
|
|
|
];
|
|
|
|
$includePath = false;
|
|
|
|
for ($i = 0; $i < count($autoload); $i++) {
|
2021-10-13 20:06:24 +02:00
|
|
|
if (file_exists($autoload[$i]) && is_dir($includes[$i])) {
|
2016-11-12 17:02:13 +07:00
|
|
|
require $autoload[$i];
|
|
|
|
$includePath = $includes[$i];
|
2021-10-13 20:06:24 +02:00
|
|
|
break;
|
2016-11-12 17:02:13 +07:00
|
|
|
}
|
|
|
|
}
|
2021-10-13 20:06:24 +02:00
|
|
|
if (empty($includePath)) {
|
|
|
|
fwrite(STDERR, "Error: The `autoload.php` file not found in:\n");
|
|
|
|
for ($i = 0; $i < count($autoload); $i++) {
|
|
|
|
$a = file_exists($autoload[$i]) ? 'true' : 'false';
|
|
|
|
$b = is_dir($includes[$i]) ? 'true' : 'false';
|
|
|
|
fwrite(STDERR, " - file_exists($autoload[$i]) = $a\n");
|
|
|
|
fwrite(STDERR, " is_dir($includes[$i]) = $b\n");
|
|
|
|
}
|
|
|
|
exit(1);
|
|
|
|
}
|
2016-11-12 17:02:13 +07:00
|
|
|
|
2021-10-13 20:06:24 +02:00
|
|
|
// Errors to exception
|
|
|
|
set_error_handler(function ($severity, $message, $filename, $lineno) {
|
|
|
|
if (error_reporting() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (error_reporting() & $severity) {
|
|
|
|
throw new ErrorException($message, 0, $severity, $filename, $lineno);
|
|
|
|
}
|
|
|
|
});
|
2016-11-12 17:02:13 +07:00
|
|
|
|
2021-10-13 20:06:24 +02:00
|
|
|
// Enable recipe loading
|
2016-11-12 17:02:13 +07:00
|
|
|
set_include_path($includePath . PATH_SEPARATOR . get_include_path());
|
2021-10-13 20:06:24 +02:00
|
|
|
|
|
|
|
// Deployer constants
|
|
|
|
define('DEPLOYER', true);
|
|
|
|
define('DEPLOYER_BIN', __FILE__);
|
2020-11-04 19:20:23 +01:00
|
|
|
define('DEPLOYER_DEPLOY_FILE', $deployFile);
|
2021-10-13 20:06:24 +02:00
|
|
|
|
2022-03-17 20:32:27 +01:00
|
|
|
Deployer\Deployer::run('master', $deployFile);
|