getTargetWorkspace() public static method

获取目标机要发布的目录 {webroot}
public static getTargetWorkspace ( ) : string
return string
Example #1
0
 /**
  * 获取远程服务器要操作的任务命令
  *
  * @param $task    string
  * @param $version string
  * @return string string
  */
 public static function getRemoteTaskCommand($task, $version)
 {
     $tasks = GlobalHelper::str2arr($task);
     if (empty($tasks)) {
         return '';
     }
     $cmd = [];
     $workspace = Project::getTargetWorkspace();
     $version = Project::getReleaseVersionDir($version);
     $pattern = ['#{WORKSPACE}#', '#{VERSION}#'];
     $replace = [$workspace, $version];
     foreach ($tasks as $task) {
         $cmd[] = preg_replace($pattern, $replace, $task);
     }
     return join(' && ', $cmd);
 }
Example #2
0
 /**
  * @param Project $project
  * @param TaskModel $task
  * @return bool
  * @throws \Exception
  */
 protected function _unpackageFilesByAnsible(Project $project, TaskModel $task)
 {
     $version = $task->link_id;
     $releasePackage = Project::getReleaseVersionPackage($version);
     $webrootPath = Project::getTargetWorkspace();
     $releasePath = Project::getReleaseVersionDir($version);
     $cmd = [];
     if ($task->file_transmission_mode == TaskModel::FILE_TRANSMISSION_MODE_PART) {
         // 增量传输时, 在解压数据包之前, 需要把目标机当前版本复制一份到release目录
         $cmd[] = sprintf('cp -arf %s/. %s', $webrootPath, $releasePath);
     }
     $cmd[] = sprintf('cd %1$s && tar --no-same-owner -pm -C %1$s -xz -f %2$s', $releasePath, $releasePackage);
     $command = join(' && ', $cmd);
     $ret = $this->runRemoteCommandByAnsibleShell($command);
     if (!$ret) {
         throw new \Exception(yii::t('walle', 'unpackage error'));
     }
     return true;
 }
Example #3
0
 /**
  * 获取远程服务器要操作的任务命令
  *
  * @param $task    string
  * @param $version string
  * @return string string
  */
 public static function getRemoteTaskCommand($task, $version)
 {
     $tasks = GlobalHelper::str2arr($task);
     if (empty($tasks)) {
         return '';
     }
     // 可能要做一些依赖环境变量的命令操作
     $cmd = ['source /etc/profile'];
     $workspace = Project::getTargetWorkspace();
     $version = Project::getReleaseVersionDir($version);
     $pattern = ['#{WORKSPACE}#', '#{VERSION}#'];
     $replace = [$workspace, $version];
     // 简化用户切换目录,直接切换到当前的版本目录:{release_library}/{project}/{version}
     $cmd[] = "cd {$version}";
     foreach ($tasks as $task) {
         $cmd[] = preg_replace($pattern, $replace, $task);
     }
     return join(' && ', $cmd);
 }