mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-11-04 17:10:18 +01:00 
			
		
		
		
	force use of sh on remote server and make directory ownership check more portable
This commit is contained in:
		
							parent
							
								
									23b59869ec
								
							
						
					
					
						commit
						47b089cb3e
					
				@ -170,9 +170,10 @@ abstract class AbstractTask
 | 
				
			|||||||
     * Runs a Shell Command on the Remote Host
 | 
					     * Runs a Shell Command on the Remote Host
 | 
				
			||||||
     * @param string $command
 | 
					     * @param string $command
 | 
				
			||||||
     * @param string $output
 | 
					     * @param string $output
 | 
				
			||||||
 | 
					     * @param boolean $cdToDirectoryFirst
 | 
				
			||||||
     * @return boolean
 | 
					     * @return boolean
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    protected final function runCommandRemote($command, &$output = null)
 | 
					    protected final function runCommandRemote($command, &$output = null, $cdToDirectoryFirst = true)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if ($this->getConfig()->release('enabled', false) == true) {
 | 
					        if ($this->getConfig()->release('enabled', false) == true) {
 | 
				
			||||||
            if ($this instanceOf IsReleaseAware) {
 | 
					            if ($this instanceOf IsReleaseAware) {
 | 
				
			||||||
@ -194,9 +195,15 @@ abstract class AbstractTask
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        $localCommand = 'ssh ' . $this->getConfig()->getHostIdentityFileOption() . $needs_tty . ' -p ' . $this->getConfig()->getHostPort() . ' '
 | 
					        $localCommand = 'ssh ' . $this->getConfig()->getHostIdentityFileOption() . $needs_tty . ' -p ' . $this->getConfig()->getHostPort() . ' '
 | 
				
			||||||
                      . '-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no '
 | 
					                      . '-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no '
 | 
				
			||||||
                      . $this->getConfig()->deployment('user') . '@' . $this->getConfig()->getHostName() . ' '
 | 
					                      . $this->getConfig()->deployment('user') . '@' . $this->getConfig()->getHostName();
 | 
				
			||||||
                      . '"cd ' . rtrim($this->getConfig()->deployment('to'), '/') . $releasesDirectory . ' && '
 | 
					
 | 
				
			||||||
                      . str_replace('"', '\"', $command) . '"';
 | 
					        $remoteCommand = str_replace('"', '\"', $command);
 | 
				
			||||||
 | 
					        if($cdToDirectoryFirst){
 | 
				
			||||||
 | 
					            $remoteCommand = 'cd ' . rtrim($this->getConfig()->deployment('to'), '/') . $releasesDirectory . ' && ' . $remoteCommand;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        $localCommand .= ' ' . '"sh -c \"' .  $remoteCommand . '\""';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Console::log('Run remote command ' . $remoteCommand);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $this->runCommandLocal($localCommand, $output);
 | 
					        return $this->runCommandLocal($localCommand, $output);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -46,9 +46,30 @@ class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            $currentCopy = $releasesDirectory . '/' . $this->getConfig()->getReleaseId();
 | 
					            $currentCopy = $releasesDirectory . '/' . $this->getConfig()->getReleaseId();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            //Check if target user:group is specified
 | 
				
			||||||
 | 
					            $userGroup = $this->getConfig()->deployment('chown');
 | 
				
			||||||
            // Fetch the user and group from base directory; defaults usergroup to 33:33
 | 
					            // Fetch the user and group from base directory; defaults usergroup to 33:33
 | 
				
			||||||
            $userGroup = '';
 | 
					            if(empty($userGroup)){
 | 
				
			||||||
            $resultFetch = $this->runCommandRemote('ls -ld . | awk \'{print \$3":"\$4}\'', $userGroup);
 | 
					                $user = '33';
 | 
				
			||||||
 | 
					                $group = '33';
 | 
				
			||||||
 | 
					                $directoryInfos = '';
 | 
				
			||||||
 | 
					                // Get raw directory info and parse it in php.
 | 
				
			||||||
 | 
					                // "stat" command don't behave the same on different systems, ls output format also varies
 | 
				
			||||||
 | 
					                // and awk parameters need special care depending on the executing shell
 | 
				
			||||||
 | 
					                $resultFetch = $this->runCommandRemote("ls -ld .", $directoryInfos);
 | 
				
			||||||
 | 
					                if(!empty($directoryInfos)){
 | 
				
			||||||
 | 
					                    //uniformize format as it depends on the system deployed on
 | 
				
			||||||
 | 
					                    $directoryInfos = trim(str_replace(array("  ", "\t"), ' ', $directoryInfos));
 | 
				
			||||||
 | 
					                    $infoArray = explode(' ', $directoryInfos);
 | 
				
			||||||
 | 
					                    if(!empty($infoArray[2])) {
 | 
				
			||||||
 | 
					                        $user = $infoArray[2];
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    if(!empty($infoArray[3])) {
 | 
				
			||||||
 | 
					                        $group = $infoArray[3];
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    $userGroup = $user . ':' . $group;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Remove symlink if exists; create new symlink and change owners
 | 
					            // Remove symlink if exists; create new symlink and change owners
 | 
				
			||||||
            $command = 'rm -f ' . $symlink
 | 
					            $command = 'rm -f ' . $symlink
 | 
				
			||||||
 | 
				
			|||||||
@ -79,6 +79,10 @@ class RsyncTask extends AbstractTask implements IsReleaseAware
 | 
				
			|||||||
            $deployToDirectory = rtrim($this->getConfig()->deployment('to'), '/')
 | 
					            $deployToDirectory = rtrim($this->getConfig()->deployment('to'), '/')
 | 
				
			||||||
                               . '/' . $releasesDirectory
 | 
					                               . '/' . $releasesDirectory
 | 
				
			||||||
                               . '/' . $this->getConfig()->getReleaseId();
 | 
					                               . '/' . $this->getConfig()->getReleaseId();
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            Console::log('Deploy to ' . $deployToDirectory);
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            $resultFetch = $this->runCommandRemote('ls -ld current | cut -d"/" -f2', $currentRelease);
 | 
					            $resultFetch = $this->runCommandRemote('ls -ld current | cut -d"/" -f2', $currentRelease);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if ($resultFetch && $currentRelease) {
 | 
					            if ($resultFetch && $currentRelease) {
 | 
				
			||||||
 | 
				
			|||||||
@ -69,11 +69,11 @@ class TarGzTask extends AbstractTask implements IsReleaseAware
 | 
				
			|||||||
        $deployToDirectory = $this->getConfig()->deployment('to');
 | 
					        $deployToDirectory = $this->getConfig()->deployment('to');
 | 
				
			||||||
        if ($this->getConfig()->release('enabled', false) == true) {
 | 
					        if ($this->getConfig()->release('enabled', false) == true) {
 | 
				
			||||||
            $releasesDirectory = $this->getConfig()->release('directory', 'releases');
 | 
					            $releasesDirectory = $this->getConfig()->release('directory', 'releases');
 | 
				
			||||||
 | 
					 | 
				
			||||||
            $deployToDirectory = rtrim($this->getConfig()->deployment('to'), '/')
 | 
					            $deployToDirectory = rtrim($this->getConfig()->deployment('to'), '/')
 | 
				
			||||||
                               . '/' . $releasesDirectory
 | 
					                               . '/' . $releasesDirectory
 | 
				
			||||||
                               . '/' . $this->getConfig()->getReleaseId();
 | 
					                               . '/' . $this->getConfig()->getReleaseId();
 | 
				
			||||||
            $this->runCommandRemote('mkdir -p ' . $releasesDirectory . '/' . $this->getConfig()->getReleaseId());
 | 
					            $output = null;
 | 
				
			||||||
 | 
					            $this->runCommandRemote('mkdir -p ' . $deployToDirectory, $output , false);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Create Tar Gz
 | 
					        // Create Tar Gz
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user