Reorganize common Deployment code.

This commit is contained in:
Andrés Montañez 2014-06-12 17:12:30 -03:00
parent b174d04da2
commit 4528788d49
4 changed files with 74 additions and 47 deletions

View file

@ -0,0 +1,64 @@
<?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mage\Task\BuiltIn\Deployment\Strategy;
use Mage\Task\AbstractTask;
use Mage\Task\Releases\IsReleaseAware;
/**
* Abstract Base task to concentrate common code for Deployment Tasks
*
* @author Andrés Montañez <andres@andresmontanez.com>
*/
abstract class BaseStrategyTaskAbstract extends AbstractTask implements IsReleaseAware
{
/**
* Checks if there is an override underway
*
* @return bool
*/
protected function checkOverrideRelease()
{
$overrideRelease = $this->getParameter('overrideRelease', false);
if ($overrideRelease == true) {
$releaseToOverride = false;
$resultFetch = $this->runCommandRemote('ls -ld current | cut -d"/" -f2', $releaseToOverride);
if ($resultFetch && is_numeric($releaseToOverride)) {
$this->getConfig()->setReleaseId($releaseToOverride);
}
}
return $overrideRelease;
}
/**
* Gathers the files to exclude
*
* @return array
*/
protected function getExcludes()
{
$excludes = array(
'.git',
'.svn',
'.mage',
'.gitignore',
'.gitkeep',
'nohup.out'
);
// Look for User Excludes
$userExcludes = $this->getConfig()->deployment('excludes', array());
return array_merge($excludes, $userExcludes);
}
}

View file

@ -10,7 +10,7 @@
namespace Mage\Task\BuiltIn\Deployment\Strategy;
use Mage\Task\AbstractTask;
use Mage\Task\BuiltIn\Deployment\Strategy\BaseStrategyTaskAbstract;
use Mage\Task\Releases\IsReleaseAware;
/**
@ -18,7 +18,7 @@ use Mage\Task\Releases\IsReleaseAware;
*
* @author Andrés Montañez <andres@andresmontanez.com>
*/
class RsyncTask extends AbstractTask implements IsReleaseAware
class RsyncTask extends BaseStrategyTaskAbstract implements IsReleaseAware
{
/**
* (non-PHPdoc)
@ -48,27 +48,9 @@ class RsyncTask extends AbstractTask implements IsReleaseAware
*/
public function run()
{
$overrideRelease = $this->getParameter('overrideRelease', false);
$this->checkOverrideRelease();
if ($overrideRelease == true) {
$releaseToOverride = false;
$resultFetch = $this->runCommandRemote('ls -ld current | cut -d"/" -f2', $releaseToOverride);
if ($resultFetch && is_numeric($releaseToOverride)) {
$this->getConfig()->setReleaseId($releaseToOverride);
}
}
$excludes = array(
'.git',
'.svn',
'.mage',
'.gitignore',
'.gitkeep',
'nohup.out'
);
// Look for User Excludes
$userExcludes = $this->getConfig()->deployment('excludes', array());
$excludes = $this->getExcludes();
// If we are working with releases
$deployToDirectory = $this->getConfig()->deployment('to');
@ -95,7 +77,7 @@ class RsyncTask extends AbstractTask implements IsReleaseAware
$command = 'rsync -avz '
. '--rsh="ssh ' . $this->getConfig()->getHostIdentityFileOption() . '-p' . $this->getConfig()->getHostPort() . '" '
. $this->excludes(array_merge($excludes, $userExcludes)) . ' '
. $this->excludes($excludes) . ' '
. $this->getConfig()->deployment('from') . ' '
. $this->getConfig()->deployment('user') . '@' . $this->getConfig()->getHostName() . ':' . $deployToDirectory;

View file

@ -10,7 +10,7 @@
namespace Mage\Task\BuiltIn\Deployment\Strategy;
use Mage\Task\AbstractTask;
use Mage\Task\BuiltIn\Deployment\Strategy\BaseStrategyTaskAbstract;
use Mage\Task\Releases\IsReleaseAware;
/**
@ -18,7 +18,7 @@ use Mage\Task\Releases\IsReleaseAware;
*
* @author Andrés Montañez <andres@andresmontanez.com>
*/
class TarGzTask extends AbstractTask implements IsReleaseAware
class TarGzTask extends BaseStrategyTaskAbstract implements IsReleaseAware
{
/**
* (non-PHPdoc)
@ -43,27 +43,9 @@ class TarGzTask extends AbstractTask implements IsReleaseAware
*/
public function run()
{
$overrideRelease = $this->getParameter('overrideRelease', false);
$this->checkOverrideRelease();
if ($overrideRelease == true) {
$releaseToOverride = false;
$resultFetch = $this->runCommandRemote('ls -ld current | cut -d"/" -f2', $releaseToOverride);
if ($resultFetch && is_numeric($releaseToOverride)) {
$this->getConfig()->setReleaseId($releaseToOverride);
}
}
$excludes = array(
'.git',
'.svn',
'.mage',
'.gitignore',
'.gitkeep',
'nohup.out'
);
// Look for User Excludes
$userExcludes = $this->getConfig()->deployment('excludes', array());
$excludes = $this->getExcludes();
// If we are working with releases
$deployToDirectory = $this->getConfig()->deployment('to');
@ -79,7 +61,6 @@ class TarGzTask extends AbstractTask implements IsReleaseAware
// Create Tar Gz
$localTarGz = tempnam(sys_get_temp_dir(), 'mage');
$remoteTarGz = basename($localTarGz);
$excludes = array_merge($excludes, $userExcludes);
$excludeCmd = '';
foreach ($excludes as $excludeFile) {
$excludeCmd .= ' --exclude=' . $excludeFile;

View file

@ -2,7 +2,7 @@
deployment:
user: root
from: ./
to: /var/www/
to: /var/vvv
scm:
branch: master
releases: