Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.*.un~
.*.swp
9 changes: 9 additions & 0 deletions BeSimpleDeploymentBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace BeSimple\DeploymentBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class BeSimpleDeploymentBundle extends Bundle
{
}
29 changes: 16 additions & 13 deletions Command/DeploymentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
namespace BeSimple\DeploymentBundle\Command;

use Symfony\Component\EventDispatcher\EventInterface;
use Bundle\DeploymentBundle\Deployer\Deployer;
use BeSimple\DeploymentBundle\Deployer\Deployer;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\Output;
use Symfony\Bundle\FrameworkBundle\Command\Command as BaseCommand;

abstract class DeploymentCommand extends Command
abstract class DeploymentCommand extends BaseCommand
{
protected function configure()
{
parent::configure();

$this
->setDefinition(array(
new InputArgument('server', InputArgument::OPTIONAL, 'The target server name', null),
Expand All @@ -23,23 +26,23 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output)
{
$deployer = $this->container->get('besimple_deployment.deployer');
$deployer = $this->container->get('be_simple_deployment.deployer');
$eventDispatcher = $this->container->get('event_dispatcher');

$this->output = $output;
$this->output->setDecorated(true);

if ($output->getVerbosity() > Output::VERBOSITY_QUIET) {
$dispatcher->connect('besimple_deployment.start', function ($event) use ($that) { $that->write($event, 'start'); });
$dispatcher->connect('besimple_deployment.error', function ($event) use ($that) { $that->write($event, 'error'); });
$dispatcher->connect('besimple_deployment.success', function ($event) use ($that) { $that->write($event, 'success'); });
//if ($output->getVerbosity() > Output::VERBOSITY_QUIET) {
//$eventDispatcher->addListener('besimple_deployment.start', function ($event) use ($that) { $that->write($event, 'start'); });
//$eventDispatcher->addListener('besimple_deployment.error', function ($event) use ($that) { $that->write($event, 'error'); });
//$eventDispatcher->addListener('besimple_deployment.success', function ($event) use ($that) { $that->write($event, 'success'); });

if ($output->getVerbosity() > Output::VERBOSITY_NORMAL) {
$dispatcher->connect('besimple_deployment.rsync', function ($event) use ($that) { $that->write($event, 'rsync'); });
}
//if ($output->getVerbosity() > Output::VERBOSITY_NORMAL) {
//$eventDispatcher->addListener('besimple_deployment.rsync', function ($event) use ($that) { $that->write($event, 'rsync'); });
//}

// TODO: add SSH events
}
//// TODO: add SSH events
//}

$this->executeDeployment($deployer, $input->getArgument('server'));
}
Expand Down Expand Up @@ -77,4 +80,4 @@ public function write(EventInterface $event, $type)
}

abstract protected function executeDeployment(Deployer $deployer, $server);
}
}
8 changes: 5 additions & 3 deletions Command/LaunchDeploymentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

namespace BeSimple\DeploymentBundle\Command;

use Bundle\DeploymentBundle\Deployer\Deployer;
use BeSimple\DeploymentBundle\Deployer\Deployer;
use Symfony\Component\Console\Command\Command;

abstract class DeploymentCommand extends Command
class LaunchDeploymentCommand extends DeploymentCommand
{
protected function configure()
{
parent::configure();
$this->setName('deployment:launch');
}

protected function executeDeployment(Deployer $deployer, $server)
{
$deployer->launch($server);
}
}
}
8 changes: 5 additions & 3 deletions Command/TestDeploymentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

namespace BeSimple\DeploymentBundle\Command;

use Bundle\DeploymentBundle\Deployer\Deployer;
use BeSimple\DeploymentBundle\Deployer\Deployer;
use Symfony\Component\Console\Command\Command;

abstract class DeploymentCommand extends Command
class TestDeploymentCommand extends DeploymentCommand
{
protected function configure()
{
parent::configure();
$this->setName('deployment:test');
}

protected function executeDeployment(Deployer $deployer, $server)
{
$deployer->test($server);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
namespace BeSimple\DeploymentBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;

class BeSimpleDeploymentExtension extends Extension
{
Expand All @@ -18,10 +19,15 @@ public function load(array $configs, ContainerBuilder $container)
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('deployment.xml');

$container->setParameter('besimple_deployment.config.rsync', $config['rsync']);
$container->setParameter('besimple_deployment.config.ssh', $config['rsync']);
$container->setParameter('besimple_deployment.config.rules', $config['rules']);
$container->setParameter('besimple_deployment.config.commands', $config['commands']);
$container->setParameter('besimple_deployment.config.servers', $config['servers']);
$container->setParameter('be_simple_deployment.config.rsync', $config['rsync']);
$container->setParameter('be_simple_deployment.config.ssh', $config['rsync']);
$container->setParameter('be_simple_deployment.config.rules', $config['rules']);
$container->setParameter('be_simple_deployment.config.commands', $config['commands']);
$container->setParameter('be_simple_deployment.config.servers', $config['servers']);
}
}

public function getAlias()
{
return 'be_simple_deployment';
}
}
67 changes: 35 additions & 32 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace BeSimple\DeploymentBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\NodeBuilder;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;

class Configuration
Expand All @@ -15,7 +15,7 @@ class Configuration
public function getConfigTree()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('besimple_deployment', 'array');
$rootNode = $treeBuilder->root('be_simple_deployment', 'array');

$this->addRsyncSection($rootNode);
$this->addSshSection($rootNode);
Expand All @@ -26,73 +26,76 @@ public function getConfigTree()
return $treeBuilder->buildTree();
}

protected function addRsyncSection(NodeBuilder $node)
protected function addRsyncSection(ArrayNodeDefinition $node)
{
$node
$node->children()
->arrayNode('rsync')
->scalarNode('command')->defaultValue('rsync')->cannotBeEmpty()->end()
->booleanNode('delete')->defaultFalse()->end()
->scalarNode('options')->defaultValue('-Cva')->end()
->scalarNode('root')->defaultValue('%kernel.root_dir%/..')->isRequired()->cannotBeEmpty()->end()
->end()
->addDefaultsIfNotSet()
->children()
->scalarNode('command')->defaultValue('rsync')->cannotBeEmpty()->end()
->booleanNode('delete')->defaultFalse()->end()
->scalarNode('options')->defaultValue('-Cva')->end()
->scalarNode('root')->defaultValue('%kernel.root_dir%/..')->cannotBeEmpty()->end()
->end()
;
}

protected function addSshSection(NodeBuilder $node)
protected function addSshSection(ArrayNodeDefinition $node)
{
$node
->arrayNode('rsync')
$node->children()
->arrayNode('ssh')->children()
->scalarNode('pubkey_file')->defaultNull()->end()
->scalarNode('privkey_file')->defaultNull()->end()
->scalarNode('passpharse')->defaultNull()->end()
->scalarNode('passphrase')->defaultNull()->end()
->end()
;
}

protected function addRulesSection(NodeBuilder $node)
protected function addRulesSection(ArrayNodeDefinition $node)
{
$node
$node->children()
->arrayNode('rules')
->useAttributeAsKey('name')
->prototype('array')
->arrayNode('ignore')->defaultValue(array())->end()
->arrayNode('force')->defaultValue(array())->end()
->prototype('array')->children()
->arrayNode('ignore')->defaultValue(array())->ignoreExtraKeys()->end()
->arrayNode('force')->defaultValue(array())->ignoreExtraKeys()->end()
->end()
->end()
;
}

protected function addCommandsSection(NodeBuilder $node)
protected function addCommandsSection(ArrayNodeDefinition $node)
{
$node
$node->children()
->arrayNode('commands')
->useAttributeAsKey('name')
->children()
->scalarNode('command')->defaultValue('./app/console')->cannotBeEmpty()->end()
->useAttributeAsKey('name')
->prototype('array')
->arrayNode('type')->defaultValue('symfony')->end()
->arrayNode('command')->isRequired()->cannotBeEmpty()->end()
->arrayNode('env')->defaultNull()->end()
->end()
->end()
->prototype('array')->children()
->scalarNode('type')->defaultValue('symfony')->end()
->scalarNode('command')->isRequired()->cannotBeEmpty()->end()
->scalarNode('env')->defaultNull()->end()
->end()
;
}

protected function addServersSection(NodeBuilder $node)
protected function addServersSection(ArrayNodeDefinition $node)
{
$node
$node->children()
->arrayNode('servers')
->useAttributeAsKey('name')
->prototype('array')
->prototype('array')->children()
->scalarNode('host')->defaultValue('localhost')->end()
->scalarNode('rsync_port')->defaultNull()->end()
->scalarNode('ssh_port')->defaultValue(22)->cannotBeEmpty()->end()
->scalarNode('username')->defaultNull()->end()
->scalarNode('password')->defaultNull()->end()
->scalarNode('path')->isRequired()->cannotBeEmpty()->end()
->arrayNode('rules')->defaultValue(array())->end()
->arrayNode('commands')->defaultValue(array())->end()
->arrayNode('rules')->defaultValue(array())->ignoreExtraKeys()->end()
->arrayNode('commands')->defaultValue(array())->ignoreExtraKeys()->end()
->end()
->end()
;
}
}
}
30 changes: 15 additions & 15 deletions Deployer/Config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Bundle\DeploymentBundle\Deployer;
namespace BeSimple\DeploymentBundle\Deployer;

class Config
{
Expand All @@ -14,34 +14,34 @@ public function __construct(array $rules, array $commands, array $servers)
$this->rules = $rules;
$this->commands = $commands;
$this->servers = $servers;
$this->config = $config;
$this->config = array();
}

public function getServerNames()
{
return array_keys($this->servers);
}

public function getSeverConfig($name)
public function getServerConfig($server)
{
if (!isset($this->servers[$name])) {
throw new \InvalidArgumentException(sprintf('Server "%s" not configured', $name));
if (!isset($this->servers[$server])) {
throw new \InvalidArgumentException(sprintf('Server "%s" not configured', $server));
}

if (!isset($this->config[$name])) {
$this->config[$name] = array(
'connection' => $this->getConnectionConfig($this->server[$name]),
'rules' => $this->getRulesConfig($this->server[$name]),
'commands' => $this->getCommandsConfig($this->server[$name]),
if (!isset($this->config[$server])) {
$this->config[$server] = array(
'connection' => $this->getConnectionConfig($server),
'rules' => $this->getRulesConfig($server),
'commands' => $this->getCommandsConfig($server),
);
}

return $this->config[$name];
return $this->config[$server];
}

protected function getConnectionConfig($server)
{
$config = $this->server[$server];
$config = $this->servers[$server];
unset($config['rules'], $config['commands']);

return $config;
Expand All @@ -56,7 +56,7 @@ protected function getRulesConfig($server)

$parameters = array_keys($config);

foreach ($this->server[$server]['rules'] as $name) {
foreach ($this->servers[$server]['rules'] as $name) {
if (!isset($this->rules[$name])) {
throw new \InvalidArgumentException(sprintf('Rule "%s" declared in server "%s" is not configured', $name, $server));
}
Expand All @@ -73,7 +73,7 @@ protected function getCommandsConfig($server)
{
$config = array();

foreach ($this->server[$server]['commands'] as $name) {
foreach ($this->servers[$server]['commands'] as $name) {
if (!isset($this->commands[$name])) {
throw new \InvalidArgumentException(sprintf('Command "%s" declared in server "%s" is not configured', $name, $server));
}
Expand All @@ -83,4 +83,4 @@ protected function getCommandsConfig($server)

return $config;
}
}
}
Loading