From e7d8d5ce6875663a845b2cbd76c6e972e27cc4cf Mon Sep 17 00:00:00 2001 From: mikec Date: Tue, 28 Jan 2014 21:43:43 -0500 Subject: [PATCH] Adds general.yml parameter "ssh_needs_tty" which appends "-t" to the ssh command Adds deployment parameter "rsync: { copy: yes }" which copies the prior release then rsync's (to increase speed) --- Mage/Command/BuiltIn/InitCommand.php | 9 ++++--- Mage/Task/AbstractTask.php | 15 ++++++----- .../BuiltIn/Deployment/Strategy/RsyncTask.php | 26 +++++++++++++++---- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/Mage/Command/BuiltIn/InitCommand.php b/Mage/Command/BuiltIn/InitCommand.php index 2395b39d..c26d912a 100644 --- a/Mage/Command/BuiltIn/InitCommand.php +++ b/Mage/Command/BuiltIn/InitCommand.php @@ -73,13 +73,15 @@ protected function getGeneralConfig() '%notificationEnabled%', '%loggingEnabled%', '%maxlogs%', + '%ssh_needs_tty%', ), array( $projectName, $notificationEmail, $notificationEnabled, 'true', - 30 + 30, + 'false' ), $this->getGeneralConfigTemplate() ); @@ -98,8 +100,9 @@ protected function getGeneralConfigTemplate() . 'email: %notificationEmail%' . PHP_EOL . 'notifications: %notificationEnabled%' . PHP_EOL . 'logging: %loggingEnabled%' . PHP_EOL - . 'maxlogs: %maxlogs%' . PHP_EOL; + . 'maxlogs: %maxlogs%' . PHP_EOL + . 'ssh_needs_tty: %ssh_needs_tty%' . PHP_EOL; return $template; } -} \ No newline at end of file +} diff --git a/Mage/Task/AbstractTask.php b/Mage/Task/AbstractTask.php index 3f34b94a..e1ea9341 100644 --- a/Mage/Task/AbstractTask.php +++ b/Mage/Task/AbstractTask.php @@ -179,17 +179,20 @@ protected final function runCommandRemote($command, &$output = null) $releasesDirectory = ''; } else { - $releasesDirectory = '/' - . $this->getConfig()->release('directory', 'releases') - . '/' + $releasesDirectory = '/' + . $this->getConfig()->release('directory', 'releases') + . '/' . $this->getConfig()->getReleaseId(); - } + } } else { $releasesDirectory = ''; } + + // if general.yml includes "ssy_needs_tty: true", then add "-t" to the ssh command + $needs_tty = ($this->getConfig()->general('ssh_needs_tty',false) ? "-t" : ""); - $localCommand = 'ssh -p ' . $this->getConfig()->getHostPort() . ' ' + $localCommand = 'ssh ' . $needs_tty . ' -p ' . $this->getConfig()->getHostPort() . ' ' . '-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ' . $this->getConfig()->deployment('user') . '@' . $this->getConfig()->getHostName() . ' ' . '"cd ' . rtrim($this->getConfig()->deployment('to'), '/') . $releasesDirectory . ' && ' @@ -213,4 +216,4 @@ protected final function runCommand($command, &$output = null) return $this->runCommandLocal($command, $output); } } -} \ No newline at end of file +} diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php index e1f9cca5..345b4047 100644 --- a/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php +++ b/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php @@ -30,7 +30,12 @@ public function getName() if ($this->getConfig()->getParameter('overrideRelease', false) == true) { return 'Deploy via Rsync (with Releases override) [built-in]'; } else { - return 'Deploy via Rsync (with Releases) [built-in]'; + $rsync_copy = $this->getConfig()->deployment("rsync"); + if ( $rsync_copy && is_array($rsync_copy) && $rsync_copy['copy'] ) { + return 'Deploy via Rsync (with Releases) [built-in, incremental]'; + } else { + return 'Deploy via Rsync (with Releases) [built-in]'; + } } } else { return 'Deploy via Rsync [built-in]'; @@ -58,8 +63,8 @@ public function run() '.svn', '.mage', '.gitignore', - '.gitkeep', - 'nohup.out' + '.gitkeep', + 'nohup.out' ); // Look for User Excludes @@ -73,7 +78,18 @@ public function run() $deployToDirectory = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory . '/' . $this->getConfig()->getReleaseId(); - $this->runCommandRemote('mkdir -p ' . $releasesDirectory . '/' . $this->getConfig()->getReleaseId()); + $resultFetch = $this->runCommandRemote('ls -ld current | cut -d"/" -f2', $releaseToOverride); + + if ( $resultFetch ) { + // If deployment configuration is rsync, include a flag to simply sync the deltas between the prior release + // rsync: { copy: yes } + $rsync_copy = $this->getConfig()->deployment("rsync"); + if ( $rsync_copy && is_array($rsync_copy) && $rsync_copy['copy'] ) { + $this->runCommandRemote('cp -R ' . $releasesDirectory . '/' . $releaseToOverride . ' ' . $releasesDirectory . '/' . $this->getConfig()->getReleaseId()); + } else { + $this->runCommandRemote('mkdir -p ' . $releasesDirectory . '/' . $this->getConfig()->getReleaseId()); + } + } } $command = 'rsync -avz ' @@ -137,4 +153,4 @@ protected function excludes(Array $excludes) $excludesRsync = trim($excludesRsync); return $excludesRsync; } -} \ No newline at end of file +}