38 lines
1.2 KiB
PHP
38 lines
1.2 KiB
PHP
<?php
|
|
|
|
use Workerman\Worker;
|
|
use Workerman\Connection\TcpConnection;
|
|
use Workerman\Protocols\Http\Request;
|
|
use Dotenv\Dotenv;
|
|
|
|
require_once __DIR__ . '/vendor/autoload.php';
|
|
// 加载.env文件
|
|
$dotenv = Dotenv::createImmutable(__DIR__);
|
|
$dotenv->load();
|
|
|
|
$worker = new Worker('http://0.0.0.0:8787');
|
|
|
|
$worker->onConnect = function ($connection) {
|
|
echo "New connection\n";
|
|
};
|
|
|
|
$worker->onMessage = function (TcpConnection $connection, Request $request) {
|
|
$work_dir = '/www/wwwroot/fs.book.wandoubaba.com';
|
|
$branch = 'master';
|
|
$git_url = 'git@git.wandoubaba.com:wandoubaba/knowledge.git';
|
|
$repository = $request->post('repository');
|
|
if (is_array($repository)) {
|
|
$ssh_url = isset($repository['ssh_url']) ? $repository['ssh_url'] : null;
|
|
$clone_url = isset($repository['clone_url']) ? $repository['clone_url'] : null;
|
|
if ($git_url === $ssh_url || $git_url === $clone_url) {
|
|
chdir($work_dir);
|
|
shell_exec("sh auto_build.sh > /dev/null &");
|
|
$connection->send("Deployment finished\n");
|
|
$connection->close();
|
|
}
|
|
}
|
|
};
|
|
|
|
// 运行worker
|
|
Worker::runAll();
|