From 60d93f335c4a3380974a7665382c3a904bc50da8 Mon Sep 17 00:00:00 2001 From: Jonas Wouters Date: Thu, 21 Apr 2011 11:04:46 +0200 Subject: [PATCH 01/14] Fixed naming issues --- .gitignore | 1 + BeSimpleDeploymentBundle.php | 9 +++++++++ Command/DeploymentCommand.php | 5 ++++- Command/LaunchDeploymentCommand.php | 6 ++++-- Command/TestDeploymentCommand.php | 6 ++++-- DependencyInjection/DeploymentExtension.php | 9 +++++++-- 6 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 .gitignore create mode 100755 BeSimpleDeploymentBundle.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f9d5fb1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.*.un~ \ No newline at end of file diff --git a/BeSimpleDeploymentBundle.php b/BeSimpleDeploymentBundle.php new file mode 100755 index 0000000..f783299 --- /dev/null +++ b/BeSimpleDeploymentBundle.php @@ -0,0 +1,9 @@ +setDefinition(array( new InputArgument('server', InputArgument::OPTIONAL, 'The target server name', null), @@ -77,4 +80,4 @@ public function write(EventInterface $event, $type) } abstract protected function executeDeployment(Deployer $deployer, $server); -} \ No newline at end of file +} diff --git a/Command/LaunchDeploymentCommand.php b/Command/LaunchDeploymentCommand.php index bffad00..9d3df25 100644 --- a/Command/LaunchDeploymentCommand.php +++ b/Command/LaunchDeploymentCommand.php @@ -3,11 +3,13 @@ namespace BeSimple\DeploymentBundle\Command; use Bundle\DeploymentBundle\Deployer\Deployer; +use Symfony\Component\Console\Command\Command; -abstract class DeploymentCommand extends Command +abstract class LaunchDeploymentCommand extends DeploymentCommand { protected function configure() { + parent::configure(); $this->setName('deployment:launch'); } @@ -15,4 +17,4 @@ protected function executeDeployment(Deployer $deployer, $server) { $deployer->launch($server); } -} \ No newline at end of file +} diff --git a/Command/TestDeploymentCommand.php b/Command/TestDeploymentCommand.php index 767e873..e1d059a 100644 --- a/Command/TestDeploymentCommand.php +++ b/Command/TestDeploymentCommand.php @@ -3,11 +3,13 @@ namespace BeSimple\DeploymentBundle\Command; use Bundle\DeploymentBundle\Deployer\Deployer; +use Symfony\Component\Console\Command\Command; -abstract class DeploymentCommand extends Command +abstract class TestDeploymentCommand extends DeploymentCommand { protected function configure() { + parent::configure(); $this->setName('deployment:test'); } @@ -15,4 +17,4 @@ protected function executeDeployment(Deployer $deployer, $server) { $deployer->test($server); } -} \ No newline at end of file +} diff --git a/DependencyInjection/DeploymentExtension.php b/DependencyInjection/DeploymentExtension.php index 3b9d6c5..5d46506 100755 --- a/DependencyInjection/DeploymentExtension.php +++ b/DependencyInjection/DeploymentExtension.php @@ -3,7 +3,7 @@ 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; @@ -24,4 +24,9 @@ public function load(array $configs, ContainerBuilder $container) $container->setParameter('besimple_deployment.config.commands', $config['commands']); $container->setParameter('besimple_deployment.config.servers', $config['servers']); } -} \ No newline at end of file + + public function getAlias() + { + return 'besimple_deployment'; + } +} From 1ae5fe2480d8fe78ae0763405f2bffcdbaa9694d Mon Sep 17 00:00:00 2001 From: Jonas Wouters Date: Thu, 21 Apr 2011 11:05:40 +0200 Subject: [PATCH 02/14] Fixed documentation --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9ee8443..74a04e9 100755 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ How to configure ###An example - deployment: + besimple_deployment: rsync: delete: true @@ -198,4 +198,4 @@ Subject of these events is the `besimple.ssh` service - command: The command line - stdout: The `stdout` lines as array -- stderr: The `stderr` lines as array \ No newline at end of file +- stderr: The `stderr` lines as array From 0322c78ab669b5071c496ec8c3f6030378932e81 Mon Sep 17 00:00:00 2001 From: Jonas Wouters Date: Thu, 21 Apr 2011 11:08:41 +0200 Subject: [PATCH 03/14] Removed duplicate bundle class --- DeploymentBundle.php | 9 --------- 1 file changed, 9 deletions(-) delete mode 100755 DeploymentBundle.php diff --git a/DeploymentBundle.php b/DeploymentBundle.php deleted file mode 100755 index 8545c9d..0000000 --- a/DeploymentBundle.php +++ /dev/null @@ -1,9 +0,0 @@ - Date: Thu, 21 Apr 2011 11:10:14 +0200 Subject: [PATCH 04/14] Rename extension file --- .../{DeploymentExtension.php => BeSimpleDeploymentExtension.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename DependencyInjection/{DeploymentExtension.php => BeSimpleDeploymentExtension.php} (100%) diff --git a/DependencyInjection/DeploymentExtension.php b/DependencyInjection/BeSimpleDeploymentExtension.php similarity index 100% rename from DependencyInjection/DeploymentExtension.php rename to DependencyInjection/BeSimpleDeploymentExtension.php From 7d44bc55a7d506edc1a8fc463885df922cb0a464 Mon Sep 17 00:00:00 2001 From: Jonas Wouters Date: Thu, 21 Apr 2011 13:15:33 +0200 Subject: [PATCH 05/14] Changed config to correct name --- .../BeSimpleDeploymentExtension.php | 12 ++--- DependencyInjection/Configuration.php | 47 ++++++++++--------- Resources/config/deployment.xml | 40 ++++++++-------- 3 files changed, 50 insertions(+), 49 deletions(-) diff --git a/DependencyInjection/BeSimpleDeploymentExtension.php b/DependencyInjection/BeSimpleDeploymentExtension.php index 5d46506..8372b1d 100755 --- a/DependencyInjection/BeSimpleDeploymentExtension.php +++ b/DependencyInjection/BeSimpleDeploymentExtension.php @@ -18,15 +18,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 'besimple_deployment'; + return 'be_simple_deployment'; } } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 03665cc..b84b600 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -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 @@ -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); @@ -26,10 +26,10 @@ public function getConfigTree() return $treeBuilder->buildTree(); } - protected function addRsyncSection(NodeBuilder $node) + protected function addRsyncSection(ArrayNodeDefinition $node) { - $node - ->arrayNode('rsync') + $node->children() + ->arrayNode('rsync')->children() ->scalarNode('command')->defaultValue('rsync')->cannotBeEmpty()->end() ->booleanNode('delete')->defaultFalse()->end() ->scalarNode('options')->defaultValue('-Cva')->end() @@ -38,10 +38,10 @@ protected function addRsyncSection(NodeBuilder $node) ; } - protected function addSshSection(NodeBuilder $node) + protected function addSshSection(ArrayNodeDefinition $node) { - $node - ->arrayNode('rsync') + $node->children() + ->arrayNode('rsync')->children() ->scalarNode('pubkey_file')->defaultNull()->end() ->scalarNode('privkey_file')->defaultNull()->end() ->scalarNode('passpharse')->defaultNull()->end() @@ -49,12 +49,12 @@ protected function addSshSection(NodeBuilder $node) ; } - protected function addRulesSection(NodeBuilder $node) + protected function addRulesSection(ArrayNodeDefinition $node) { - $node + $node->children() ->arrayNode('rules') ->useAttributeAsKey('name') - ->prototype('array') + ->prototype('array')->children() ->arrayNode('ignore')->defaultValue(array())->end() ->arrayNode('force')->defaultValue(array())->end() ->end() @@ -62,27 +62,28 @@ protected function addRulesSection(NodeBuilder $node) ; } - 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() + ->arrayNode('type')->defaultValue('symfony')->end() + ->arrayNode('command')->isRequired()->cannotBeEmpty()->end() + ->arrayNode('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() @@ -95,4 +96,4 @@ protected function addServersSection(NodeBuilder $node) ->end() ; } -} \ No newline at end of file +} diff --git a/Resources/config/deployment.xml b/Resources/config/deployment.xml index bd69415..1e0bfd9 100755 --- a/Resources/config/deployment.xml +++ b/Resources/config/deployment.xml @@ -5,42 +5,42 @@ xsi:schemaLocation="http://www.symfony-project.org/schema/dic/services http://www.symfony-project.org/schema/dic/services/services-1.0.xsd"> - BeSimple\DeploymentBundle\Deployer\Rsync - BeSimple\DeploymentBundle\Deployer\Ssh - BeSimple\DeploymentBundle\Deployer\Config - BeSimple\DeploymentBundle\Deployer\Logger - BeSimple\DeploymentBundle\Deployer\Deployer + BeSimple\DeploymentBundle\Deployer\Rsync + BeSimple\DeploymentBundle\Deployer\Ssh + BeSimple\DeploymentBundle\Deployer\Config + BeSimple\DeploymentBundle\Deployer\Logger + BeSimple\DeploymentBundle\Deployer\Deployer - - + + - %besimple_deployment.config.rsync% + %be_simple_deployment.config.rsync% - - + + - %besimple_deployment.config.ssh% + %be_simple_deployment.config.ssh% - - %besimple_deployment.config.rules% - %besimple_deployment.config.commands% - %besimple_deployment.config.servers% + + %be_simple_deployment.config.rules% + %be_simple_deployment.config.commands% + %be_simple_deployment.config.servers% - + - - - + + + - \ No newline at end of file + From 16c7944e7b05f9dcf1fa5f1bdd463c09ac25fe63 Mon Sep 17 00:00:00 2001 From: Jonas Wouters Date: Thu, 21 Apr 2011 13:15:55 +0200 Subject: [PATCH 06/14] Extra ignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f9d5fb1..f1d68ca 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.*.un~ \ No newline at end of file +.*.un~ +.*.swp \ No newline at end of file From 2947daa88717a54e42c0c457eb707bed9ff5bf57 Mon Sep 17 00:00:00 2001 From: Jonas Wouters Date: Thu, 21 Apr 2011 13:52:11 +0200 Subject: [PATCH 07/14] Fixed configuration parser --- .../BeSimpleDeploymentExtension.php | 1 + DependencyInjection/Configuration.php | 32 ++++++++++--------- Resources/config/deployment.xml | 4 +-- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/DependencyInjection/BeSimpleDeploymentExtension.php b/DependencyInjection/BeSimpleDeploymentExtension.php index 8372b1d..974f64b 100755 --- a/DependencyInjection/BeSimpleDeploymentExtension.php +++ b/DependencyInjection/BeSimpleDeploymentExtension.php @@ -6,6 +6,7 @@ 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 { diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index b84b600..ca71fdc 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -29,22 +29,24 @@ public function getConfigTree() protected function addRsyncSection(ArrayNodeDefinition $node) { $node->children() - ->arrayNode('rsync')->children() - ->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() + ->arrayNode('rsync') + ->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(ArrayNodeDefinition $node) { $node->children() - ->arrayNode('rsync')->children() + ->arrayNode('ssh')->children() ->scalarNode('pubkey_file')->defaultNull()->end() ->scalarNode('privkey_file')->defaultNull()->end() - ->scalarNode('passpharse')->defaultNull()->end() + ->scalarNode('passphrase')->defaultNull()->end() ->end() ; } @@ -55,8 +57,8 @@ protected function addRulesSection(ArrayNodeDefinition $node) ->arrayNode('rules') ->useAttributeAsKey('name') ->prototype('array')->children() - ->arrayNode('ignore')->defaultValue(array())->end() - ->arrayNode('force')->defaultValue(array())->end() + ->arrayNode('ignore')->defaultValue(array())->ignoreExtraKeys()->end() + ->arrayNode('force')->defaultValue(array())->ignoreExtraKeys()->end() ->end() ->end() ; @@ -71,9 +73,9 @@ protected function addCommandsSection(ArrayNodeDefinition $node) ->scalarNode('command')->defaultValue('./app/console')->cannotBeEmpty()->end() ->end() ->prototype('array')->children() - ->arrayNode('type')->defaultValue('symfony')->end() - ->arrayNode('command')->isRequired()->cannotBeEmpty()->end() - ->arrayNode('env')->defaultNull()->end() + ->scalarNode('type')->defaultValue('symfony')->end() + ->scalarNode('command')->isRequired()->cannotBeEmpty()->end() + ->scalarNode('env')->defaultNull()->end() ->end() ; } @@ -90,8 +92,8 @@ protected function addServersSection(ArrayNodeDefinition $node) ->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() ; diff --git a/Resources/config/deployment.xml b/Resources/config/deployment.xml index 1e0bfd9..eec4699 100755 --- a/Resources/config/deployment.xml +++ b/Resources/config/deployment.xml @@ -1,8 +1,8 @@ - + xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> BeSimple\DeploymentBundle\Deployer\Rsync From 1b75ff376c334023d37583c5be82f97c012824a2 Mon Sep 17 00:00:00 2001 From: Jonas Wouters Date: Thu, 21 Apr 2011 13:55:37 +0200 Subject: [PATCH 08/14] Fixed commands --- Command/DeploymentCommand.php | 4 ++-- Command/LaunchDeploymentCommand.php | 2 +- Command/TestDeploymentCommand.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Command/DeploymentCommand.php b/Command/DeploymentCommand.php index 147c8a4..9c0aa91 100644 --- a/Command/DeploymentCommand.php +++ b/Command/DeploymentCommand.php @@ -9,9 +9,9 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\Output; -use Symfony\Component\Console\Command\Command; +use Symfony\Bundle\FrameworkBundle\Command\Command as BaseCommand; -abstract class DeploymentCommand extends Command +abstract class DeploymentCommand extends BaseCommand { protected function configure() { diff --git a/Command/LaunchDeploymentCommand.php b/Command/LaunchDeploymentCommand.php index 9d3df25..c676522 100644 --- a/Command/LaunchDeploymentCommand.php +++ b/Command/LaunchDeploymentCommand.php @@ -5,7 +5,7 @@ use Bundle\DeploymentBundle\Deployer\Deployer; use Symfony\Component\Console\Command\Command; -abstract class LaunchDeploymentCommand extends DeploymentCommand +class LaunchDeploymentCommand extends DeploymentCommand { protected function configure() { diff --git a/Command/TestDeploymentCommand.php b/Command/TestDeploymentCommand.php index e1d059a..2f7db44 100644 --- a/Command/TestDeploymentCommand.php +++ b/Command/TestDeploymentCommand.php @@ -5,7 +5,7 @@ use Bundle\DeploymentBundle\Deployer\Deployer; use Symfony\Component\Console\Command\Command; -abstract class TestDeploymentCommand extends DeploymentCommand +class TestDeploymentCommand extends DeploymentCommand { protected function configure() { From 377a2275594a70f9e43e3f78e1d2e3fa8b2529e1 Mon Sep 17 00:00:00 2001 From: Jonas Wouters Date: Thu, 21 Apr 2011 15:02:16 +0200 Subject: [PATCH 09/14] Fixed config of services --- Command/DeploymentCommand.php | 10 +++++----- Command/LaunchDeploymentCommand.php | 2 +- Command/TestDeploymentCommand.php | 2 +- Resources/config/deployment.xml | 3 ++- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Command/DeploymentCommand.php b/Command/DeploymentCommand.php index 9c0aa91..9b5e08a 100644 --- a/Command/DeploymentCommand.php +++ b/Command/DeploymentCommand.php @@ -3,7 +3,7 @@ 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; @@ -33,12 +33,12 @@ protected function execute(InputInterface $input, OutputInterface $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'); }); + $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'); }); + $eventDispatcher->addListener('besimple_deployment.rsync', function ($event) use ($that) { $that->write($event, 'rsync'); }); } // TODO: add SSH events diff --git a/Command/LaunchDeploymentCommand.php b/Command/LaunchDeploymentCommand.php index c676522..86ed521 100644 --- a/Command/LaunchDeploymentCommand.php +++ b/Command/LaunchDeploymentCommand.php @@ -2,7 +2,7 @@ namespace BeSimple\DeploymentBundle\Command; -use Bundle\DeploymentBundle\Deployer\Deployer; +use BeSimple\DeploymentBundle\Deployer\Deployer; use Symfony\Component\Console\Command\Command; class LaunchDeploymentCommand extends DeploymentCommand diff --git a/Command/TestDeploymentCommand.php b/Command/TestDeploymentCommand.php index 2f7db44..71e816e 100644 --- a/Command/TestDeploymentCommand.php +++ b/Command/TestDeploymentCommand.php @@ -2,7 +2,7 @@ namespace BeSimple\DeploymentBundle\Command; -use Bundle\DeploymentBundle\Deployer\Deployer; +use BeSimple\DeploymentBundle\Deployer\Deployer; use Symfony\Component\Console\Command\Command; class TestDeploymentCommand extends DeploymentCommand diff --git a/Resources/config/deployment.xml b/Resources/config/deployment.xml index eec4699..b02faa7 100755 --- a/Resources/config/deployment.xml +++ b/Resources/config/deployment.xml @@ -22,7 +22,7 @@ - + %be_simple_deployment.config.ssh% @@ -38,6 +38,7 @@ + From 0ca7d7a5033757783b477155a4b27c348eb2b04a Mon Sep 17 00:00:00 2001 From: Jonas Wouters Date: Fri, 22 Apr 2011 10:42:56 +0200 Subject: [PATCH 10/14] Disabled events (for now) --- Command/DeploymentCommand.php | 20 ++++++++++---------- Deployer/Config.php | 28 ++++++++++++++-------------- Deployer/Deployer.php | 15 ++++++++------- Deployer/Rsync.php | 6 +++--- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/Command/DeploymentCommand.php b/Command/DeploymentCommand.php index 9b5e08a..1463538 100644 --- a/Command/DeploymentCommand.php +++ b/Command/DeploymentCommand.php @@ -26,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) { - $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_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) { - $eventDispatcher->addListener('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')); } diff --git a/Deployer/Config.php b/Deployer/Config.php index 019c465..f6774c5 100755 --- a/Deployer/Config.php +++ b/Deployer/Config.php @@ -1,6 +1,6 @@ rules = $rules; $this->commands = $commands; $this->servers = $servers; - $this->config = $config; + $this->config = array(); } public function getServerNames() @@ -22,17 +22,17 @@ 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($this->servers[$server]), + 'rules' => $this->getRulesConfig($this->servers[$server]), + 'commands' => $this->getCommandsConfig($this->servers[$server]), ); } @@ -41,7 +41,7 @@ public function getSeverConfig($name) protected function getConnectionConfig($server) { - $config = $this->server[$server]; + $config = $this->servers[$server]; unset($config['rules'], $config['commands']); return $config; @@ -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)); } @@ -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)); } @@ -83,4 +83,4 @@ protected function getCommandsConfig($server) return $config; } -} \ No newline at end of file +} diff --git a/Deployer/Deployer.php b/Deployer/Deployer.php index efc7315..20d01ec 100755 --- a/Deployer/Deployer.php +++ b/Deployer/Deployer.php @@ -1,8 +1,8 @@ rsync = $rsync; $this->ssh = $ssh; @@ -48,14 +48,15 @@ protected function call($server = null, $real = false) } catch(\Exception $e) { - $this->dispatchEvent('error', array('server' => $server, 'method' => $method, 'exception' => $e)); + throw $e; + //$this->dispatchEvent('error', array('server' => $server, 'method' => $method, 'exception' => $e)); } - $this->dispatchEvent('success', array('server' => $server, 'real' => $real, 'rsync' => $rsync, 'ssh' => $ssh)); + //$this->dispatchEvent('success', array('server' => $server, 'real' => $real, 'rsync' => $rsync, 'ssh' => $ssh)); } protected function dispatchEvent($name, array $parameters) { - $this->eventDispatcher->notify(new Event($this, 'besimple_deployment.'.$name, $parameters)); + //$this->eventDispatcher->notify(new Event($this, 'besimple_deployment.'.$name, $parameters)); } -} \ No newline at end of file +} diff --git a/Deployer/Rsync.php b/Deployer/Rsync.php index d1ae654..7920401 100644 --- a/Deployer/Rsync.php +++ b/Deployer/Rsync.php @@ -2,7 +2,7 @@ namespace BeSimple\DeploymentBundle\Deployer; -use Symfony\Bundle\FrameworkBundle\EventDispatcher; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\Event; use Symfony\Component\Process\Process; @@ -15,7 +15,7 @@ class Rsync protected $stdout; protected $callback; - public function __construct(Logger $logger, EventDispatcher $eventDispatcher, array $config) + public function __construct(Logger $logger, EventDispatcherInterface $eventDispatcher, array $config) { $this->logger = $logger; $this->eventDispatcher = $eventDispatcher; @@ -106,4 +106,4 @@ protected function buildCommand(array $connection, array $rules, $real = false) return sprintf('%s -e ssh %s %s %s', $this->config['command'], implode(' ', $options), $source, $detination); } -} \ No newline at end of file +} From a790dcec1baabd98481af9c7bc57fd30aeb9f658 Mon Sep 17 00:00:00 2001 From: Jonas Wouters Date: Fri, 22 Apr 2011 10:43:16 +0200 Subject: [PATCH 11/14] Fixed config parameter --- Deployer/Ssh.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Deployer/Ssh.php b/Deployer/Ssh.php index 0ce7b63..1b645b9 100644 --- a/Deployer/Ssh.php +++ b/Deployer/Ssh.php @@ -2,19 +2,21 @@ namespace BeSimple\DeploymentBundle\Deployer; +use Symfony\Component\DependencyInjection\ContainerInterface; + class Ssh { protected $logger; - protected $config; + protected $container; protected $session; protected $shell; protected $stdout; protected $stderr; - public function __construct(Logger $logger, array $config) + public function __construct(Logger $logger, ContainerInterface $container) { $this->logger = $logger; - $this->config = $config; + $this->container = $container; $this->session = null; $this->stdout = array(); $this->stdin = array(); @@ -72,7 +74,7 @@ protected function connect(array $connection) } } - $this->shell = ssh2_shell($this->session, $this->config['shell']); + $this->shell = ssh2_shell($this->session, $this->container->getParameter('be_simple_deployment.ssh.shell')); if (!$this->shell) { throw new \RuntimeException(sprintf('Failed opening "%s" shell', $this->config['shell'])); @@ -120,4 +122,4 @@ protected function buildCommand(array $command) return sprintf('%s %s --env="%s"', $symfony, $command['command'], $env); } -} \ No newline at end of file +} From 8db95cee2c8e27b4f6976f11020b21d109838172 Mon Sep 17 00:00:00 2001 From: Jonas Wouters Date: Fri, 22 Apr 2011 11:53:01 +0200 Subject: [PATCH 12/14] Fixed rsync --- Deployer/Config.php | 8 ++++---- Deployer/Rsync.php | 18 ++++++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Deployer/Config.php b/Deployer/Config.php index f6774c5..1255011 100755 --- a/Deployer/Config.php +++ b/Deployer/Config.php @@ -30,13 +30,13 @@ public function getServerConfig($server) if (!isset($this->config[$server])) { $this->config[$server] = array( - 'connection' => $this->getConnectionConfig($this->servers[$server]), - 'rules' => $this->getRulesConfig($this->servers[$server]), - 'commands' => $this->getCommandsConfig($this->servers[$server]), + 'connection' => $this->getConnectionConfig($server), + 'rules' => $this->getRulesConfig($server), + 'commands' => $this->getCommandsConfig($server), ); } - return $this->config[$name]; + return $this->config[$server]; } protected function getConnectionConfig($server) diff --git a/Deployer/Rsync.php b/Deployer/Rsync.php index 7920401..d4bdbbe 100644 --- a/Deployer/Rsync.php +++ b/Deployer/Rsync.php @@ -52,7 +52,8 @@ public function run(array $connection, array $rules, $real = false) } $command = $this->buildCommand($connection, $rules, $real); - $process = new Process($commant, $root); + echo $command; + $process = new Process($command, $root); $this->stderr = array(); $this->stdout = array(); @@ -60,7 +61,7 @@ public function run(array $connection, array $rules, $real = false) $code = $process->run(array($this, 'onStdLine')); if ($code !== 0) { - throw new \RuntimeErrorException($this->stderr, $process->getExitCode()); + throw new \Exception($this->stderr, $process->getExitCode()); } return $this->stdout; @@ -74,7 +75,7 @@ public function onStdLine($type, $line) $this->stderr = $line; } - $this->eventDispatcher->notify(new Event($this, 'besimple_deployer.rsync', array('line' => $line, 'type' => $type))); + //$this->eventDispatcher->notify(new Event($this, 'besimple_deployer.rsync', array('line' => $line, 'type' => $type))); } protected function buildCommand(array $connection, array $rules, $real = false) @@ -82,18 +83,19 @@ protected function buildCommand(array $connection, array $rules, $real = false) $source = '.'; $user = $connection['username'] ? $connection['username'].'@' : ''; $destination = sprintf('%s%s:%s', $user, $connection['host'], $connection['path']); - $options = $this->config['options']; + $options = array(); + $options[] = $this->config['options']; - if ($connection['port']) { + if (!empty($connection['port'])) { $options[] = '-p '.$connection['port']; } - if ($this->options['delete']) { + if ($this->config['delete']) { $options[] = '--delete'; } if (count($rules)) { - $options[] = '-f +*'; + $options[] = "--filter='+ *'"; foreach ($rules['ignore'] as $mask) { $options[] = sprintf('-f -%s', $mask); @@ -104,6 +106,6 @@ protected function buildCommand(array $connection, array $rules, $real = false) } } - return sprintf('%s -e ssh %s %s %s', $this->config['command'], implode(' ', $options), $source, $detination); + return sprintf('%s -e ssh %s %s %s', $this->config['command'], implode(' ', $options), $source, $destination); } } From 4d2417a0f183bdac89ced8c22274e327f0cb335d Mon Sep 17 00:00:00 2001 From: Jonas Wouters Date: Fri, 22 Apr 2011 11:53:15 +0200 Subject: [PATCH 13/14] Unknown parameter removed --- Deployer/Ssh.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Deployer/Ssh.php b/Deployer/Ssh.php index 1b645b9..70168f4 100644 --- a/Deployer/Ssh.php +++ b/Deployer/Ssh.php @@ -74,7 +74,7 @@ protected function connect(array $connection) } } - $this->shell = ssh2_shell($this->session, $this->container->getParameter('be_simple_deployment.ssh.shell')); + $this->shell = ssh2_shell($this->session); if (!$this->shell) { throw new \RuntimeException(sprintf('Failed opening "%s" shell', $this->config['shell'])); From 5030d3aba64aab43608e959fbb31b2ee57301801 Mon Sep 17 00:00:00 2001 From: Jonas Wouters Date: Tue, 26 Apr 2011 10:35:58 +0200 Subject: [PATCH 14/14] Fixed ssh. --- Deployer/Ssh.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Deployer/Ssh.php b/Deployer/Ssh.php index 70168f4..37106cd 100644 --- a/Deployer/Ssh.php +++ b/Deployer/Ssh.php @@ -20,6 +20,7 @@ public function __construct(Logger $logger, ContainerInterface $container) $this->session = null; $this->stdout = array(); $this->stdin = array(); + $this->stderr = array(); } public function getStdout($glue = "\n") @@ -43,7 +44,7 @@ public function getStderr($glue = "\n") public function run(array $connection, array $commands, $real = false) { $this->connect($connection); - $this->execute(sprintf('cd %s', $connection['path'])); + $this->execute(array('type' => 'shell', 'command' => sprintf('cd %s', $connection['path']))); if ($real) { foreach ($commands as $command) { @@ -64,7 +65,7 @@ protected function connect(array $connection) throw new \InvalidArgumentException(sprintf('SSH connection failed on "%s:%s"', $connection['host'], $connection['ssh_port'])); } - if ($connection['username'] && $connection['pubkey_file'] && $connection['privkey_file']) { + if (isset($connection['username']) && isset($connection['pubkey_file']) && isset($connection['privkey_file'])) { if (!ssh2_auth_pubkey_file($connection['username'], $connection['pubkey_file'], $connection['privkey_file'], $connection['passphrase'])) { throw new \InvalidArgumentException(sprintf('SSH authentication failed for user "%s" with public key "%s"', $connection['username'], $connection['pubkey_file'])); } @@ -93,8 +94,8 @@ protected function execute(array $command) { $command = $this->buildCommand($command); - $outStream = ssh2_exec($connection, $command); - $errStream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR); + $outStream = ssh2_exec($this->session, $command); + $errStream = ssh2_fetch_stream($outStream, SSH2_STREAM_STDERR); stream_set_blocking($outStream, true); stream_set_blocking($errStream, true); @@ -102,10 +103,12 @@ protected function execute(array $command) $stdout = explode("\n", stream_get_contents($outStream)); $stderr = explode("\n", stream_get_contents($errStream)); - $this->dispatch('command', array('stdout' => stdout, 'stderr' => $stderr)); + //$this->dispatch('command', array('stdout' => stdout, 'stderr' => $stderr)); $this->stdout = array_merge($this->stdout, $stdout); - $this->stderr = array_merge($this->stderr, $stderr); + if (is_array($stderr)) { + $this->stderr = array_merge($this->stderr, $stderr); + } fclose($outStream); fclose($errStream);