Skip to content

Commit

Permalink
Merge pull request #375 from andres-montanez/nostromo
Browse files Browse the repository at this point in the history
v3.2
  • Loading branch information
andres-montanez committed Apr 15, 2017
2 parents d95e498 + 8a10e61 commit 7c87fb4
Show file tree
Hide file tree
Showing 30 changed files with 686 additions and 76 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,14 @@
CHANGELOG for 3.X
=================

* 3.2.0 (2017-04-14)
* Allow to pre-register Custom Tasks
* [PR#365] New option "from" to define deployment start point
* Allow to define excludes in the global scope.
* Improve code quality, remove duplications on Symfony Tasks.
* Improve code quality, remove duplications on Composer Tasks.
* [PR#364] Allow to define custom timeout to Composer:Install

* 3.1.0 (2017-02-25)
* Add new Exec task to execute arbitrary shell commands
* Add new Composer task, to update phar (composer/self-update)
Expand Down
4 changes: 4 additions & 0 deletions docs/example-config.yml
Expand Up @@ -3,6 +3,7 @@ magephp:
production:
user: app
branch: test
from: ./
host_path: /var/www/test
releases: 4
exclude:
Expand All @@ -25,3 +26,6 @@ magephp:
on-release:
post-release:
post-deploy:
- magic
custom_tasks:
- App\Deployment\MagicTask
2 changes: 1 addition & 1 deletion src/Mage.php
Expand Up @@ -17,6 +17,6 @@
*/
class Mage
{
const VERSION = '3.1.0';
const VERSION = '3.x-dev';
const CODENAME = 'Nostromo';
}
38 changes: 38 additions & 0 deletions src/Task/BuiltIn/Composer/AbstractComposerTask.php
@@ -0,0 +1,38 @@
<?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\Composer;

use Mage\Task\AbstractTask;

/**
* Abstract Composer Task
*
* @author Andrés Montañez <andresmontanez@gmail.com>
*/
abstract class AbstractComposerTask extends AbstractTask
{
protected function getOptions()
{
$options = array_merge(
['path' => 'composer'],
$this->getComposerOptions(),
$this->runtime->getMergedOption('composer'),
$this->options
);

return $options;
}

protected function getComposerOptions()
{
return [];
}
}
13 changes: 3 additions & 10 deletions src/Task/BuiltIn/Composer/DumpAutoloadTask.php
Expand Up @@ -11,14 +11,13 @@
namespace Mage\Task\BuiltIn\Composer;

use Symfony\Component\Process\Process;
use Mage\Task\AbstractTask;

/**
* Composer Task - Generate Autoload
*
* @author Andrés Montañez <andresmontanez@gmail.com>
*/
class DumpAutoloadTask extends AbstractTask
class DumpAutoloadTask extends AbstractComposerTask
{
public function getName()
{
Expand All @@ -41,14 +40,8 @@ public function execute()
return $process->isSuccessful();
}

protected function getOptions()
protected function getComposerOptions()
{
$options = array_merge(
['path' => 'composer', 'flags' => '--optimize'],
$this->runtime->getMergedOption('composer'),
$this->options
);

return $options;
return ['flags' => '--optimize'];
}
}
15 changes: 4 additions & 11 deletions src/Task/BuiltIn/Composer/InstallTask.php
Expand Up @@ -11,14 +11,13 @@
namespace Mage\Task\BuiltIn\Composer;

use Symfony\Component\Process\Process;
use Mage\Task\AbstractTask;

/**
* Composer Task - Install Vendors
*
* @author Andrés Montañez <andresmontanez@gmail.com>
*/
class InstallTask extends AbstractTask
class InstallTask extends AbstractComposerTask
{
public function getName()
{
Expand All @@ -36,19 +35,13 @@ public function execute()
$cmd = sprintf('%s install %s', $options['path'], $options['flags']);

/** @var Process $process */
$process = $this->runtime->runCommand(trim($cmd));
$process = $this->runtime->runCommand(trim($cmd), $options['timeout']);

return $process->isSuccessful();
}

protected function getOptions()
protected function getComposerOptions()
{
$options = array_merge(
['path' => 'composer', 'flags' => '--optimize-autoloader'],
$this->runtime->getMergedOption('composer'),
$this->options
);

return $options;
return ['flags' => '--optimize-autoloader', 'timeout' => 120];
}
}
13 changes: 3 additions & 10 deletions src/Task/BuiltIn/Composer/SelfUpdateTask.php
Expand Up @@ -12,15 +12,14 @@

use Mage\Task\Exception\SkipException;
use Symfony\Component\Process\Process;
use Mage\Task\AbstractTask;
use DateTime;

/**
* Composer Task - Self update
*
* @author Yanick Witschi <https://github.com/Toflar>
*/
class SelfUpdateTask extends AbstractTask
class SelfUpdateTask extends AbstractComposerTask
{
public function getName()
{
Expand Down Expand Up @@ -80,14 +79,8 @@ protected function getCompareDate()
return $compareDate;
}

protected function getOptions()
protected function getComposerOptions()
{
$options = array_merge(
['path' => 'composer', 'days' => 60],
$this->runtime->getMergedOption('composer'),
$this->options
);

return $options;
return ['days' => 60];
}
}
5 changes: 3 additions & 2 deletions src/Task/BuiltIn/Deploy/RsyncTask.php
Expand Up @@ -45,7 +45,8 @@ public function execute()
}

$excludes = $this->getExcludes();
$cmdRsync = sprintf('rsync -e "ssh -p %d %s" %s %s ./ %s@%s:%s', $sshConfig['port'], $sshConfig['flags'], $flags, $excludes, $user, $host, $targetDir);
$from = $this->runtime->getEnvOption('from', './');
$cmdRsync = sprintf('rsync -e "ssh -p %d %s" %s %s %s %s@%s:%s', $sshConfig['port'], $sshConfig['flags'], $flags, $excludes, $from, $user, $host, $targetDir);

/** @var Process $process */
$process = $this->runtime->runLocalCommand($cmdRsync, 600);
Expand All @@ -54,7 +55,7 @@ public function execute()

protected function getExcludes()
{
$excludes = $this->runtime->getEnvOption('exclude', []);
$excludes = $this->runtime->getMergedOption('exclude', []);
$excludes = array_merge(['.git'], array_filter($excludes));

foreach ($excludes as &$exclude) {
Expand Down
5 changes: 3 additions & 2 deletions src/Task/BuiltIn/Deploy/Tar/PrepareTask.php
Expand Up @@ -42,7 +42,8 @@ public function execute()

$excludes = $this->getExcludes();
$flags = $this->runtime->getEnvOption('tar_create', 'cfzp');
$cmdTar = sprintf('tar %s %s %s ./', $flags, $tarLocal, $excludes);
$from = $this->runtime->getEnvOption('from', './');
$cmdTar = sprintf('tar %s %s %s %s', $flags, $tarLocal, $excludes, $from);

/** @var Process $process */
$process = $this->runtime->runLocalCommand($cmdTar, 300);
Expand All @@ -51,7 +52,7 @@ public function execute()

protected function getExcludes()
{
$excludes = $this->runtime->getEnvOption('exclude', []);
$excludes = $this->runtime->getMergedOption('exclude', []);
$excludes = array_merge(['.git'], array_filter($excludes));

foreach ($excludes as &$exclude) {
Expand Down
38 changes: 38 additions & 0 deletions src/Task/BuiltIn/Symfony/AbstractSymfonyTask.php
@@ -0,0 +1,38 @@
<?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\Symfony;

use Mage\Task\AbstractTask;

/**
* Abstract Symfony Task
*
* @author Andrés Montañez <andresmontanez@gmail.com>
*/
abstract class AbstractSymfonyTask extends AbstractTask
{
protected function getOptions()
{
$options = array_merge(
['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
$this->getSymfonyOptions(),
$this->runtime->getMergedOption('symfony'),
$this->options
);

return $options;
}

protected function getSymfonyOptions()
{
return [];
}
}
13 changes: 3 additions & 10 deletions src/Task/BuiltIn/Symfony/AssetsInstallTask.php
Expand Up @@ -11,14 +11,13 @@
namespace Mage\Task\BuiltIn\Symfony;

use Symfony\Component\Process\Process;
use Mage\Task\AbstractTask;

/**
* Symfony Task - Install Assets
*
* @author Andrés Montañez <andresmontanez@gmail.com>
*/
class AssetsInstallTask extends AbstractTask
class AssetsInstallTask extends AbstractSymfonyTask
{
public function getName()
{
Expand All @@ -41,14 +40,8 @@ public function execute()
return $process->isSuccessful();
}

protected function getOptions()
protected function getSymfonyOptions()
{
$options = array_merge(
['console' => 'bin/console', 'env' => 'dev', 'target' => 'web', 'flags' => '--symlink --relative'],
$this->runtime->getMergedOption('symfony'),
$this->options
);

return $options;
return ['target' => 'web', 'flags' => '--symlink --relative'];
}
}
14 changes: 1 addition & 13 deletions src/Task/BuiltIn/Symfony/CacheClearTask.php
Expand Up @@ -11,14 +11,13 @@
namespace Mage\Task\BuiltIn\Symfony;

use Symfony\Component\Process\Process;
use Mage\Task\AbstractTask;

/**
* Symfony Task - Clear Cache
*
* @author Andrés Montañez <andresmontanez@gmail.com>
*/
class CacheClearTask extends AbstractTask
class CacheClearTask extends AbstractSymfonyTask
{
public function getName()
{
Expand All @@ -40,15 +39,4 @@ public function execute()

return $process->isSuccessful();
}

protected function getOptions()
{
$options = array_merge(
['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
$this->runtime->getMergedOption('symfony'),
$this->options
);

return $options;
}
}
14 changes: 1 addition & 13 deletions src/Task/BuiltIn/Symfony/CacheWarmupTask.php
Expand Up @@ -11,14 +11,13 @@
namespace Mage\Task\BuiltIn\Symfony;

use Symfony\Component\Process\Process;
use Mage\Task\AbstractTask;

/**
* Symfony Task - Cache Warmup
*
* @author Andrés Montañez <andresmontanez@gmail.com>
*/
class CacheWarmupTask extends AbstractTask
class CacheWarmupTask extends AbstractSymfonyTask
{
public function getName()
{
Expand All @@ -40,15 +39,4 @@ public function execute()

return $process->isSuccessful();
}

protected function getOptions()
{
$options = array_merge(
['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
$this->runtime->getMergedOption('symfony'),
$this->options
);

return $options;
}
}

0 comments on commit 7c87fb4

Please sign in to comment.