Last active
February 11, 2018 03:01
-
-
Save liujingyu/d35202524d0c01a6de5e0b0946e52118 to your computer and use it in GitHub Desktop.
walle-web v1.2.0 a patch support docker deploy,use dir map way.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/components/Folder.php b/components/Folder.php | |
index 2a84f32..1e757c4 100644 | |
--- a/components/Folder.php | |
+++ b/components/Folder.php | |
@@ -267,9 +267,13 @@ class Folder extends Ansible { | |
$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); | |
+ | |
+ $webroot = $this->getConfig()->release_to; | |
+ $webroots = explode(DIRECTORY_SEPARATOR, $webroot); | |
+ $alias = array_pop($webroots); | |
+ $htdocs = implode(DIRECTORY_SEPARATOR, $webroots); | |
+ $relative = self::find_relative_path($htdocs, $linkFrom); | |
+ $cmd[] = sprintf('cd %s && ln -sfn %s %s', $htdocs, $relative, $alias); | |
return join(' && ', $cmd); | |
} | |
@@ -339,5 +343,41 @@ class Folder extends Ansible { | |
return $this->runLocalCommand($command); | |
} | |
+ /** | |
+ * | |
+ * Find the relative file system path between two file system paths | |
+ * | |
+ * @param string $frompath Path to start from | |
+ * @param string $topath Path we want to end up in | |
+ * | |
+ * @return string Path leading from $frompath to $topath | |
+ */ | |
+ public static function find_relative_path($frompath, $topath) { | |
+ $from = explode(DIRECTORY_SEPARATOR, $frompath); // Folders/File | |
+ $to = explode(DIRECTORY_SEPARATOR, $topath); // Folders/File | |
+ $relpath = ''; | |
+ | |
+ $i = 0; | |
+ // Find how far the path is the same | |
+ while (isset($from[$i]) && isset($to[$i])) { | |
+ if ($from[$i] != $to[$i]) break; | |
+ $i++; | |
+ } | |
+ $j = count($from) - 1; | |
+ // Add '..' until the path is the same | |
+ while ($i <= $j) { | |
+ if (!empty($from[$j])) $relpath .= '..' . DIRECTORY_SEPARATOR; | |
+ $j--; | |
+ } | |
+ // Go to folder from where it starts differing | |
+ while (isset($to[$i])) { | |
+ if (!empty($to[$i])) $relpath .= $to[$i] . DIRECTORY_SEPARATOR; | |
+ $i++; | |
+ } | |
+ | |
+ // Strip last separator | |
+ return substr($relpath, 0, -1); | |
+ } | |
+ | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment