|
|
@@ -45,11 +45,64 @@ class Start
|
|
|
case 'remove':
|
|
|
$this->remove($name);
|
|
|
break;
|
|
|
+ case 'nginx':
|
|
|
+ $this->nginx($name, $proginnBranch, $rooterBranch, $proginnFrontendBranch);//同步nginx配置,不用每次都重新拉取
|
|
|
+ break;
|
|
|
default:
|
|
|
echo "Usage: php index.php --action=start|remove --name=mydev --proginn-branch=dev --rooter-branch=dev --proginn-frontend-branch dev\n";
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public function nginx($name, $proginnBranch, $rooterBranch, $proginnFrontendBranch)
|
|
|
+ {
|
|
|
+ if (preg_match('/[^a-zA-Z0-9_]+/', $name)) {
|
|
|
+ echo "创建失败,容器名:{$name}只能字母、数字及下划线组成。\n";
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (preg_match('/[^a-zA-Z0-9_]+/', $proginnBranch)) {
|
|
|
+ echo "创建失败,proginn分支名:{$name}只能字母、数字及下划线组成。\n";
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (preg_match('/[^a-zA-Z0-9_]+/', $rooterBranch)) {
|
|
|
+ echo "创建失败,rooter分支名:{$name}只能字母、数字及下划线组成。\n";
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (preg_match('/[^a-zA-Z0-9_]+/', $proginnFrontendBranch)) {
|
|
|
+ echo "创建失败,proginn-frontend分支名:{$name}只能字母、数字及下划线组成。\n";
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $db = $this->getConnection();
|
|
|
+ $row = $db->get('sites', '*', [
|
|
|
+ 'name' => $name,
|
|
|
+ ]);
|
|
|
+ if (empty($row)) {
|
|
|
+ echo "获取失败,容器:{$name}不存在,请确认。\n";
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $ip = $this->getIp();
|
|
|
+ $ipv4 = long2ip($ip);
|
|
|
+ $domain = $name;
|
|
|
+ $this->getConnection()->query('start transaction');
|
|
|
+ try {
|
|
|
+ // 容器存储目录
|
|
|
+ $directory = $this->containersBasePath . $name;
|
|
|
+
|
|
|
+ // nginx 配置
|
|
|
+ $proginn = file_get_contents(ROOT_DIR . '/config/nginx/template/proginn.nginx.conf');
|
|
|
+ $proginn = str_replace('{{domain}}', $domain, $proginn);
|
|
|
+ $proginn = str_replace('{{ip}}', $ipv4, $proginn);
|
|
|
+ file_put_contents("{$directory}/config/nginx.conf", $proginn);
|
|
|
+
|
|
|
+ // 重载Nginx
|
|
|
+ system("docker exec nginx nginx -s reload");
|
|
|
+ $this->getConnection()->query('commit');
|
|
|
+ } catch (\Throwable $e) {
|
|
|
+ echo "exception:" . $e->__toString() . "\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public function start($name, $proginnBranch, $rooterBranch, $proginnFrontendBranch)
|
|
|
{
|
|
|
if (preg_match('/[^a-zA-Z0-9_]+/', $name)) {
|