app\components\Folder::initRemoteVersion PHP Method

initRemoteVersion() public method

目标机器的版本库初始化 git 和 svn 没有任何区别, 只初始空目录
Author: wushuiyong
public initRemoteVersion ( $version ) : boolean
return boolean
    public function initRemoteVersion($version)
    {
        $command = sprintf('mkdir -p %s', Project::getReleaseVersionDir($version));
        if (Project::getAnsibleStatus()) {
            // ansible 并发执行远程命令
            return $this->runRemoteCommandByAnsibleShell($command);
        } else {
            // ssh 循环执行远程命令
            return $this->runRemoteCommand($command);
        }
    }

Usage Example

 /**
  * 检查目录和权限,工作空间的准备
  * 每一个版本都单独开辟一个工作空间,防止代码污染
  *
  * @return bool
  * @throws \Exception
  */
 private function _initWorkspace()
 {
     $folder = new Folder();
     $sTime = Command::getMs();
     $folder->setConfig($this->conf);
     // 本地宿主机工作区初始化
     $folder->initLocalWorkspace($this->task->link_id);
     // 本地宿主机代码仓库检查
     // 远程目标目录检查,并且生成版本目录
     $ret = $folder->initRemoteVersion($this->task->link_id);
     // 记录执行时间
     $duration = Command::getMs() - $sTime;
     Record::saveRecord($folder, $this->task->id, Record::ACTION_PERMSSION, $duration);
     if (!$ret) {
         throw new \Exception('初始化部署隔离空间出错');
     }
     return true;
 }