本文整理匯總了PHP中app\models\Project::getReleaseVersionDir方法的典型用法代碼示例。如果您正苦於以下問題:PHP Project::getReleaseVersionDir方法的具體用法?PHP Project::getReleaseVersionDir怎麽用?PHP Project::getReleaseVersionDir使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\models\Project
的用法示例。
在下文中一共展示了Project::getReleaseVersionDir方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getLinkCommand
/**
* 打軟鏈
*
* @param null $version
* @return bool
*/
public function getLinkCommand($version)
{
$user = $this->config->release_user;
$project = Project::getGitProjectName($this->getConfig()->repo_url);
$currentTmp = sprintf('%s/%s/current-%s.tmp', rtrim($this->getConfig()->release_library, '/'), $project, $project);
// 遇到回滾,則使用回滾的版本version
$linkFrom = Project::getReleaseVersionDir($version);
$cmd[] = sprintf('ln -sfn %s %s', $linkFrom, $currentTmp);
$cmd[] = sprintf('chown -h %s %s', $user, $currentTmp);
$cmd[] = sprintf('mv -fT %s %s', $currentTmp, $this->getConfig()->release_to);
return join(' && ', $cmd);
}
示例2: getRemoteTaskCommand
/**
* 獲取遠程服務器要操作的任務命令
*
* @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 = rtrim(Project::getDeployWorkspace($version), '/');
$version = Project::getReleaseVersionDir($version);
$pattern = ['#{WORKSPACE}#', '#{VERSION}#'];
$replace = [$workspace, $version];
foreach ($tasks as $task) {
$cmd[] = preg_replace($pattern, $replace, $task);
}
return join(' && ', $cmd);
}
示例3: postRelease
/**
* 同步代碼之後觸發任務
* 所有目標機器都部署完畢之後,做一些清理工作,如刪除緩存、重啟服務(nginx、php、task)
*
* @return bool
*/
public function postRelease($version)
{
$tasks = GlobalHelper::str2arr($this->getConfig()->post_release);
if (empty($tasks)) {
return true;
}
$cmd = [];
$workspace = rtrim(Project::getDeployWorkspace($version), '/');
$version = Project::getReleaseVersionDir($version);
$pattern = ['#{WORKSPACE}#', '#{VERSION}#'];
$replace = [$workspace, $version];
foreach ($tasks as $task) {
$cmd[] = preg_replace($pattern, $replace, $task);
}
$command = join(' && ', $cmd);
return $this->runRemoteCommand($command);
}
示例4: actionDetection
/**
* 項目配置檢測,提前發現配置不當之處。
*
* @return string
*/
public function actionDetection($projectId)
{
$project = Project::getConf($projectId);
$log = [];
$code = 0;
// 本地git ssh-key是否加入deploy-keys列表
$revision = Repo::getRevision($project);
try {
$ret = $revision->updateRepo();
if (!$ret) {
$code = -1;
$error = $project->repo_type == Project::REPO_GIT ? '把ssh-key加入git的deploy-keys列表' : '用戶名密碼無誤';
$log[] = sprintf('宿主機代碼檢出檢測出錯,請確認php進程用戶%s有代碼存儲倉庫%s讀寫權限,
並且%s。詳細錯誤:%s<br>', getenv("USER"), $project->deploy_from, $error, $revision->getExeLog());
}
} catch (\Exception $e) {
$code = -1;
$log[] = sprintf('宿主機檢測時發生係統錯誤:%s<br>', $e->getMessage());
}
// 權限與免密碼登錄檢測
$this->walleTask = new WalleTask($project);
try {
$command = sprintf('mkdir -p %s', Project::getReleaseVersionDir('detection'));
$ret = $this->walleTask->runRemoteTaskCommandPackage([$command]);
if (!$ret) {
$code = -1;
$log[] = sprintf('目標機器部署出錯,請確認php進程用戶%s用戶ssh-key加入目標機器的%s用戶ssh-key信任列表,
且%s有目標機器發布版本庫%s寫入權限。詳細錯誤:%s<br>', getenv("USER"), $project->release_user, $project->release_user, $project->release_to, $this->walleTask->getExeLog());
}
// 清除
$command = sprintf('rm -rf %s', Project::getReleaseVersionDir('detection'));
$this->walleTask->runRemoteTaskCommandPackage([$command]);
} catch (\Exception $e) {
$code = -1;
$log[] = sprintf('目標機檢測時發生係統錯誤:%s<br>', $e->getMessage());
}
// task 檢測todo...
if ($code === 0) {
$log[] = '配置檢測通過,恭喜:)';
}
$this->renderJson(join("<br>", $log), $code);
}
示例5: actionDetection
/**
* 項目配置檢測,提前發現配置不當之處。
*
* @return string
*/
public function actionDetection($projectId)
{
$project = Project::getConf($projectId);
$log = [];
$code = 0;
// 本地git ssh-key是否加入deploy-keys列表
$revision = Repo::getRevision($project);
try {
// 1.檢測宿主機檢出目錄是否可讀寫
$codeBaseDir = Project::getDeployFromDir();
$isWritable = is_dir($codeBaseDir) ? is_writable($codeBaseDir) : @mkdir($codeBaseDir, 0755, true);
if (!$isWritable) {
$code = -1;
$log[] = yii::t('walle', 'hosted server is not writable error', ['user' => getenv("USER"), 'path' => $project->deploy_from]);
}
// 2.檢測宿主機ssh是否加入git信任
$ret = $revision->updateRepo();
if (!$ret) {
$code = -1;
$error = $project->repo_type == Project::REPO_GIT ? yii::t('walle', 'ssh-key to git', ['user' => getenv("USER")]) : yii::t('walle', 'correct username passwd');
$log[] = yii::t('walle', 'hosted server ssh error', ['error' => $error]);
}
if ($project->ansible) {
$this->ansible = new Ansible($project);
// 3.檢測 ansible 是否安裝
$ret = $this->ansible->test();
if (!$ret) {
$code = -1;
$log[] = yii::t('walle', 'hosted server ansible error');
}
}
} catch (\Exception $e) {
$code = -1;
$log[] = yii::t('walle', 'hosted server sys error', ['error' => $e->getMessage()]);
}
// 權限與免密碼登錄檢測
$this->walleTask = new WalleTask($project);
try {
// 4.檢測php用戶是否加入目標機ssh信任
$command = 'id';
$ret = $this->walleTask->runRemoteTaskCommandPackage([$command]);
if (!$ret) {
$code = -1;
$log[] = yii::t('walle', 'target server ssh error', ['local_user' => getenv("USER"), 'remote_user' => $project->release_user, 'path' => $project->release_to]);
}
if ($project->ansible) {
// 5.檢測 ansible 連接目標機是否正常
$ret = $this->ansible->ping();
if (!$ret) {
$code = -1;
$log[] = yii::t('walle', 'target server ansible ping error');
}
}
// 6.檢測php用戶是否具有目標機release目錄讀寫權限
$tmpDir = 'detection' . time();
$command = sprintf('mkdir -p %s', Project::getReleaseVersionDir($tmpDir));
$ret = $this->walleTask->runRemoteTaskCommandPackage([$command]);
if (!$ret) {
$code = -1;
$log[] = yii::t('walle', 'target server is not writable error', ['remote_user' => $project->release_user, 'path' => $project->release_to]);
}
// 清除
$command = sprintf('rm -rf %s', Project::getReleaseVersionDir($tmpDir));
$this->walleTask->runRemoteTaskCommandPackage([$command]);
} catch (\Exception $e) {
$code = -1;
$log[] = yii::t('walle', 'target server sys error', ['error' => $e->getMessage()]);
}
// 7.路徑必須為絕對路徑
$needAbsoluteDir = [Yii::t('conf', 'deploy from') => Project::getConf()->deploy_from, Yii::t('conf', 'webroot') => Project::getConf()->release_to, Yii::t('conf', 'releases') => Project::getConf()->release_library];
foreach ($needAbsoluteDir as $tips => $dir) {
if (0 !== strpos($dir, '/')) {
$code = -1;
$log[] = yii::t('walle', 'config dir must absolute', ['path' => sprintf('%s:%s', $tips, $dir)]);
}
}
// task 檢測todo...
if ($code === 0) {
$log[] = yii::t('walle', 'project configuration works');
}
$this->renderJson(join("<br>", $log), $code);
}
示例6: actionDetection
/**
* 項目配置檢測,提前發現配置不當之處。
*
* @return string
*/
public function actionDetection($projectId)
{
$project = Project::getConf($projectId);
$log = [];
$code = 0;
// 本地git ssh-key是否加入deploy-keys列表
$revision = Repo::getRevision($project);
try {
$ret = $revision->updateRepo();
if (!$ret) {
$code = -1;
$error = $project->repo_type == Project::REPO_GIT ? yii::t('walle', 'ssh-key to git') : yii::t('walle', 'correct username passwd');
$log[] = yii::t('walle', 'hosted server error', ['user' => getenv("USER"), 'path' => $project->deploy_from, 'ssh_passwd' => $error, 'error' => $revision->getExeLog()]);
}
} catch (\Exception $e) {
$code = -1;
$log[] = yii::t('walle', 'hosted server sys error', ['error' => $e->getMessage()]);
}
// 權限與免密碼登錄檢測
$this->walleTask = new WalleTask($project);
try {
$command = sprintf('mkdir -p %s', Project::getReleaseVersionDir('detection'));
$ret = $this->walleTask->runRemoteTaskCommandPackage([$command]);
if (!$ret) {
$code = -1;
$log[] = yii::t('walle', 'target server error', ['local_user' => getenv("USER"), 'remote_user' => $project->release_user, 'path' => $project->release_to, 'error' => $this->walleTask->getExeLog()]);
}
// 清除
$command = sprintf('rm -rf %s', Project::getReleaseVersionDir('detection'));
$this->walleTask->runRemoteTaskCommandPackage([$command]);
} catch (\Exception $e) {
$code = -1;
$log[] = yii::t('walle', 'target server sys error', ['error' => $e->getMessage()]);
}
// task 檢測todo...
if ($code === 0) {
$log[] = yii::t('walle', 'project configuration works');
}
$this->renderJson(join("<br>", $log), $code);
}
示例7: getRemoteTaskCommand
/**
* 獲取遠程服務器要操作的任務命令
*
* @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);
}
示例8: actionDetection
/**
* 項目配置檢測,提前發現配置不當之處。
*
* @return string
*/
public function actionDetection($projectId)
{
$project = Project::getConf($projectId);
$log = [];
$code = 0;
// 本地git ssh-key是否加入deploy-keys列表
$git = new Git();
try {
$ret = $git->setConfig($project)->updateRepo();
if (!$ret) {
$code = -1;
$log[] = sprintf('宿主機代碼檢出檢測出錯,請確認php進程用戶%s有代碼存儲倉庫權限,
並且把ssh-key加入git的deploy-keys列表。詳細錯誤:%s', Get_Current_User(), $git->getExeLog());
}
} catch (\Exception $e) {
$code = -1;
$log[] = sprintf('宿主機檢測時發生係統錯誤:%s', $e->getMessage());
}
// 權限與免密碼登錄檢測
$task = new WalleTask();
try {
$task->setConfig($project);
$command = sprintf('mkdir -p %s', Project::getReleaseVersionDir('detection'));
$ret = $task->runRemoteTaskCommandPackage([$command]);
if (!$ret) {
$code = -1;
$log[] = sprintf('目標機器代碼檢出檢測出錯,請確認php進程用戶%s用戶加入目標機器的%s用戶ssh-key信任列表,
且%s有目標機器發布版本庫寫入權限。詳細錯誤:%s', Get_Current_User(), $project->release_user, $project->release_user, $task->getExeLog());
}
// 清除
$command = sprintf('rm -rf %s', Project::getReleaseVersionDir('detection'));
$task->runRemoteTaskCommandPackage([$command]);
} catch (\Exception $e) {
$code = -1;
$log[] = sprintf('目標機檢測時發生係統錯誤:%s', $e->getMessage());
}
// task 檢測todo...
if ($code === 0) {
$log[] = '配置檢測通過,恭喜:)';
}
$this->renderJson(join("<br>", $log), $code);
}