getReleaseVersionPackage() public static method

拼接目标机要发布的打包文件路径 {release_library}/{project}/{version}.tar.gz
public static getReleaseVersionPackage ( string $version = '' ) : string
$version string
return string
Example #1
0
 /**
  * 将多个文件/目录通过ansible传输到指定的多个目标机
  *
  * ansible 不支持 rsync模块, 改用宿主机 tar 打包, ansible 并发传输到目标机临时目录, 目标机解压
  *
  * @param $version
  * @param string $files 相对仓库文件/目录路径, 空格分割
  * @param array $remoteHosts
  */
 public function copyFiles($version, $files = '*', $remoteHosts = [])
 {
     // 1. 打包
     $excludes = GlobalHelper::str2arr($this->getConfig()->excludes);
     $packagePath = Project::getDeployPackagePath($version);
     $packageCommand = sprintf('cd %s && tar -p %s -cz -f %s %s', escapeshellarg(rtrim(Project::getDeployWorkspace($version), '/') . '/'), $this->excludes($excludes), escapeshellarg($packagePath), $files);
     $ret = $this->runLocalCommand($packageCommand);
     if (!$ret) {
         return false;
     }
     // 2. 传输文件
     $releasePackage = Project::getReleaseVersionPackage($version);
     $ret = $this->copyFilesByAnsibleCopy($packagePath, $releasePackage);
     if (!$ret) {
         return false;
     }
     // 3. 解压
     $releasePath = Project::getReleaseVersionDir($version);
     $unpackageCommand = sprintf('cd %1$s && tar --no-same-owner -pm -C %1$s -xz -f %2$s', $releasePath, $releasePackage);
     $ret = $this->runRemoteCommandByAnsibleShell($unpackageCommand);
     return $ret;
 }
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;
 }