From 1c6c965a28da2554e3b43c68063a77b595049f66 Mon Sep 17 00:00:00 2001 From: Maxime Fabre Date: Fri, 16 Aug 2013 13:54:55 +0200 Subject: [PATCH 01/20] Fix some indentations --- docs | 2 +- .../Commands/DeployDeployCommand.php | 26 +++++++++---------- .../Commands/DeployUpdateCommand.php | 24 ++++++++--------- src/Rocketeer/RocketeerServiceProvider.php | 23 ++++++---------- src/Rocketeer/Tasks/Ignite.php | 2 +- tests/ConsoleTest.php | 2 +- tests/Tasks/CheckTest.php | 2 +- tests/Tasks/CleanupTest.php | 2 +- tests/Tasks/CurrentReleaseTest.php | 2 +- tests/Tasks/DeployTest.php | 2 +- tests/Tasks/IgniteTest.php | 2 +- tests/Tasks/RollbackTest.php | 2 +- tests/Tasks/SetupTest.php | 2 +- tests/Tasks/TeardownTest.php | 2 +- tests/Tasks/TestTest.php | 2 +- tests/Tasks/UpdateTest.php | 2 +- tests/TasksQueueTest.php | 2 +- 17 files changed, 47 insertions(+), 54 deletions(-) diff --git a/docs b/docs index 396795da7..542031cd6 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 396795da7bb89ccef3ddd1ebfa8a1be39059f68c +Subproject commit 542031cd6731e8e4aeb602aee7d694defb3a62ce diff --git a/src/Rocketeer/Commands/DeployDeployCommand.php b/src/Rocketeer/Commands/DeployDeployCommand.php index de6176e75..5bd49a010 100644 --- a/src/Rocketeer/Commands/DeployDeployCommand.php +++ b/src/Rocketeer/Commands/DeployDeployCommand.php @@ -35,17 +35,17 @@ public function fire() )); } - /** - * Get the console command options. - * - * @return array - */ - protected function getOptions() - { - return array_merge(parent::getOptions(), array( - array('tests', 't', InputOption::VALUE_NONE, 'Runs the tests on deploy'), - array('migrate', 'm', InputOption::VALUE_NONE, 'Run the migrations'), - array('seed', 's', InputOption::VALUE_NONE, 'Seed the database after migrating the database'), - )); - } + /** + * Get the console command options. + * + * @return array + */ + protected function getOptions() + { + return array_merge(parent::getOptions(), array( + array('tests', 't', InputOption::VALUE_NONE, 'Runs the tests on deploy'), + array('migrate', 'm', InputOption::VALUE_NONE, 'Run the migrations'), + array('seed', 's', InputOption::VALUE_NONE, 'Seed the database after migrating the database'), + )); + } } diff --git a/src/Rocketeer/Commands/DeployUpdateCommand.php b/src/Rocketeer/Commands/DeployUpdateCommand.php index a6647c1fd..71dda0396 100644 --- a/src/Rocketeer/Commands/DeployUpdateCommand.php +++ b/src/Rocketeer/Commands/DeployUpdateCommand.php @@ -32,16 +32,16 @@ public function fire() return $this->fireTasksQueue('Rocketeer\Tasks\Update'); } - /** - * Get the console command options. - * - * @return array - */ - protected function getOptions() - { - return array_merge(parent::getOptions(), array( - array('migrate', 'm', InputOption::VALUE_NONE, 'Run the migrations'), - array('seed', 's', InputOption::VALUE_NONE, 'Seed the database after migrating the database'), - )); - } + /** + * Get the console command options. + * + * @return array + */ + protected function getOptions() + { + return array_merge(parent::getOptions(), array( + array('migrate', 'm', InputOption::VALUE_NONE, 'Run the migrations'), + array('seed', 's', InputOption::VALUE_NONE, 'Seed the database after migrating the database'), + )); + } } diff --git a/src/Rocketeer/RocketeerServiceProvider.php b/src/Rocketeer/RocketeerServiceProvider.php index 53797c306..22ea765f4 100644 --- a/src/Rocketeer/RocketeerServiceProvider.php +++ b/src/Rocketeer/RocketeerServiceProvider.php @@ -18,13 +18,6 @@ */ class RocketeerServiceProvider extends ServiceProvider { - /** - * Indicates if loading of the provider is deferred. - * - * @var bool - */ - protected $defer = false; - /** * The commands to register * @@ -98,17 +91,17 @@ public static function make($app = null) */ public function bindCoreClasses(Container $app) { - $app->bindIf('files', 'Illuminate\Filesystem\Filesystem'); + $app->bindIf('files', 'Illuminate\Filesystem\Filesystem'); - $app->bindIf('request', function ($app) { - return Request::createFromGlobals(); - }, true); + $app->bindIf('request', function ($app) { + return Request::createFromGlobals(); + }, true); - $app->bindIf('config', function ($app) { + $app->bindIf('config', function ($app) { $fileloader = new FileLoader($app['files'], __DIR__.'/../config'); return new Repository($fileloader, 'config'); - }, true); + }, true); $app->bindIf('remote', function($app) { return new RemoteManager($app); @@ -117,7 +110,7 @@ public function bindCoreClasses(Container $app) // Register factory and custom configurations $app = $this->registerConfig($app); - return $app; + return $app; } /** @@ -270,7 +263,7 @@ protected function registerConfig(Container $app) $app['path.base'] = $base[0]; } - // Register config file + // Register config file $app['config']->package('anahkiasen/rocketeer', __DIR__.'/../config'); // Register custom config diff --git a/src/Rocketeer/Tasks/Ignite.php b/src/Rocketeer/Tasks/Ignite.php index 99098bb45..951d3dfbe 100644 --- a/src/Rocketeer/Tasks/Ignite.php +++ b/src/Rocketeer/Tasks/Ignite.php @@ -38,4 +38,4 @@ public function execute() return $this->history; } -} \ No newline at end of file +} diff --git a/tests/ConsoleTest.php b/tests/ConsoleTest.php index e8d6d8408..9e9e0f7ae 100644 --- a/tests/ConsoleTest.php +++ b/tests/ConsoleTest.php @@ -7,4 +7,4 @@ public function testCanRunStandaloneConsole() $this->assertContains('Rocketeer version 0', $console); } -} \ No newline at end of file +} diff --git a/tests/Tasks/CheckTest.php b/tests/Tasks/CheckTest.php index e5bdd06ca..d795bb5fe 100644 --- a/tests/Tasks/CheckTest.php +++ b/tests/Tasks/CheckTest.php @@ -7,4 +7,4 @@ public function testCanPretendToCheck() $task = $this->pretendTask('Check'); $task->execute(); } -} \ No newline at end of file +} diff --git a/tests/Tasks/CleanupTest.php b/tests/Tasks/CleanupTest.php index 4a769fa66..966225ff1 100644 --- a/tests/Tasks/CleanupTest.php +++ b/tests/Tasks/CleanupTest.php @@ -13,4 +13,4 @@ public function testCanCleanupServer() $output = $cleanup->execute(); $this->assertEquals('No releases to prune from the server', $output); } -} \ No newline at end of file +} diff --git a/tests/Tasks/CurrentReleaseTest.php b/tests/Tasks/CurrentReleaseTest.php index 39ec1391e..18de26fb8 100644 --- a/tests/Tasks/CurrentReleaseTest.php +++ b/tests/Tasks/CurrentReleaseTest.php @@ -11,4 +11,4 @@ public function testCanGetCurrentRelease() $current = $this->task('CurrentRelease')->execute(); $this->assertEquals('No release has yet been deployed', $current); } -} \ No newline at end of file +} diff --git a/tests/Tasks/DeployTest.php b/tests/Tasks/DeployTest.php index 453eb9d0f..b9805fc35 100644 --- a/tests/Tasks/DeployTest.php +++ b/tests/Tasks/DeployTest.php @@ -21,4 +21,4 @@ public function testCanDeployToServer() $this->recreateVirtualServer(); } -} \ No newline at end of file +} diff --git a/tests/Tasks/IgniteTest.php b/tests/Tasks/IgniteTest.php index 27eb1bbf7..3df3ec627 100644 --- a/tests/Tasks/IgniteTest.php +++ b/tests/Tasks/IgniteTest.php @@ -37,4 +37,4 @@ public function testCanIgniteConfigurationInLaravel() $contents = file_get_contents($root); $this->assertEquals('foobar', $contents); } -} \ No newline at end of file +} diff --git a/tests/Tasks/RollbackTest.php b/tests/Tasks/RollbackTest.php index 006d7ea80..dc0293e48 100644 --- a/tests/Tasks/RollbackTest.php +++ b/tests/Tasks/RollbackTest.php @@ -8,4 +8,4 @@ public function testCanRollbackRelease() $this->assertEquals(10000000000000, $this->app['rocketeer.releases']->getCurrentRelease()); } -} \ No newline at end of file +} diff --git a/tests/Tasks/SetupTest.php b/tests/Tasks/SetupTest.php index 13707dcfb..5c1f4488b 100644 --- a/tests/Tasks/SetupTest.php +++ b/tests/Tasks/SetupTest.php @@ -11,4 +11,4 @@ public function testCanSetupServer() $this->assertFileExists($this->server.'/current'); $this->assertFileExists($this->server.'/releases'); } -} \ No newline at end of file +} diff --git a/tests/Tasks/TeardownTest.php b/tests/Tasks/TeardownTest.php index cbd89738c..d00cd66d7 100644 --- a/tests/Tasks/TeardownTest.php +++ b/tests/Tasks/TeardownTest.php @@ -20,4 +20,4 @@ public function testCanAbortTeardown() $this->assertEquals('Teardown aborted', $message); } -} \ No newline at end of file +} diff --git a/tests/Tasks/TestTest.php b/tests/Tasks/TestTest.php index 2c237d416..382bebb58 100644 --- a/tests/Tasks/TestTest.php +++ b/tests/Tasks/TestTest.php @@ -8,4 +8,4 @@ public function testCanRunTests() $this->assertEquals('cd '.$this->server.'/releases/20000000000000', $tests[0]); $this->assertContains('phpunit --stop-on-failure', $tests[1]); } -} \ No newline at end of file +} diff --git a/tests/Tasks/UpdateTest.php b/tests/Tasks/UpdateTest.php index 67a85a8b9..e2521abb2 100644 --- a/tests/Tasks/UpdateTest.php +++ b/tests/Tasks/UpdateTest.php @@ -41,4 +41,4 @@ public function testCanUpdateRepository() $this->assertEquals($matcher, $update); } -} \ No newline at end of file +} diff --git a/tests/TasksQueueTest.php b/tests/TasksQueueTest.php index 6811773f7..5512bbff8 100644 --- a/tests/TasksQueueTest.php +++ b/tests/TasksQueueTest.php @@ -143,7 +143,7 @@ function ($task) { public function testCanRunQueue() { - $this->expectOutputString('JOEY DOESNT SHARE FOOD'); + $this->expectOutputString('JOEY DOESNT SHARE FOOD'); $this->tasksQueue()->run(array( function ($task) { print 'JOEY DOESNT SHARE FOOD'; From ac33e569601e8719fdf234f01b223eb715bff490 Mon Sep 17 00:00:00 2001 From: Maxime Fabre Date: Sun, 18 Aug 2013 20:54:47 +0200 Subject: [PATCH 02/20] Fix Rocketeer overwriting storage path --- composer.lock | 28 +++++++--------------- src/Rocketeer/RocketeerServiceProvider.php | 5 ++-- tests/meta/coverage.txt | 2 +- 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/composer.lock b/composer.lock index bc69f1984..6c274d595 100644 --- a/composer.lock +++ b/composer.lock @@ -46,9 +46,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com", - "homepage": "https://github.com/taylorotwell", - "role": "Developer" + "email": "taylorotwell@gmail.com" } ], "time": "2013-08-10 17:47:18" @@ -92,9 +90,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com", - "homepage": "https://github.com/taylorotwell", - "role": "Developer" + "email": "taylorotwell@gmail.com" } ], "time": "2013-07-19 10:47:48" @@ -138,9 +134,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com", - "homepage": "https://github.com/taylorotwell", - "role": "Developer" + "email": "taylorotwell@gmail.com" } ], "time": "2013-07-31 15:34:38" @@ -186,9 +180,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com", - "homepage": "https://github.com/taylorotwell", - "role": "Developer" + "email": "taylorotwell@gmail.com" } ], "time": "2013-07-02 17:46:50" @@ -237,9 +229,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com", - "homepage": "https://github.com/taylorotwell", - "role": "Developer" + "email": "taylorotwell@gmail.com" } ], "time": "2013-08-05 13:28:56" @@ -251,12 +241,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/Console.git", - "reference": "v2.3.3" + "reference": "db78f8ff7fc9e28d25ff9a0bf6ddf9f0e35fbbe3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Console/zipball/v2.3.3", - "reference": "v2.3.3", + "url": "https://api.github.com/repos/symfony/Console/zipball/db78f8ff7fc9e28d25ff9a0bf6ddf9f0e35fbbe3", + "reference": "db78f8ff7fc9e28d25ff9a0bf6ddf9f0e35fbbe3", "shasum": "" }, "require": { @@ -295,7 +285,7 @@ ], "description": "Symfony Console Component", "homepage": "http://symfony.com", - "time": "2013-07-21 12:12:18" + "time": "2013-08-17 16:34:49" }, { "name": "symfony/finder", diff --git a/src/Rocketeer/RocketeerServiceProvider.php b/src/Rocketeer/RocketeerServiceProvider.php index 22ea765f4..6bbfb6df9 100644 --- a/src/Rocketeer/RocketeerServiceProvider.php +++ b/src/Rocketeer/RocketeerServiceProvider.php @@ -258,9 +258,8 @@ public function bindCommands(Container $app) protected function registerConfig(Container $app) { // Register paths - if (!isset($app['path.base'])) { - $base = explode('/vendor', __DIR__); - $app['path.base'] = $base[0]; + if (!$app->bound('path.base')) { + $app['path.base'] = realpath(__DIR__.'/../../../'); } // Register config file diff --git a/tests/meta/coverage.txt b/tests/meta/coverage.txt index 6d68366fd..4cf508f16 100644 --- a/tests/meta/coverage.txt +++ b/tests/meta/coverage.txt @@ -1,7 +1,7 @@ Code Coverage Report: - 2013-08-16 13:29:09 + 2013-08-18 21:08:47 Summary: Classes: 63.16% (12/19) From cf12c2ef2b56451fa082b7aaa8d00e675f465763 Mon Sep 17 00:00:00 2001 From: Maxime Fabre Date: Thu, 19 Sep 2013 12:00:11 +0200 Subject: [PATCH 03/20] Added to clear Rocketeer's cache of credentials --- CHANGELOG.md | 4 ++ composer.lock | 62 +++++++++++-------- src/Rocketeer/Commands/DeployFlushCommand.php | 33 ++++++++++ src/Rocketeer/RocketeerServiceProvider.php | 13 ++-- tests/meta/coverage.txt | 6 +- 5 files changed, 83 insertions(+), 35 deletions(-) create mode 100644 src/Rocketeer/Commands/DeployFlushCommand.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fa5587cd..4f88bbe9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ### Changelog +### 0.7.1 (develop) + +- Added `deploy:flush` to clear Rocketeer's cache of credentials + ### 0.7.0 (stable) - **Rocketeer can now work outside of Laravel** diff --git a/composer.lock b/composer.lock index 6c274d595..53e258ebc 100644 --- a/composer.lock +++ b/composer.lock @@ -102,12 +102,12 @@ "source": { "type": "git", "url": "https://github.com/illuminate/container.git", - "reference": "b9ecfb12b5d45f06e6eb0c9db82fcde6cb5c705e" + "reference": "0d827306eebba40483c185b56f9996fd0b9e842c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/container/zipball/b9ecfb12b5d45f06e6eb0c9db82fcde6cb5c705e", - "reference": "b9ecfb12b5d45f06e6eb0c9db82fcde6cb5c705e", + "url": "https://api.github.com/repos/illuminate/container/zipball/0d827306eebba40483c185b56f9996fd0b9e842c", + "reference": "0d827306eebba40483c185b56f9996fd0b9e842c", "shasum": "" }, "require": { @@ -134,10 +134,12 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylorotwell@gmail.com", + "homepage": "https://github.com/taylorotwell", + "role": "Developer" } ], - "time": "2013-07-31 15:34:38" + "time": "2013-08-26 18:53:15" }, { "name": "illuminate/filesystem", @@ -192,12 +194,12 @@ "source": { "type": "git", "url": "https://github.com/illuminate/support.git", - "reference": "9507e57aa5b237993e2bdb82d8534fc89d5dac6c" + "reference": "9e61ed7335f457521b888fd405f16eda6f7caf02" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/support/zipball/9507e57aa5b237993e2bdb82d8534fc89d5dac6c", - "reference": "9507e57aa5b237993e2bdb82d8534fc89d5dac6c", + "url": "https://api.github.com/repos/illuminate/support/zipball/9e61ed7335f457521b888fd405f16eda6f7caf02", + "reference": "9e61ed7335f457521b888fd405f16eda6f7caf02", "shasum": "" }, "require": { @@ -229,10 +231,12 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylorotwell@gmail.com", + "homepage": "https://github.com/taylorotwell", + "role": "Developer" } ], - "time": "2013-08-05 13:28:56" + "time": "2013-09-06 05:21:45" }, { "name": "symfony/console", @@ -241,12 +245,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/Console.git", - "reference": "db78f8ff7fc9e28d25ff9a0bf6ddf9f0e35fbbe3" + "reference": "aba4731bf8dafa21b7c4a59bd69c62f73c0a6dcf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Console/zipball/db78f8ff7fc9e28d25ff9a0bf6ddf9f0e35fbbe3", - "reference": "db78f8ff7fc9e28d25ff9a0bf6ddf9f0e35fbbe3", + "url": "https://api.github.com/repos/symfony/Console/zipball/aba4731bf8dafa21b7c4a59bd69c62f73c0a6dcf", + "reference": "aba4731bf8dafa21b7c4a59bd69c62f73c0a6dcf", "shasum": "" }, "require": { @@ -285,7 +289,7 @@ ], "description": "Symfony Console Component", "homepage": "http://symfony.com", - "time": "2013-08-17 16:34:49" + "time": "2013-09-18 07:03:56" }, { "name": "symfony/finder", @@ -342,12 +346,12 @@ "source": { "type": "git", "url": "https://github.com/padraic/mockery.git", - "reference": "9d2460275665f4506d359f4e2037705d07833173" + "reference": "b6fe71cbc1909927b5574219ff6d50e3b264abdb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/padraic/mockery/zipball/9d2460275665f4506d359f4e2037705d07833173", - "reference": "9d2460275665f4506d359f4e2037705d07833173", + "url": "https://api.github.com/repos/padraic/mockery/zipball/b6fe71cbc1909927b5574219ff6d50e3b264abdb", + "reference": "b6fe71cbc1909927b5574219ff6d50e3b264abdb", "shasum": "" }, "require": { @@ -388,7 +392,7 @@ "test double", "testing" ], - "time": "2013-08-16 09:45:12" + "time": "2013-08-21 19:34:19" }, { "name": "nesbot/carbon", @@ -396,12 +400,12 @@ "source": { "type": "git", "url": "https://github.com/briannesbitt/Carbon.git", - "reference": "bfabf7c397090f594bf9ae01c7df5d5c9e045c76" + "reference": "06f0b8a99a90c5392ceccb09b75b74ff6c08ec07" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/bfabf7c397090f594bf9ae01c7df5d5c9e045c76", - "reference": "bfabf7c397090f594bf9ae01c7df5d5c9e045c76", + "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/06f0b8a99a90c5392ceccb09b75b74ff6c08ec07", + "reference": "06f0b8a99a90c5392ceccb09b75b74ff6c08ec07", "shasum": "" }, "require": { @@ -431,7 +435,7 @@ "datetime", "time" ], - "time": "2013-08-09 04:19:56" + "time": "2013-09-09 02:39:19" }, { "name": "patchwork/utf8", @@ -439,17 +443,23 @@ "source": { "type": "git", "url": "https://github.com/nicolas-grekas/Patchwork-UTF8.git", - "reference": "6c820a6fa0b4464a3d1ea0514937aae46f2e701c" + "reference": "e4bd68ca375d854615613e6b77003e08c1744c54" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nicolas-grekas/Patchwork-UTF8/zipball/6c820a6fa0b4464a3d1ea0514937aae46f2e701c", - "reference": "6c820a6fa0b4464a3d1ea0514937aae46f2e701c", + "url": "https://api.github.com/repos/nicolas-grekas/Patchwork-UTF8/zipball/e4bd68ca375d854615613e6b77003e08c1744c54", + "reference": "e4bd68ca375d854615613e6b77003e08c1744c54", "shasum": "" }, "require": { + "lib-pcre": "*", "php": ">=5.3.0" }, + "suggest": { + "ext-mbstring": "Use Mbstring for best performance", + "lib-iconv": "Use iconv for best performance", + "lib-icu": "Use Intl for best performance" + }, "type": "library", "autoload": { "psr-0": { @@ -476,7 +486,7 @@ "utf-8", "utf8" ], - "time": "2013-08-16 08:38:10" + "time": "2013-09-05 12:11:48" } ], "aliases": [ diff --git a/src/Rocketeer/Commands/DeployFlushCommand.php b/src/Rocketeer/Commands/DeployFlushCommand.php new file mode 100644 index 000000000..49900df71 --- /dev/null +++ b/src/Rocketeer/Commands/DeployFlushCommand.php @@ -0,0 +1,33 @@ +laravel['rocketeer.server']->deleteRepository(); + $this->info("Rocketeer's cache has been properly flushed"); + } +} diff --git a/src/Rocketeer/RocketeerServiceProvider.php b/src/Rocketeer/RocketeerServiceProvider.php index 6bbfb6df9..61bc23a15 100644 --- a/src/Rocketeer/RocketeerServiceProvider.php +++ b/src/Rocketeer/RocketeerServiceProvider.php @@ -183,16 +183,17 @@ public function bindCommands(Container $app) // Base commands $tasks = array( '' => '', - 'ignite' => 'Ignite', 'check' => 'Check', - 'setup' => 'Setup', - 'deploy' => 'Deploy', - 'update' => 'Update', - 'rollback' => 'Rollback', 'cleanup' => 'Cleanup', 'current' => 'CurrentRelease', - 'test' => 'Test', + 'deploy' => 'Deploy', + 'flush' => 'Flush', + 'ignite' => 'Ignite', + 'rollback' => 'Rollback', + 'setup' => 'Setup', 'teardown' => 'Teardown', + 'test' => 'Test', + 'update' => 'Update', ); // Add User commands diff --git a/tests/meta/coverage.txt b/tests/meta/coverage.txt index 4cf508f16..9176bea18 100644 --- a/tests/meta/coverage.txt +++ b/tests/meta/coverage.txt @@ -1,12 +1,12 @@ Code Coverage Report: - 2013-08-18 21:08:47 + 2013-09-19 12:00:54 Summary: Classes: 63.16% (12/19) Methods: 87.72% (100/114) - Lines: 90.05% (516/573) + Lines: 90.07% (517/574) \Rocketeer::Bash Methods: 88.24% (15/17) Lines: 93.07% ( 94/101) @@ -15,7 +15,7 @@ Code Coverage Report: \Rocketeer::Rocketeer Methods: 100.00% (15/15) Lines: 100.00% ( 50/ 50) \Rocketeer::Server - Methods: 90.00% ( 9/10) Lines: 90.24% ( 37/ 41) + Methods: 90.00% ( 9/10) Lines: 90.48% ( 38/ 42) \Rocketeer::TasksQueue Methods: 80.00% (12/15) Lines: 89.77% ( 79/ 88) \Rocketeer\Scm::Git From 5c679396b9e191ca9038e49c50554eb5f446c67c Mon Sep 17 00:00:00 2001 From: yusukezzz Date: Thu, 26 Sep 2013 02:09:13 +0900 Subject: [PATCH 04/20] fixed Anahkiasen/rocketeer#35 --- src/Rocketeer/Rocketeer.php | 8 +++++++- tests/ReleasesManagerTest.php | 2 +- tests/RocketeerTest.php | 2 +- tests/_start.php | 8 ++++---- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Rocketeer/Rocketeer.php b/src/Rocketeer/Rocketeer.php index 8dcbb0af8..6495ae698 100644 --- a/src/Rocketeer/Rocketeer.php +++ b/src/Rocketeer/Rocketeer.php @@ -3,6 +3,7 @@ use Illuminate\Container\Container; use Illuminate\Support\Str; +use \ReflectionException; /** * Handles interaction between the User provided informations @@ -211,7 +212,12 @@ public function replacePatterns($path) return preg_replace_callback('/\{[a-z\.]+\}/', function ($match) use ($app) { $folder = substr($match[0], 1, -1); - if (isset($app[$folder])) { + try { + $app_folder = $app[$folder]; + } catch(\ReflectionException $e) { + return false; + } + if (isset($app_folder)) { return str_replace($app['path.base'].'/', null, $app->make($folder)); } diff --git a/tests/ReleasesManagerTest.php b/tests/ReleasesManagerTest.php index cdbcb592a..2a08b29f8 100644 --- a/tests/ReleasesManagerTest.php +++ b/tests/ReleasesManagerTest.php @@ -56,6 +56,6 @@ public function testCanGetFolderInRelease() { $folder = $this->app['rocketeer.releases']->getCurrentReleasePath('{path.storage}'); - $this->assertEquals($this->server.'/releases/20000000000000/storage', $folder); + $this->assertEquals($this->server.'/releases/20000000000000/app/storage', $folder); } } diff --git a/tests/RocketeerTest.php b/tests/RocketeerTest.php index 6b6aa9213..ba77ab124 100644 --- a/tests/RocketeerTest.php +++ b/tests/RocketeerTest.php @@ -97,7 +97,7 @@ public function testCanReplacePatternsInFolders() { $folder = $this->app['rocketeer.rocketeer']->getFolder('{path.storage}'); - $this->assertEquals($this->server.'/storage', $folder); + $this->assertEquals($this->server.'/app/storage', $folder); } public function testCannotReplaceUnexistingPatternsInFolders() diff --git a/tests/_start.php b/tests/_start.php index 0a9c24eb3..6c9797aeb 100644 --- a/tests/_start.php +++ b/tests/_start.php @@ -52,10 +52,10 @@ public function setUp() // Laravel classes --------------------------------------------- / - $this->app['path.base'] = '/src'; - $this->app['path'] = '/src/app'; - $this->app['path.public'] = '/src/public'; - $this->app['path.storage'] = '/src/storage'; + $this->app->instance('path.base', '/src'); + $this->app->instance('path', '/src/app'); + $this->app->instance('path.public', '/src/public'); + $this->app->instance('path.storage', '/src/app/storage'); $this->app['files'] = new Filesystem; $this->app['config'] = $this->getConfig(); From af9f038b0be4b831ab3efe9f144dca2a29b48bea Mon Sep 17 00:00:00 2001 From: Maxime Fabre Date: Sat, 19 Oct 2013 09:56:24 +0200 Subject: [PATCH 05/20] Simpler test for paths --- composer.lock | 100 +++++++++++++++++++----------------- src/Rocketeer/Rocketeer.php | 8 +-- tests/meta/coverage.txt | 28 +++++----- 3 files changed, 68 insertions(+), 68 deletions(-) diff --git a/composer.lock b/composer.lock index 53e258ebc..37f387879 100644 --- a/composer.lock +++ b/composer.lock @@ -12,12 +12,12 @@ "source": { "type": "git", "url": "https://github.com/illuminate/config.git", - "reference": "70e05b02ed6f1ff0df447a0da0a2421cf95f6fce" + "reference": "a48873b5e777ea09777291b02cb498032924844e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/config/zipball/70e05b02ed6f1ff0df447a0da0a2421cf95f6fce", - "reference": "70e05b02ed6f1ff0df447a0da0a2421cf95f6fce", + "url": "https://api.github.com/repos/illuminate/config/zipball/a48873b5e777ea09777291b02cb498032924844e", + "reference": "a48873b5e777ea09777291b02cb498032924844e", "shasum": "" }, "require": { @@ -46,10 +46,12 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylorotwell@gmail.com", + "homepage": "https://github.com/taylorotwell", + "role": "Developer" } ], - "time": "2013-08-10 17:47:18" + "time": "2013-10-01 15:20:00" }, { "name": "illuminate/console", @@ -58,16 +60,16 @@ "source": { "type": "git", "url": "https://github.com/illuminate/console.git", - "reference": "cffaa6e6414828fb7a0a742b5f7e9d0f789e24ae" + "reference": "0b4badcd1aecdb623d3e435d1c6d8797e772e233" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/console/zipball/cffaa6e6414828fb7a0a742b5f7e9d0f789e24ae", - "reference": "cffaa6e6414828fb7a0a742b5f7e9d0f789e24ae", + "url": "https://api.github.com/repos/illuminate/console/zipball/0b4badcd1aecdb623d3e435d1c6d8797e772e233", + "reference": "0b4badcd1aecdb623d3e435d1c6d8797e772e233", "shasum": "" }, "require": { - "symfony/console": "2.3.*" + "symfony/console": "2.4.*" }, "require-dev": { "phpunit/phpunit": "3.7.*" @@ -90,10 +92,12 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylorotwell@gmail.com", + "homepage": "https://github.com/taylorotwell", + "role": "Developer" } ], - "time": "2013-07-19 10:47:48" + "time": "2013-10-08 21:46:57" }, { "name": "illuminate/container", @@ -102,12 +106,12 @@ "source": { "type": "git", "url": "https://github.com/illuminate/container.git", - "reference": "0d827306eebba40483c185b56f9996fd0b9e842c" + "reference": "1444907a30937bf4b7a910489160ba4576f3afa9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/container/zipball/0d827306eebba40483c185b56f9996fd0b9e842c", - "reference": "0d827306eebba40483c185b56f9996fd0b9e842c", + "url": "https://api.github.com/repos/illuminate/container/zipball/1444907a30937bf4b7a910489160ba4576f3afa9", + "reference": "1444907a30937bf4b7a910489160ba4576f3afa9", "shasum": "" }, "require": { @@ -139,7 +143,7 @@ "role": "Developer" } ], - "time": "2013-08-26 18:53:15" + "time": "2013-10-02 21:50:28" }, { "name": "illuminate/filesystem", @@ -148,18 +152,18 @@ "source": { "type": "git", "url": "https://github.com/illuminate/filesystem.git", - "reference": "fe9915c329ef869efccbc88334cf3ff89f2ecb03" + "reference": "98c6e3710853f4e0aee7ea14b09194083815bf1b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/filesystem/zipball/fe9915c329ef869efccbc88334cf3ff89f2ecb03", - "reference": "fe9915c329ef869efccbc88334cf3ff89f2ecb03", + "url": "https://api.github.com/repos/illuminate/filesystem/zipball/98c6e3710853f4e0aee7ea14b09194083815bf1b", + "reference": "98c6e3710853f4e0aee7ea14b09194083815bf1b", "shasum": "" }, "require": { - "illuminate/support": "4.1.x", + "illuminate/support": "4.1.*", "php": ">=5.3.0", - "symfony/finder": "2.3.x" + "symfony/finder": "2.4.*" }, "require-dev": { "phpunit/phpunit": "3.7.*" @@ -182,10 +186,12 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylorotwell@gmail.com", + "homepage": "https://github.com/taylorotwell", + "role": "Developer" } ], - "time": "2013-07-02 17:46:50" + "time": "2013-10-08 21:46:57" }, { "name": "illuminate/support", @@ -194,12 +200,12 @@ "source": { "type": "git", "url": "https://github.com/illuminate/support.git", - "reference": "9e61ed7335f457521b888fd405f16eda6f7caf02" + "reference": "33df9bdf3d9b38353097d2e6cfdfc4ebfe9900c1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/support/zipball/9e61ed7335f457521b888fd405f16eda6f7caf02", - "reference": "9e61ed7335f457521b888fd405f16eda6f7caf02", + "url": "https://api.github.com/repos/illuminate/support/zipball/33df9bdf3d9b38353097d2e6cfdfc4ebfe9900c1", + "reference": "33df9bdf3d9b38353097d2e6cfdfc4ebfe9900c1", "shasum": "" }, "require": { @@ -236,21 +242,21 @@ "role": "Developer" } ], - "time": "2013-09-06 05:21:45" + "time": "2013-10-03 21:32:36" }, { "name": "symfony/console", - "version": "2.3.x-dev", + "version": "dev-master", "target-dir": "Symfony/Component/Console", "source": { "type": "git", "url": "https://github.com/symfony/Console.git", - "reference": "aba4731bf8dafa21b7c4a59bd69c62f73c0a6dcf" + "reference": "608960cd7f7e906e64d6586b9152e308f7ea0ff2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Console/zipball/aba4731bf8dafa21b7c4a59bd69c62f73c0a6dcf", - "reference": "aba4731bf8dafa21b7c4a59bd69c62f73c0a6dcf", + "url": "https://api.github.com/repos/symfony/Console/zipball/608960cd7f7e906e64d6586b9152e308f7ea0ff2", + "reference": "608960cd7f7e906e64d6586b9152e308f7ea0ff2", "shasum": "" }, "require": { @@ -265,7 +271,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.3-dev" + "dev-master": "2.4-dev" } }, "autoload": { @@ -289,21 +295,21 @@ ], "description": "Symfony Console Component", "homepage": "http://symfony.com", - "time": "2013-09-18 07:03:56" + "time": "2013-10-16 16:16:10" }, { "name": "symfony/finder", - "version": "2.3.x-dev", + "version": "dev-master", "target-dir": "Symfony/Component/Finder", "source": { "type": "git", "url": "https://github.com/symfony/Finder.git", - "reference": "4a0fee5b86f5bbd9dfdc11ec124eba2915737ce1" + "reference": "e2ce3164ab58b4d54612e630571f158035ee8603" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Finder/zipball/4a0fee5b86f5bbd9dfdc11ec124eba2915737ce1", - "reference": "4a0fee5b86f5bbd9dfdc11ec124eba2915737ce1", + "url": "https://api.github.com/repos/symfony/Finder/zipball/e2ce3164ab58b4d54612e630571f158035ee8603", + "reference": "e2ce3164ab58b4d54612e630571f158035ee8603", "shasum": "" }, "require": { @@ -312,7 +318,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.3-dev" + "dev-master": "2.4-dev" } }, "autoload": { @@ -336,7 +342,7 @@ ], "description": "Symfony Finder Component", "homepage": "http://symfony.com", - "time": "2013-08-13 20:18:00" + "time": "2013-09-19 09:47:34" } ], "packages-dev": [ @@ -346,12 +352,12 @@ "source": { "type": "git", "url": "https://github.com/padraic/mockery.git", - "reference": "b6fe71cbc1909927b5574219ff6d50e3b264abdb" + "reference": "09ab879a09def2a658d6e8030f88432cc479f5a8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/padraic/mockery/zipball/b6fe71cbc1909927b5574219ff6d50e3b264abdb", - "reference": "b6fe71cbc1909927b5574219ff6d50e3b264abdb", + "url": "https://api.github.com/repos/padraic/mockery/zipball/09ab879a09def2a658d6e8030f88432cc479f5a8", + "reference": "09ab879a09def2a658d6e8030f88432cc479f5a8", "shasum": "" }, "require": { @@ -392,7 +398,7 @@ "test double", "testing" ], - "time": "2013-08-21 19:34:19" + "time": "2013-10-18 15:18:30" }, { "name": "nesbot/carbon", @@ -443,12 +449,12 @@ "source": { "type": "git", "url": "https://github.com/nicolas-grekas/Patchwork-UTF8.git", - "reference": "e4bd68ca375d854615613e6b77003e08c1744c54" + "reference": "efd5478a233f6940d3296ab27c2a02ba47831968" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nicolas-grekas/Patchwork-UTF8/zipball/e4bd68ca375d854615613e6b77003e08c1744c54", - "reference": "e4bd68ca375d854615613e6b77003e08c1744c54", + "url": "https://api.github.com/repos/nicolas-grekas/Patchwork-UTF8/zipball/efd5478a233f6940d3296ab27c2a02ba47831968", + "reference": "efd5478a233f6940d3296ab27c2a02ba47831968", "shasum": "" }, "require": { @@ -478,7 +484,7 @@ "role": "Developer" } ], - "description": "UTF-8 strings handling for PHP 5.3: portable, performant and extended", + "description": "Extensive, portable and performant handling of UTF-8 and grapheme clusters for PHP", "homepage": "https://github.com/nicolas-grekas/Patchwork-UTF8", "keywords": [ "i18n", @@ -486,7 +492,7 @@ "utf-8", "utf8" ], - "time": "2013-09-05 12:11:48" + "time": "2013-10-15 08:18:30" } ], "aliases": [ diff --git a/src/Rocketeer/Rocketeer.php b/src/Rocketeer/Rocketeer.php index 6495ae698..e3f1ea27e 100644 --- a/src/Rocketeer/Rocketeer.php +++ b/src/Rocketeer/Rocketeer.php @@ -3,7 +3,6 @@ use Illuminate\Container\Container; use Illuminate\Support\Str; -use \ReflectionException; /** * Handles interaction between the User provided informations @@ -212,12 +211,7 @@ public function replacePatterns($path) return preg_replace_callback('/\{[a-z\.]+\}/', function ($match) use ($app) { $folder = substr($match[0], 1, -1); - try { - $app_folder = $app[$folder]; - } catch(\ReflectionException $e) { - return false; - } - if (isset($app_folder)) { + if ($app->bound($folder)) { return str_replace($app['path.base'].'/', null, $app->make($folder)); } diff --git a/tests/meta/coverage.txt b/tests/meta/coverage.txt index 9176bea18..d28cb820a 100644 --- a/tests/meta/coverage.txt +++ b/tests/meta/coverage.txt @@ -1,27 +1,27 @@ -Code Coverage Report: - 2013-09-19 12:00:54 - - Summary: - Classes: 63.16% (12/19) +Code Coverage Report + 2013-10-19 09:59:48 + + Summary: + Classes: 65.00% (13/20) Methods: 87.72% (100/114) - Lines: 90.07% (517/574) + Lines: 90.05% (516/573) \Rocketeer::Bash - Methods: 88.24% (15/17) Lines: 93.07% ( 94/101) + Methods: 100.00% (17/17) Lines: 93.52% (101/108) \Rocketeer::ReleasesManager Methods: 100.00% ( 9/ 9) Lines: 100.00% ( 22/ 22) \Rocketeer::Rocketeer - Methods: 100.00% (15/15) Lines: 100.00% ( 50/ 50) + Methods: 100.00% (15/15) Lines: 100.00% ( 55/ 55) \Rocketeer::Server - Methods: 90.00% ( 9/10) Lines: 90.48% ( 38/ 42) + Methods: 100.00% (10/10) Lines: 91.11% ( 41/ 45) \Rocketeer::TasksQueue - Methods: 80.00% (12/15) Lines: 89.77% ( 79/ 88) + Methods: 100.00% (15/15) Lines: 91.09% ( 92/101) \Rocketeer\Scm::Git Methods: 100.00% ( 6/ 6) Lines: 100.00% ( 8/ 8) \Rocketeer\Tasks::Check - Methods: 57.14% ( 4/ 7) Lines: 66.67% ( 36/ 54) + Methods: 100.00% ( 7/ 7) Lines: 66.67% ( 36/ 54) \Rocketeer\Tasks::Cleanup Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 9/ 9) \Rocketeer\Tasks::Closure @@ -29,13 +29,13 @@ Code Coverage Report: \Rocketeer\Tasks::CurrentRelease Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 7/ 7) \Rocketeer\Tasks::Deploy - Methods: 50.00% ( 2/ 4) Lines: 62.86% ( 22/ 35) + Methods: 75.00% ( 3/ 4) Lines: 62.86% ( 22/ 35) \Rocketeer\Tasks::Ignite Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 8/ 8) \Rocketeer\Tasks::Rollback Methods: 100.00% ( 2/ 2) Lines: 100.00% ( 5/ 5) \Rocketeer\Tasks::Setup - Methods: 50.00% ( 1/ 2) Lines: 88.89% ( 24/ 27) + Methods: 100.00% ( 2/ 2) Lines: 88.89% ( 24/ 27) \Rocketeer\Tasks::Teardown Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 7/ 7) \Rocketeer\Tasks::Test @@ -45,4 +45,4 @@ Code Coverage Report: \Rocketeer\Traits::Scm Methods: 100.00% ( 3/ 3) Lines: 100.00% ( 7/ 7) \Rocketeer\Traits::Task - Methods: 86.67% (13/15) Lines: 95.83% ( 69/ 72) + Methods: 93.75% (15/16) Lines: 95.83% ( 69/ 72) From 4f5ded9e4cc65d0adb6dc7d7e886d50376e3ff3a Mon Sep 17 00:00:00 2001 From: Maxime Fabre Date: Sat, 19 Oct 2013 10:23:34 +0200 Subject: [PATCH 06/20] Add stages contextual configuration --- src/Rocketeer/Rocketeer.php | 31 +++++++++++++++++++++++++ src/config/config.php | 26 +++++++++++++++++++++ tests/RocketeerTest.php | 10 ++++++++ tests/_start.php | 1 + tests/meta/coverage.txt | 46 ++++++++----------------------------- 5 files changed, 78 insertions(+), 36 deletions(-) diff --git a/src/Rocketeer/Rocketeer.php b/src/Rocketeer/Rocketeer.php index e3f1ea27e..17a7f5018 100644 --- a/src/Rocketeer/Rocketeer.php +++ b/src/Rocketeer/Rocketeer.php @@ -50,9 +50,40 @@ public function __construct(Container $app) */ public function getOption($option) { + if ($contextual = $this->getContextualOption($option, 'stages')) { + return $contextual; + } + + if ($contextual = $this->getContextualOption($option, 'connections')) { + return $contextual; + } + return $this->app['config']->get('rocketeer::'.$option); } + /** + * Get a contextual option + * + * @param string $option + * @param string $type [stage,connection] + * + * @return mixed + */ + protected function getContextualOption($option, $type) + { + switch ($type) { + case 'stages': + $contextual = sprintf('rocketeer::on.stages.%s.%s', $this->stage, $option); + break; + + case 'connections': + $contextual = sprintf('rocketeer::on.connections.%s.%s', $this->stage, $option); + break; + } + + return $this->app['config']->get($contextual); + } + //////////////////////////////////////////////////////////////////// //////////////////////////////// STAGES //////////////////////////// //////////////////////////////////////////////////////////////////// diff --git a/src/config/config.php b/src/config/config.php index 2792ae587..2a3f79191 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -128,4 +128,30 @@ 'custom' => array(), ), + // Contextual options + // + // In this section you can fine-tune the above configuration according + // to the stage or connection currently in use. + // Per example : + // 'stages' => array( + // 'staging' => array( + // 'scm' => array('branch' => 'staging'), + // ), + // 'production' => array( + // 'scm' => array('branch' => 'master'), + // ), + // ), + + 'on' => array( + + // Stages configurations + 'stages' => array( + ), + + // Connections configuration + 'connections' => array( + ), + + ), + ); diff --git a/tests/RocketeerTest.php b/tests/RocketeerTest.php index ba77ab124..f6f668471 100644 --- a/tests/RocketeerTest.php +++ b/tests/RocketeerTest.php @@ -107,6 +107,16 @@ public function testCannotReplaceUnexistingPatternsInFolders() $this->assertEquals($this->server.'/', $folder); } + public function testCanUseRecursiveStageConfiguration() + { + $this->app['config']->shouldReceive('get')->with('rocketeer::scm.branch')->andReturn('master'); + $this->app['config']->shouldReceive('get')->with('rocketeer::on.stages.staging.scm.branch')->andReturn('staging'); + + $this->assertEquals('master', $this->app['rocketeer.rocketeer']->getOption('scm.branch')); + $this->app['rocketeer.rocketeer']->setStage('staging'); + $this->assertEquals('staging', $this->app['rocketeer.rocketeer']->getOption('scm.branch')); + } + //////////////////////////////////////////////////////////////////// //////////////////////////////// HELPERS /////////////////////////// //////////////////////////////////////////////////////////////////// diff --git a/tests/_start.php b/tests/_start.php index 6c9797aeb..ffaa5ce6e 100644 --- a/tests/_start.php +++ b/tests/_start.php @@ -222,6 +222,7 @@ protected function getCommand() protected function getConfig() { $config = Mockery::mock('Illuminate\Config\Repository'); + $config->shouldIgnoreMissing(); // Drivers $config->shouldReceive('get')->with('cache.driver')->andReturn('file'); diff --git a/tests/meta/coverage.txt b/tests/meta/coverage.txt index d28cb820a..bb889ffb6 100644 --- a/tests/meta/coverage.txt +++ b/tests/meta/coverage.txt @@ -1,48 +1,22 @@ Code Coverage Report - 2013-10-19 09:59:48 + 2013-10-19 10:26:31 Summary: - Classes: 65.00% (13/20) - Methods: 87.72% (100/114) - Lines: 90.05% (516/573) + Classes: 5.00% (1/20) + Methods: 18.26% (21/115) + Lines: 13.62% (93/683) \Rocketeer::Bash - Methods: 100.00% (17/17) Lines: 93.52% (101/108) -\Rocketeer::ReleasesManager - Methods: 100.00% ( 9/ 9) Lines: 100.00% ( 22/ 22) + Methods: 5.88% ( 1/17) Lines: 2.78% ( 3/108) \Rocketeer::Rocketeer - Methods: 100.00% (15/15) Lines: 100.00% ( 55/ 55) + Methods: 87.50% (14/16) Lines: 95.52% ( 64/ 67) \Rocketeer::Server - Methods: 100.00% (10/10) Lines: 91.11% ( 41/ 45) + Methods: 50.00% ( 5/10) Lines: 40.00% ( 18/ 45) \Rocketeer::TasksQueue - Methods: 100.00% (15/15) Lines: 91.09% ( 92/101) + Methods: 13.33% ( 2/15) Lines: 8.91% ( 9/101) \Rocketeer\Scm::Git - Methods: 100.00% ( 6/ 6) Lines: 100.00% ( 8/ 8) -\Rocketeer\Tasks::Check - Methods: 100.00% ( 7/ 7) Lines: 66.67% ( 36/ 54) -\Rocketeer\Tasks::Cleanup - Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 9/ 9) -\Rocketeer\Tasks::Closure - Methods: 100.00% ( 3/ 3) Lines: 100.00% ( 5/ 5) -\Rocketeer\Tasks::CurrentRelease - Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 7/ 7) -\Rocketeer\Tasks::Deploy - Methods: 75.00% ( 3/ 4) Lines: 62.86% ( 22/ 35) -\Rocketeer\Tasks::Ignite - Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 8/ 8) -\Rocketeer\Tasks::Rollback - Methods: 100.00% ( 2/ 2) Lines: 100.00% ( 5/ 5) -\Rocketeer\Tasks::Setup - Methods: 100.00% ( 2/ 2) Lines: 88.89% ( 24/ 27) -\Rocketeer\Tasks::Teardown - Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 7/ 7) -\Rocketeer\Tasks::Test - Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 2/ 2) -\Rocketeer\Tasks::Update - Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 9/ 9) + Methods: 16.67% ( 1/ 6) Lines: 12.50% ( 1/ 8) \Rocketeer\Traits::Scm - Methods: 100.00% ( 3/ 3) Lines: 100.00% ( 7/ 7) -\Rocketeer\Traits::Task - Methods: 93.75% (15/16) Lines: 95.83% ( 69/ 72) + Methods: 66.67% ( 2/ 3) Lines: 42.86% ( 3/ 7) From 63076e76d768158db935902c649cc46f7e487d15 Mon Sep 17 00:00:00 2001 From: Maxime Fabre Date: Sat, 19 Oct 2013 10:30:01 +0200 Subject: [PATCH 07/20] Close #45 - Add contextual connections options --- CHANGELOG.md | 1 + src/Rocketeer/Commands/BaseDeployCommand.php | 12 ++--- src/Rocketeer/Rocketeer.php | 28 +++++++++++- tests/RocketeerTest.php | 37 ++++++++++++++-- tests/_start.php | 18 +++++++- tests/meta/coverage.txt | 46 +++++++++++++++----- 6 files changed, 118 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f88bbe9b..181a03e4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### 0.7.1 (develop) +- **Rocketeer can now have specific configurations for stages and connections** - Added `deploy:flush` to clear Rocketeer's cache of credentials ### 0.7.0 (stable) diff --git a/src/Rocketeer/Commands/BaseDeployCommand.php b/src/Rocketeer/Commands/BaseDeployCommand.php index 1ecdf1a03..a3061bd2c 100644 --- a/src/Rocketeer/Commands/BaseDeployCommand.php +++ b/src/Rocketeer/Commands/BaseDeployCommand.php @@ -112,16 +112,10 @@ protected function getRepositoryCredentials() protected function getServerCredentials() { // Check for configured connections - $connections = $this->laravel['rocketeer.rocketeer']->getConnections(); - if (empty($connections)) { + $connections = $this->laravel['rocketeer.rocketeer']->getConnections(); + $connectionName = $this->laravel['rocketeer.rocketeer']->getConnection(); + if (is_null($connectionName)) { $connectionName = $this->ask('No connections have been set, please create one : (production)', 'production'); - } else { - $connectionName = key($connections); - } - - // Set the found connection as default if none is specified - if (!isset($this->laravel['config']['remote.default'])) { - $this->laravel['config']->set('remote.default', $connectionName); } // Check for server credentials diff --git a/src/Rocketeer/Rocketeer.php b/src/Rocketeer/Rocketeer.php index 17a7f5018..a1e63edb9 100644 --- a/src/Rocketeer/Rocketeer.php +++ b/src/Rocketeer/Rocketeer.php @@ -77,7 +77,7 @@ protected function getContextualOption($option, $type) break; case 'connections': - $contextual = sprintf('rocketeer::on.connections.%s.%s', $this->stage, $option); + $contextual = sprintf('rocketeer::on.connections.%s.%s', $this->getConnection(), $option); break; } @@ -149,6 +149,32 @@ public function getConnections() return $connections; } + /** + * Get the connection in use + * + * @return string + */ + public function getConnection() + { + $connections = $this->getConnections(); + $default = $this->app['config']->get('remote.default'); + + // Cancel if no connection has yet been set + if (empty($connections)) { + return null; + } + + // Get the connection to use + $connectionName = array_key_exists($default, $connections) ? $default : key($connections); + + // Get default connection + if (!$default) { + $this->app['config']->set('remote.default', $connectionName); + } + + return $connectionName; + } + /** * Get the name of the application to deploy * diff --git a/tests/RocketeerTest.php b/tests/RocketeerTest.php index f6f668471..228e89193 100644 --- a/tests/RocketeerTest.php +++ b/tests/RocketeerTest.php @@ -10,13 +10,25 @@ class RocketeerTest extends RocketeerTests public function testCanGetAvailableConnections() { $connections = $this->app['rocketeer.rocketeer']->getConnections(); - $this->assertEquals(array('production'), array_keys($connections)); + $this->assertEquals(array('production', 'staging'), array_keys($connections)); $this->app['rocketeer.server']->setValue('connections.custom.username', 'foobar'); $connections = $this->app['rocketeer.rocketeer']->getConnections(); $this->assertEquals(array('custom'), array_keys($connections)); } + public function testCanGetCurrentConnection() + { + $this->swapConfig(array('remote.default' => 'foobar')); + $this->assertEquals('production', $this->app['rocketeer.rocketeer']->getConnection()); + + $this->swapConfig(array('remote.default' => 'production')); + $this->assertEquals('production', $this->app['rocketeer.rocketeer']->getConnection()); + + $this->swapConfig(array('remote.default' => 'staging')); + $this->assertEquals('staging', $this->app['rocketeer.rocketeer']->getConnection()); + } + public function testCanUseSshRepository() { $repository = 'git@github.com:Anahkiasen/rocketeer.git'; @@ -109,14 +121,33 @@ public function testCannotReplaceUnexistingPatternsInFolders() public function testCanUseRecursiveStageConfiguration() { - $this->app['config']->shouldReceive('get')->with('rocketeer::scm.branch')->andReturn('master'); - $this->app['config']->shouldReceive('get')->with('rocketeer::on.stages.staging.scm.branch')->andReturn('staging'); + $this->swapConfig(array( + 'rocketeer::scm.branch' => 'master', + 'rocketeer::on.stages.staging.scm.branch' => 'staging', + )); $this->assertEquals('master', $this->app['rocketeer.rocketeer']->getOption('scm.branch')); $this->app['rocketeer.rocketeer']->setStage('staging'); $this->assertEquals('staging', $this->app['rocketeer.rocketeer']->getOption('scm.branch')); } + public function testCanUseRecursiveConnectionConfiguration() + { + $this->swapConfig(array( + 'remote.default' => 'production', + 'rocketeer::scm.branch' => 'master', + 'rocketeer::on.connections.staging.scm.branch' => 'staging', + )); + $this->assertEquals('master', $this->app['rocketeer.rocketeer']->getOption('scm.branch')); + + $this->swapConfig(array( + 'remote.default' => 'staging', + 'rocketeer::scm.branch' => 'master', + 'rocketeer::on.connections.staging.scm.branch' => 'staging', + )); + $this->assertEquals('staging', $this->app['rocketeer.rocketeer']->getOption('scm.branch')); + } + //////////////////////////////////////////////////////////////////// //////////////////////////////// HELPERS /////////////////////////// //////////////////////////////////////////////////////////////////// diff --git a/tests/_start.php b/tests/_start.php index ffaa5ce6e..5342d42a0 100644 --- a/tests/_start.php +++ b/tests/_start.php @@ -110,6 +110,7 @@ protected function recreateVirtualServer() ))); // Recreate altered local server + $this->app['files']->deleteDirectory(__DIR__.'/../storage'); $folders = array('current', 'shared', 'releases', 'releases/10000000000000', 'releases/20000000000000'); foreach ($folders as $folder) { $folder = $this->server.'/'.$folder; @@ -227,7 +228,7 @@ protected function getConfig() // Drivers $config->shouldReceive('get')->with('cache.driver')->andReturn('file'); $config->shouldReceive('get')->with('database.default')->andReturn('mysql'); - $config->shouldReceive('get')->with('remote.connections')->andReturn(array('production' => array())); + $config->shouldReceive('get')->with('remote.connections')->andReturn(array('production' => array(), 'staging' => array())); $config->shouldReceive('get')->with('session.driver')->andReturn('file'); // Rocketeer @@ -271,6 +272,21 @@ protected function getConfig() return $config; } + /** + * Swap the current config + * + * @param array $config + * + * @return void + */ + protected function swapConfig($config) + { + $this->app['config'] = $this->getConfig(); + foreach ($config as $key => $value) { + $this->app['config']->shouldReceive('get')->with($key)->andReturn($value); + } + } + /** * Mock the Remote component * diff --git a/tests/meta/coverage.txt b/tests/meta/coverage.txt index bb889ffb6..eedace119 100644 --- a/tests/meta/coverage.txt +++ b/tests/meta/coverage.txt @@ -1,22 +1,48 @@ Code Coverage Report - 2013-10-19 10:26:31 + 2013-10-19 11:07:13 Summary: - Classes: 5.00% (1/20) - Methods: 18.26% (21/115) - Lines: 13.62% (93/683) + Classes: 65.00% (13/20) + Methods: 87.93% (102/116) + Lines: 90.40% (537/594) \Rocketeer::Bash - Methods: 5.88% ( 1/17) Lines: 2.78% ( 3/108) + Methods: 100.00% (17/17) Lines: 93.52% (101/108) +\Rocketeer::ReleasesManager + Methods: 100.00% ( 9/ 9) Lines: 100.00% ( 22/ 22) \Rocketeer::Rocketeer - Methods: 87.50% (14/16) Lines: 95.52% ( 64/ 67) + Methods: 100.00% (17/17) Lines: 100.00% ( 76/ 76) \Rocketeer::Server - Methods: 50.00% ( 5/10) Lines: 40.00% ( 18/ 45) + Methods: 100.00% (10/10) Lines: 91.11% ( 41/ 45) \Rocketeer::TasksQueue - Methods: 13.33% ( 2/15) Lines: 8.91% ( 9/101) + Methods: 100.00% (15/15) Lines: 91.09% ( 92/101) \Rocketeer\Scm::Git - Methods: 16.67% ( 1/ 6) Lines: 12.50% ( 1/ 8) + Methods: 100.00% ( 6/ 6) Lines: 100.00% ( 8/ 8) +\Rocketeer\Tasks::Check + Methods: 100.00% ( 7/ 7) Lines: 66.67% ( 36/ 54) +\Rocketeer\Tasks::Cleanup + Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 9/ 9) +\Rocketeer\Tasks::Closure + Methods: 100.00% ( 3/ 3) Lines: 100.00% ( 5/ 5) +\Rocketeer\Tasks::CurrentRelease + Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 7/ 7) +\Rocketeer\Tasks::Deploy + Methods: 75.00% ( 3/ 4) Lines: 62.86% ( 22/ 35) +\Rocketeer\Tasks::Ignite + Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 8/ 8) +\Rocketeer\Tasks::Rollback + Methods: 100.00% ( 2/ 2) Lines: 100.00% ( 5/ 5) +\Rocketeer\Tasks::Setup + Methods: 100.00% ( 2/ 2) Lines: 88.89% ( 24/ 27) +\Rocketeer\Tasks::Teardown + Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 7/ 7) +\Rocketeer\Tasks::Test + Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 2/ 2) +\Rocketeer\Tasks::Update + Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 9/ 9) \Rocketeer\Traits::Scm - Methods: 66.67% ( 2/ 3) Lines: 42.86% ( 3/ 7) + Methods: 100.00% ( 3/ 3) Lines: 100.00% ( 7/ 7) +\Rocketeer\Traits::Task + Methods: 93.75% (15/16) Lines: 95.83% ( 69/ 72) From 8163d9c70e7d322531fcb9776a554e17db36deeb Mon Sep 17 00:00:00 2001 From: Maxime Fabre Date: Sat, 19 Oct 2013 11:22:13 +0200 Subject: [PATCH 08/20] Work on multiconnections handling --- src/Rocketeer/Rocketeer.php | 27 ++++++++++++++++++++++++++- src/Rocketeer/TasksQueue.php | 32 +++++++++++++++++++------------- tests/RocketeerTest.php | 9 +++++++++ tests/TasksQueueTest.php | 26 +++++++++++++++++++++++++- tests/_start.php | 12 +++++++----- tests/meta/coverage.txt | 10 +++++----- 6 files changed, 91 insertions(+), 25 deletions(-) diff --git a/src/Rocketeer/Rocketeer.php b/src/Rocketeer/Rocketeer.php index a1e63edb9..1146f4a7d 100644 --- a/src/Rocketeer/Rocketeer.php +++ b/src/Rocketeer/Rocketeer.php @@ -24,6 +24,13 @@ class Rocketeer */ protected $stage; + /** + * The current connection + * + * @var string + */ + protected $connection; + /** * The Rocketeer version * @@ -156,6 +163,12 @@ public function getConnections() */ public function getConnection() { + // Get cached resolved connection + if ($this->connection) { + return $this->connection; + } + + // Get all and defaults $connections = $this->getConnections(); $default = $this->app['config']->get('remote.default'); @@ -167,7 +180,8 @@ public function getConnection() // Get the connection to use $connectionName = array_key_exists($default, $connections) ? $default : key($connections); - // Get default connection + // Set current connection as default + $this->connection = $connectionName; if (!$default) { $this->app['config']->set('remote.default', $connectionName); } @@ -175,6 +189,17 @@ public function getConnection() return $connectionName; } + /** + * Set the curent connection + * + * @param string $connection + */ + public function setConnection($connection) + { + $this->connection = $connection; + $this->app['config']->set('remote.default', $connection); + } + /** * Get the name of the application to deploy * diff --git a/src/Rocketeer/TasksQueue.php b/src/Rocketeer/TasksQueue.php index e00ddd0b3..f1d7e8ed0 100644 --- a/src/Rocketeer/TasksQueue.php +++ b/src/Rocketeer/TasksQueue.php @@ -143,20 +143,26 @@ public function run(array $tasks, $command = null) $this->command = $command; $queue = $this->buildQueue($tasks); - // Check if we provided a stage - $stage = $this->getStage(); - $stages = $this->app['rocketeer.rocketeer']->getStages(); - if ($stage and in_array($stage, $stages)) { - $stages = array($stage); - } + // Get the connections to execute the tasks on + $connections = (array) $this->app['rocketeer.rocketeer']->getOption('connections'); + foreach ($connections as $connection) { + $this->app['rocketeer.rocketeer']->setConnection($connection); + + // Check if we provided a stage + $stage = $this->getStage(); + $stages = $this->app['rocketeer.rocketeer']->getStages(); + if ($stage and in_array($stage, $stages)) { + $stages = array($stage); + } - // Run the Tasks on each stage - if (!empty($stages)) { - foreach ($stages as $stage) { - $state = $this->runQueue($queue, $stage); + // Run the Tasks on each stage + if (!empty($stages)) { + foreach ($stages as $stage) { + $state = $this->runQueue($queue, $stage); + } + } else { + $state = $this->runQueue($queue); } - } else { - $state = $this->runQueue($queue); } return $state ? $queue : $state; @@ -165,7 +171,7 @@ public function run(array $tasks, $command = null) /** * Run the queue, taking into account the stage * - * @param array $tasks + * @param array $tasks * @param string $stage * * @return boolean diff --git a/tests/RocketeerTest.php b/tests/RocketeerTest.php index 228e89193..67b2f17ab 100644 --- a/tests/RocketeerTest.php +++ b/tests/RocketeerTest.php @@ -29,6 +29,15 @@ public function testCanGetCurrentConnection() $this->assertEquals('staging', $this->app['rocketeer.rocketeer']->getConnection()); } + public function testCanChangeConnection() + { + $this->assertEquals('production', $this->app['rocketeer.rocketeer']->getConnection()); + + $this->app['rocketeer.rocketeer']->setConnection('staging'); + $this->swapConfig(array('remote.default' => 'staging')); + $this->assertEquals('staging', $this->app['rocketeer.rocketeer']->getConnection()); + } + public function testCanUseSshRepository() { $repository = 'git@github.com:Anahkiasen/rocketeer.git'; diff --git a/tests/TasksQueueTest.php b/tests/TasksQueueTest.php index 5512bbff8..a01e47c1d 100644 --- a/tests/TasksQueueTest.php +++ b/tests/TasksQueueTest.php @@ -3,7 +3,6 @@ class TasksQueueTest extends RocketeerTests { - public function testCanUseFacadeOutsideOfLaravel() { Rocketeer::before('deploy', 'ls'); @@ -150,4 +149,29 @@ function ($task) { } ), $this->getCommand()); } + + public function testCanRunQueueOnDifferentConnectionsAndStages() + { + $this->swapConfig(array( + 'rocketeer::connections' => array('staging', 'production'), + 'rocketeer::stages.stages' => array('first', 'second'), + )); + + $output = array(); + $queue = array( + function($task) use (&$output) { + $output[] = $task->rocketeer->getConnection(). ' - ' .$task->rocketeer->getStage(); + } + ); + + $queue = $this->tasksQueue()->buildQueue($queue); + $this->tasksQueue()->run($queue, $this->getCommand()); + + $this->assertEquals(array( + 'staging - first', + 'staging - second', + 'production - first', + 'production - second', + ), $output); + } } diff --git a/tests/_start.php b/tests/_start.php index 5342d42a0..0980e04a7 100644 --- a/tests/_start.php +++ b/tests/_start.php @@ -220,11 +220,15 @@ protected function getCommand() * * @return Mockery */ - protected function getConfig() + protected function getConfig($options = array()) { $config = Mockery::mock('Illuminate\Config\Repository'); $config->shouldIgnoreMissing(); + foreach ($options as $key => $value) { + $config->shouldReceive('get')->with($key)->andReturn($value); + } + // Drivers $config->shouldReceive('get')->with('cache.driver')->andReturn('file'); $config->shouldReceive('get')->with('database.default')->andReturn('mysql'); @@ -281,10 +285,8 @@ protected function getConfig() */ protected function swapConfig($config) { - $this->app['config'] = $this->getConfig(); - foreach ($config as $key => $value) { - $this->app['config']->shouldReceive('get')->with($key)->andReturn($value); - } + $this->app['rocketeer.rocketeer']->setConnection(null); + $this->app['config'] = $this->getConfig($config); } /** diff --git a/tests/meta/coverage.txt b/tests/meta/coverage.txt index eedace119..54ce857e9 100644 --- a/tests/meta/coverage.txt +++ b/tests/meta/coverage.txt @@ -1,23 +1,23 @@ Code Coverage Report - 2013-10-19 11:07:13 + 2013-10-19 12:11:07 Summary: Classes: 65.00% (13/20) - Methods: 87.93% (102/116) - Lines: 90.40% (537/594) + Methods: 88.03% (103/117) + Lines: 91.23% (551/604) \Rocketeer::Bash Methods: 100.00% (17/17) Lines: 93.52% (101/108) \Rocketeer::ReleasesManager Methods: 100.00% ( 9/ 9) Lines: 100.00% ( 22/ 22) \Rocketeer::Rocketeer - Methods: 100.00% (17/17) Lines: 100.00% ( 76/ 76) + Methods: 100.00% (18/18) Lines: 100.00% ( 82/ 82) \Rocketeer::Server Methods: 100.00% (10/10) Lines: 91.11% ( 41/ 45) \Rocketeer::TasksQueue - Methods: 100.00% (15/15) Lines: 91.09% ( 92/101) + Methods: 100.00% (15/15) Lines: 95.24% (100/105) \Rocketeer\Scm::Git Methods: 100.00% ( 6/ 6) Lines: 100.00% ( 8/ 8) \Rocketeer\Tasks::Check From 1d1b3a39fc29aac1a09199eae5fcd020015fedae Mon Sep 17 00:00:00 2001 From: Maxime Fabre Date: Sat, 19 Oct 2013 12:39:18 +0200 Subject: [PATCH 09/20] Work on connection flag --- src/Rocketeer/Commands/BaseDeployCommand.php | 6 ++ src/Rocketeer/Rocketeer.php | 86 ++++++++++++++++---- src/Rocketeer/TasksQueue.php | 2 +- src/config/config.php | 2 +- tests/RocketeerTest.php | 16 ++-- tests/TasksQueueTest.php | 8 +- tests/_start.php | 5 +- tests/meta/coverage.txt | 12 +-- 8 files changed, 99 insertions(+), 38 deletions(-) diff --git a/src/Rocketeer/Commands/BaseDeployCommand.php b/src/Rocketeer/Commands/BaseDeployCommand.php index a3061bd2c..cc61a0003 100644 --- a/src/Rocketeer/Commands/BaseDeployCommand.php +++ b/src/Rocketeer/Commands/BaseDeployCommand.php @@ -25,6 +25,7 @@ protected function getOptions() { return array( array('pretend', 'p', InputOption::VALUE_NONE, 'Returns an array of commands to be executed instead of actually executing them'), + array('on', 'C', InputOption::VALUE_REQUIRED, 'The connection(s) to execute the Task in'), array('stage', 'S', InputOption::VALUE_REQUIRED, 'The stage to execute the Task in') ); } @@ -111,9 +112,14 @@ protected function getRepositoryCredentials() */ protected function getServerCredentials() { + if ($connection = $this->option('on')) { + $this->laravel['rocketeer.rocketeer']->setConnection($connection); + } + // Check for configured connections $connections = $this->laravel['rocketeer.rocketeer']->getConnections(); $connectionName = $this->laravel['rocketeer.rocketeer']->getConnection(); + dd($connectionName); if (is_null($connectionName)) { $connectionName = $this->ask('No connections have been set, please create one : (production)', 'production'); } diff --git a/src/Rocketeer/Rocketeer.php b/src/Rocketeer/Rocketeer.php index 1146f4a7d..006b73034 100644 --- a/src/Rocketeer/Rocketeer.php +++ b/src/Rocketeer/Rocketeer.php @@ -24,6 +24,13 @@ class Rocketeer */ protected $stage; + /** + * The connections to use + * + * @var array + */ + protected $connections; + /** * The current connection * @@ -146,7 +153,7 @@ public function needsCredentials() * * @return array */ - public function getConnections() + public function getAvailableConnections() { $connections = $this->app['rocketeer.server']->getValue('connections'); if (!$connections) { @@ -156,37 +163,69 @@ public function getConnections() return $connections; } + /** + * Check if a connection has credentials related to it + * + * @param string $connection + * + * @return boolean + */ + public function isValidConnection($connection) + { + $available = (array) $this->getAvailableConnections(); + + return array_key_exists($connection, $available); + } + /** * Get the connection in use * * @return string */ - public function getConnection() + public function getConnections() { - // Get cached resolved connection - if ($this->connection) { - return $this->connection; + // Get cached resolved connections + if ($this->connections) { + return $this->connections; } // Get all and defaults - $connections = $this->getConnections(); + $connections = (array) $this->app['config']->get('rocketeer::connections'); $default = $this->app['config']->get('remote.default'); - // Cancel if no connection has yet been set + // Remove invalid connections + $me = $this; + $connections = array_filter($connections, function($value) use ($me) { + return $me->isValidConnection($value); + }); + + // Return default if no active connection(s) set if (empty($connections)) { - return null; + return array($default); } - // Get the connection to use - $connectionName = array_key_exists($default, $connections) ? $default : key($connections); - // Set current connection as default - $this->connection = $connectionName; - if (!$default) { - $this->app['config']->set('remote.default', $connectionName); + $this->connections = $connections; + + return $connections; + } + + /** + * Get the active connection + * + * @return string + */ + public function getConnection() + { + // Get cached resolved connection + if ($this->connection) { + return $this->connection; } - return $connectionName; + $connection = array_get($this->getConnections(), 0); + $this->connection = $connection; + + return $this->connection; } /** @@ -196,8 +235,21 @@ public function getConnection() */ public function setConnection($connection) { - $this->connection = $connection; - $this->app['config']->set('remote.default', $connection); + if ($this->isValidConnection($connection)) { + $this->connection = $connection; + $this->app['config']->set('remote.default', $connection); + } + } + + /** + * Flush active connection(s) + * + * @return void + */ + public function disconnect() + { + $this->connection = null; + $this->connections = null; } /** diff --git a/src/Rocketeer/TasksQueue.php b/src/Rocketeer/TasksQueue.php index f1d7e8ed0..740525cd6 100644 --- a/src/Rocketeer/TasksQueue.php +++ b/src/Rocketeer/TasksQueue.php @@ -144,7 +144,7 @@ public function run(array $tasks, $command = null) $queue = $this->buildQueue($tasks); // Get the connections to execute the tasks on - $connections = (array) $this->app['rocketeer.rocketeer']->getOption('connections'); + $connections = (array) $this->app['rocketeer.rocketeer']->getConnections(); foreach ($connections as $connection) { $this->app['rocketeer.rocketeer']->setConnection($connection); diff --git a/src/config/config.php b/src/config/config.php index 2a3f79191..2706f5867 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -3,7 +3,7 @@ // Remote access // // You can either use a single connection or an array of connections - // For this configure your app/remote.php file + // If this is null, the "default" entry in remote.php will be used ////////////////////////////////////////////////////////////////////// // The remote connection(s) to deploy to diff --git a/tests/RocketeerTest.php b/tests/RocketeerTest.php index 67b2f17ab..96b00333f 100644 --- a/tests/RocketeerTest.php +++ b/tests/RocketeerTest.php @@ -2,30 +2,29 @@ class RocketeerTest extends RocketeerTests { - //////////////////////////////////////////////////////////////////// //////////////////////////////// TESTS ///////////////////////////// //////////////////////////////////////////////////////////////////// public function testCanGetAvailableConnections() { - $connections = $this->app['rocketeer.rocketeer']->getConnections(); + $connections = $this->app['rocketeer.rocketeer']->getAvailableConnections(); $this->assertEquals(array('production', 'staging'), array_keys($connections)); $this->app['rocketeer.server']->setValue('connections.custom.username', 'foobar'); - $connections = $this->app['rocketeer.rocketeer']->getConnections(); + $connections = $this->app['rocketeer.rocketeer']->getAvailableConnections(); $this->assertEquals(array('custom'), array_keys($connections)); } public function testCanGetCurrentConnection() { - $this->swapConfig(array('remote.default' => 'foobar')); + $this->swapConfig(array('rocketeer::connections' => 'foobar')); $this->assertEquals('production', $this->app['rocketeer.rocketeer']->getConnection()); - $this->swapConfig(array('remote.default' => 'production')); + $this->swapConfig(array('rocketeer::connections' => 'production')); $this->assertEquals('production', $this->app['rocketeer.rocketeer']->getConnection()); - $this->swapConfig(array('remote.default' => 'staging')); + $this->swapConfig(array('rocketeer::connections' => 'staging')); $this->assertEquals('staging', $this->app['rocketeer.rocketeer']->getConnection()); } @@ -34,7 +33,6 @@ public function testCanChangeConnection() $this->assertEquals('production', $this->app['rocketeer.rocketeer']->getConnection()); $this->app['rocketeer.rocketeer']->setConnection('staging'); - $this->swapConfig(array('remote.default' => 'staging')); $this->assertEquals('staging', $this->app['rocketeer.rocketeer']->getConnection()); } @@ -143,14 +141,14 @@ public function testCanUseRecursiveStageConfiguration() public function testCanUseRecursiveConnectionConfiguration() { $this->swapConfig(array( - 'remote.default' => 'production', + 'rocketeer::connections' => 'production', 'rocketeer::scm.branch' => 'master', 'rocketeer::on.connections.staging.scm.branch' => 'staging', )); $this->assertEquals('master', $this->app['rocketeer.rocketeer']->getOption('scm.branch')); $this->swapConfig(array( - 'remote.default' => 'staging', + 'rocketeer::connections' => 'staging', 'rocketeer::scm.branch' => 'master', 'rocketeer::on.connections.staging.scm.branch' => 'staging', )); diff --git a/tests/TasksQueueTest.php b/tests/TasksQueueTest.php index a01e47c1d..f3f6ce837 100644 --- a/tests/TasksQueueTest.php +++ b/tests/TasksQueueTest.php @@ -142,6 +142,10 @@ function ($task) { public function testCanRunQueue() { + $this->swapConfig(array( + 'rocketeer::connections' => 'production', + )); + $this->expectOutputString('JOEY DOESNT SHARE FOOD'); $this->tasksQueue()->run(array( function ($task) { @@ -153,8 +157,8 @@ function ($task) { public function testCanRunQueueOnDifferentConnectionsAndStages() { $this->swapConfig(array( - 'rocketeer::connections' => array('staging', 'production'), - 'rocketeer::stages.stages' => array('first', 'second'), + 'rocketeer::connections' => array('staging', 'production'), + 'rocketeer::stages.stages' => array('first', 'second'), )); $output = array(); diff --git a/tests/_start.php b/tests/_start.php index 0980e04a7..472928d6b 100644 --- a/tests/_start.php +++ b/tests/_start.php @@ -232,11 +232,12 @@ protected function getConfig($options = array()) // Drivers $config->shouldReceive('get')->with('cache.driver')->andReturn('file'); $config->shouldReceive('get')->with('database.default')->andReturn('mysql'); + $config->shouldReceive('get')->with('remote.default')->andReturn('production'); $config->shouldReceive('get')->with('remote.connections')->andReturn(array('production' => array(), 'staging' => array())); $config->shouldReceive('get')->with('session.driver')->andReturn('file'); // Rocketeer - $config->shouldReceive('get')->with('rocketeer::connections')->andReturn('production'); + $config->shouldReceive('get')->with('rocketeer::connections')->andReturn(array('production', 'staging')); $config->shouldReceive('get')->with('rocketeer::remote.application_name')->andReturn('foobar'); $config->shouldReceive('get')->with('rocketeer::remote.keep_releases')->andReturn(1); $config->shouldReceive('get')->with('rocketeer::remote.permissions')->andReturn(array( @@ -285,7 +286,7 @@ protected function getConfig($options = array()) */ protected function swapConfig($config) { - $this->app['rocketeer.rocketeer']->setConnection(null); + $this->app['rocketeer.rocketeer']->disconnect(); $this->app['config'] = $this->getConfig($config); } diff --git a/tests/meta/coverage.txt b/tests/meta/coverage.txt index 54ce857e9..14fca88a1 100644 --- a/tests/meta/coverage.txt +++ b/tests/meta/coverage.txt @@ -1,19 +1,19 @@ Code Coverage Report - 2013-10-19 12:11:07 + 2013-10-19 13:11:55 Summary: - Classes: 65.00% (13/20) - Methods: 88.03% (103/117) - Lines: 91.23% (551/604) + Classes: 60.00% (12/20) + Methods: 87.50% (105/120) + Lines: 91.22% (561/615) \Rocketeer::Bash Methods: 100.00% (17/17) Lines: 93.52% (101/108) \Rocketeer::ReleasesManager Methods: 100.00% ( 9/ 9) Lines: 100.00% ( 22/ 22) \Rocketeer::Rocketeer - Methods: 100.00% (18/18) Lines: 100.00% ( 82/ 82) + Methods: 100.00% (21/21) Lines: 98.91% ( 91/ 92) \Rocketeer::Server Methods: 100.00% (10/10) Lines: 91.11% ( 41/ 45) \Rocketeer::TasksQueue @@ -29,7 +29,7 @@ Code Coverage Report \Rocketeer\Tasks::CurrentRelease Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 7/ 7) \Rocketeer\Tasks::Deploy - Methods: 75.00% ( 3/ 4) Lines: 62.86% ( 22/ 35) + Methods: 100.00% ( 4/ 4) Lines: 63.89% ( 23/ 36) \Rocketeer\Tasks::Ignite Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 8/ 8) \Rocketeer\Tasks::Rollback From 7e2e0ac9f9ae34ea6b9407ebf7013b456c60929b Mon Sep 17 00:00:00 2001 From: Maxime Fabre Date: Sat, 19 Oct 2013 13:44:02 +0200 Subject: [PATCH 10/20] Add Rocketeer::execute and Rocketeer::on --- CHANGELOG.md | 5 +++- src/Rocketeer/TasksQueue.php | 49 +++++++++++++++++++++++++++++++++--- tests/TasksQueueTest.php | 37 +++++++++++++++++++++++++++ tests/meta/coverage.txt | 8 +++--- 4 files changed, 91 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 181a03e4c..8b5879f3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,11 @@ ### Changelog -### 0.7.1 (develop) +### 0.8.0 (develop) - **Rocketeer can now have specific configurations for stages and connections** +- **Better handling of multiple connections** +- **Added facade shortcuts `Rocketeer::execute(Task)` and `Rocketeer::on(connection[s], Task)` to execute commands on the remote servers** +- Added the `--on` flag to all commands to specify which connections the task should be executed on - Added `deploy:flush` to clear Rocketeer's cache of credentials ### 0.7.0 (stable) diff --git a/src/Rocketeer/TasksQueue.php b/src/Rocketeer/TasksQueue.php index 740525cd6..6e7c910a6 100644 --- a/src/Rocketeer/TasksQueue.php +++ b/src/Rocketeer/TasksQueue.php @@ -39,6 +39,13 @@ class TasksQueue */ protected $command; + /** + * The output of the queue + * + * @var array + */ + protected $output = array(); + /** * Build a new TasksQueue Instance * @@ -123,6 +130,39 @@ public function getAfter(Task $task) return $this->getSurroundingTasks($task, 'after'); } + /** + * Execute Tasks on the default connection + * + * @param string|array|Closure $task + * + * @return array + */ + public function execute($queue) + { + $queue = (array) $queue; + $queue = $this->buildQueue($queue); + + return $this->run($queue); + } + + /** + * Execute Tasks on various connections + * + * @param string|array $connections + * @param string|array|Closure $queue + * + * @return array + */ + public function on($connections, $queue) + { + $this->app['config']->set('rocketeer::connections', $connections); + + $queue = (array) $queue; + $queue = $this->buildQueue($queue); + + return $this->run($queue); + } + //////////////////////////////////////////////////////////////////// //////////////////////////////// QUEUE ///////////////////////////// //////////////////////////////////////////////////////////////////// @@ -165,7 +205,7 @@ public function run(array $tasks, $command = null) } } - return $state ? $queue : $state; + return $this->output; } /** @@ -183,6 +223,7 @@ protected function runQueue($tasks, $stage = null) $this->app['rocketeer.rocketeer']->setStage($currentStage); $state = $task->execute(); + $this->output[] = $state; if ($state === false) { return false; } @@ -355,8 +396,10 @@ protected function getSurroundingTasks(Task $task, $position) */ protected function getStage() { - $defaultStage = $this->app['rocketeer.rocketeer']->getOption('stages.default'); - $stage = $this->command->option('stage') ?: $defaultStage; + $stage = $this->app['rocketeer.rocketeer']->getOption('stages.default'); + if ($this->command) { + $stage = $this->command->option('stage') ?: $stage; + } // Return all stages if "all" if ($stage == 'all') { diff --git a/tests/TasksQueueTest.php b/tests/TasksQueueTest.php index f3f6ce837..37db36e62 100644 --- a/tests/TasksQueueTest.php +++ b/tests/TasksQueueTest.php @@ -178,4 +178,41 @@ function($task) use (&$output) { 'production - second', ), $output); } + + public function testCanRunQueueViaExecute() + { + $this->swapConfig(array( + 'rocketeer::connections' => 'production', + )); + + $output = $this->tasksQueue()->execute(array( + 'ls -a', + function($task) { + return 'JOEY DOESNT SHARE FOOD'; + } + )); + + $this->assertEquals(array( + '.'.PHP_EOL.'..'.PHP_EOL.'.gitkeep', + 'JOEY DOESNT SHARE FOOD', + ), $output); + } + + public function testCanRunOnMultipleConnectionsViaOn() + { + $this->swapConfig(array( + 'rocketeer::stages.stages' => array('first', 'second'), + )); + + $output = $this->tasksQueue()->on(['staging', 'production'], function($task) { + return $task->rocketeer->getConnection(). ' - ' .$task->rocketeer->getStage(); + }); + + $this->assertEquals(array( + 'production - first', + 'production - second', + 'staging - first', + 'staging - second', + ), $output); + } } diff --git a/tests/meta/coverage.txt b/tests/meta/coverage.txt index 14fca88a1..1902c37c3 100644 --- a/tests/meta/coverage.txt +++ b/tests/meta/coverage.txt @@ -1,12 +1,12 @@ Code Coverage Report - 2013-10-19 13:11:55 + 2013-10-19 13:44:08 Summary: Classes: 60.00% (12/20) - Methods: 87.50% (105/120) - Lines: 91.22% (561/615) + Methods: 87.70% (107/122) + Lines: 91.39% (573/627) \Rocketeer::Bash Methods: 100.00% (17/17) Lines: 93.52% (101/108) @@ -17,7 +17,7 @@ Code Coverage Report \Rocketeer::Server Methods: 100.00% (10/10) Lines: 91.11% ( 41/ 45) \Rocketeer::TasksQueue - Methods: 100.00% (15/15) Lines: 95.24% (100/105) + Methods: 100.00% (17/17) Lines: 95.73% (112/117) \Rocketeer\Scm::Git Methods: 100.00% ( 6/ 6) Lines: 100.00% ( 8/ 8) \Rocketeer\Tasks::Check From 5c4ab96bb4f31484b99c6ecb8d2566a841a7d740 Mon Sep 17 00:00:00 2001 From: Maxime Fabre Date: Sat, 19 Oct 2013 13:46:36 +0200 Subject: [PATCH 11/20] Allow multiple connections in --on flag --- src/Rocketeer/Commands/BaseDeployCommand.php | 10 +++++----- src/Rocketeer/Rocketeer.php | 20 +++++++++++++++++--- src/Rocketeer/TasksQueue.php | 2 +- tests/TasksQueueTest.php | 4 ++-- tests/meta/coverage.txt | 8 ++++---- 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/Rocketeer/Commands/BaseDeployCommand.php b/src/Rocketeer/Commands/BaseDeployCommand.php index cc61a0003..b3e66a8a9 100644 --- a/src/Rocketeer/Commands/BaseDeployCommand.php +++ b/src/Rocketeer/Commands/BaseDeployCommand.php @@ -112,14 +112,14 @@ protected function getRepositoryCredentials() */ protected function getServerCredentials() { - if ($connection = $this->option('on')) { - $this->laravel['rocketeer.rocketeer']->setConnection($connection); + if ($connections = $this->option('on')) { + $this->laravel['rocketeer.rocketeer']->setConnections($connections); } // Check for configured connections $connections = $this->laravel['rocketeer.rocketeer']->getConnections(); $connectionName = $this->laravel['rocketeer.rocketeer']->getConnection(); - dd($connectionName); + if (is_null($connectionName)) { $connectionName = $this->ask('No connections have been set, please create one : (production)', 'production'); } @@ -132,13 +132,13 @@ protected function getServerCredentials() foreach ($credentials as $credential => $required) { ${$credential} = array_get($connection, $credential); if (!${$credential} and $required) { - ${$credential} = $this->ask('No '.$credential. ' is set for current connection, please provide one :'); + ${$credential} = $this->ask('No '.$credential. ' is set for [' .$connectionName. '], please provide one :'); } } // Get password or key if (!$password and !$key) { - $type = $this->ask('No password or SSH key is set for current connection, which would you use ? [key/password]'); + $type = $this->ask('No password or SSH key is set for [' .$connectionName. '], which would you use ? [key/password]'); if ($type == 'key') { $key = $this->ask('Please enter the full path to your key'); } else { diff --git a/src/Rocketeer/Rocketeer.php b/src/Rocketeer/Rocketeer.php index 006b73034..07a4460d6 100644 --- a/src/Rocketeer/Rocketeer.php +++ b/src/Rocketeer/Rocketeer.php @@ -194,9 +194,9 @@ public function getConnections() $default = $this->app['config']->get('remote.default'); // Remove invalid connections - $me = $this; - $connections = array_filter($connections, function($value) use ($me) { - return $me->isValidConnection($value); + $instance = $this; + $connections = array_filter($connections, function($value) use ($instance) { + return $instance->isValidConnection($value); }); // Return default if no active connection(s) set @@ -228,6 +228,20 @@ public function getConnection() return $this->connection; } + /** + * Set the active connections + * + * @param string|array $connections + */ + public function setConnections($connections) + { + if (!is_array($connections)) { + $connections = explode(',', $connections); + } + + $this->connections = $connections; + } + /** * Set the curent connection * diff --git a/src/Rocketeer/TasksQueue.php b/src/Rocketeer/TasksQueue.php index 6e7c910a6..7565769ca 100644 --- a/src/Rocketeer/TasksQueue.php +++ b/src/Rocketeer/TasksQueue.php @@ -155,7 +155,7 @@ public function execute($queue) */ public function on($connections, $queue) { - $this->app['config']->set('rocketeer::connections', $connections); + $this->app['rocketeer.rocketeer']->setConnections($connections); $queue = (array) $queue; $queue = $this->buildQueue($queue); diff --git a/tests/TasksQueueTest.php b/tests/TasksQueueTest.php index 37db36e62..e207345cf 100644 --- a/tests/TasksQueueTest.php +++ b/tests/TasksQueueTest.php @@ -209,10 +209,10 @@ public function testCanRunOnMultipleConnectionsViaOn() }); $this->assertEquals(array( - 'production - first', - 'production - second', 'staging - first', 'staging - second', + 'production - first', + 'production - second', ), $output); } } diff --git a/tests/meta/coverage.txt b/tests/meta/coverage.txt index 1902c37c3..e8ee0c2e9 100644 --- a/tests/meta/coverage.txt +++ b/tests/meta/coverage.txt @@ -1,19 +1,19 @@ Code Coverage Report - 2013-10-19 13:44:08 + 2013-10-19 13:56:15 Summary: Classes: 60.00% (12/20) - Methods: 87.70% (107/122) - Lines: 91.39% (573/627) + Methods: 87.80% (108/123) + Lines: 91.30% (577/632) \Rocketeer::Bash Methods: 100.00% (17/17) Lines: 93.52% (101/108) \Rocketeer::ReleasesManager Methods: 100.00% ( 9/ 9) Lines: 100.00% ( 22/ 22) \Rocketeer::Rocketeer - Methods: 100.00% (21/21) Lines: 98.91% ( 91/ 92) + Methods: 100.00% (22/22) Lines: 97.94% ( 95/ 97) \Rocketeer::Server Methods: 100.00% (10/10) Lines: 91.11% ( 41/ 45) \Rocketeer::TasksQueue From 6f8b8136a2e9c5436b97dbc59d2361b337821b5d Mon Sep 17 00:00:00 2001 From: Maxime Fabre Date: Sat, 19 Oct 2013 14:02:01 +0200 Subject: [PATCH 12/20] Fix PHP 5.3 compatiblity --- tests/TasksQueueTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TasksQueueTest.php b/tests/TasksQueueTest.php index e207345cf..abb74401b 100644 --- a/tests/TasksQueueTest.php +++ b/tests/TasksQueueTest.php @@ -204,7 +204,7 @@ public function testCanRunOnMultipleConnectionsViaOn() 'rocketeer::stages.stages' => array('first', 'second'), )); - $output = $this->tasksQueue()->on(['staging', 'production'], function($task) { + $output = $this->tasksQueue()->on(array('staging', 'production'), function($task) { return $task->rocketeer->getConnection(). ' - ' .$task->rocketeer->getStage(); }); From 332a918eeac63c2832fdef1a3486818894b9a48a Mon Sep 17 00:00:00 2001 From: Maxime Fabre Date: Sat, 19 Oct 2013 14:10:32 +0200 Subject: [PATCH 13/20] Don't run chmod if not permissions are set --- src/Rocketeer/Traits/Task.php | 17 ++++++++++++----- src/config/config.php | 1 + 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Rocketeer/Traits/Task.php b/src/Rocketeer/Traits/Task.php index 229d884a3..3add14cb6 100644 --- a/src/Rocketeer/Traits/Task.php +++ b/src/Rocketeer/Traits/Task.php @@ -209,27 +209,34 @@ public function share($file) */ public function setPermissions($folder) { + $commands = array(); + // Get path to folder $folder = $this->releasesManager->getCurrentReleasePath($folder); $this->command->comment('Setting permissions for '.$folder); // Get permissions options $options = $this->rocketeer->getOption('remote.permissions'); - $chmod = array_get($options, 'permissions', 775); + $chmod = array_get($options, 'permissions'); $user = array_get($options, 'apache.user'); $group = array_get($options, 'apache.group'); // Add chmod - $commands = array( - sprintf('chmod -R %s %s', $chmod, $folder), - sprintf('chmod -R g+s %s', $folder), - ); + if ($chmod) { + $commands[] = sprintf('chmod -R %s %s', $chmod, $folder); + $commands[] = sprintf('chmod -R g+s %s', $folder); + } // And chown if ($user and $group) { $commands[] = sprintf('chown -R %s:%s %s', $user, $group, $folder); } + // Cancel if setting of permissions is not configured + if (empty($commands)) { + return true; + } + return $this->runForCurrentRelease($commands); } diff --git a/src/config/config.php b/src/config/config.php index 2706f5867..830a5e73e 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -75,6 +75,7 @@ 'permissions' => array( // The permissions to CHMOD folders to + // Change to null to leave the folders untouched 'permissions' => 755, // The folders and files to set as web writable From 2b3d08ebdeb30e0aa57943d8310cfb28c40a4d2c Mon Sep 17 00:00:00 2001 From: Maxime Fabre Date: Sat, 19 Oct 2013 14:17:09 +0200 Subject: [PATCH 14/20] Fix wrong command call --- src/Rocketeer/Commands/BaseDeployCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Rocketeer/Commands/BaseDeployCommand.php b/src/Rocketeer/Commands/BaseDeployCommand.php index b3e66a8a9..a69136318 100644 --- a/src/Rocketeer/Commands/BaseDeployCommand.php +++ b/src/Rocketeer/Commands/BaseDeployCommand.php @@ -117,7 +117,7 @@ protected function getServerCredentials() } // Check for configured connections - $connections = $this->laravel['rocketeer.rocketeer']->getConnections(); + $connections = $this->laravel['rocketeer.rocketeer']->getAvailableConnections(); $connectionName = $this->laravel['rocketeer.rocketeer']->getConnection(); if (is_null($connectionName)) { From 80317e651ce497d2e19ecaec7f0f631692e8d401 Mon Sep 17 00:00:00 2001 From: Maxime Fabre Date: Sat, 19 Oct 2013 14:25:59 +0200 Subject: [PATCH 15/20] Use shallow git clone --- src/Rocketeer/Scm/Git.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Rocketeer/Scm/Git.php b/src/Rocketeer/Scm/Git.php index e679ef747..426103e94 100644 --- a/src/Rocketeer/Scm/Git.php +++ b/src/Rocketeer/Scm/Git.php @@ -65,7 +65,7 @@ public function checkout($destination) $branch = $this->app['rocketeer.rocketeer']->getRepositoryBranch(); $repository = $this->app['rocketeer.rocketeer']->getRepository(); - return sprintf($this->getCommand('clone -b %s %s %s'), $branch, $repository, $destination); + return sprintf($this->getCommand('clone --depth 1 -b %s %s %s'), $branch, $repository, $destination); } /** From a4fccddf83506452706254340e6d69df1db61699 Mon Sep 17 00:00:00 2001 From: Maxime Fabre Date: Sat, 19 Oct 2013 14:40:07 +0200 Subject: [PATCH 16/20] Fix Rollback default behaviour --- src/Rocketeer/Tasks/Rollback.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Rocketeer/Tasks/Rollback.php b/src/Rocketeer/Tasks/Rollback.php index d65464048..1c608e4cb 100644 --- a/src/Rocketeer/Tasks/Rollback.php +++ b/src/Rocketeer/Tasks/Rollback.php @@ -34,6 +34,11 @@ public function execute() */ protected function getRollbackRelease() { - return array_get($this->command->argument(), 'release', $this->releasesManager->getPreviousRelease()); + $release = $this->command->argument('release'); + if (!$release) { + $release = $this->releasesManager->getPreviousRelease(); + } + + return $release; } } From 0fc284725a6f02c96370b182fdd4c052c392f6ff Mon Sep 17 00:00:00 2001 From: Maxime Fabre Date: Sat, 19 Oct 2013 14:41:11 +0200 Subject: [PATCH 17/20] Add rollback --list option to pick from releases --- CHANGELOG.md | 3 ++- .../Commands/DeployRollbackCommand.php | 13 +++++++++++++ src/Rocketeer/Tasks/Rollback.php | 19 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b5879f3b..c7fc914c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,8 @@ - **Rocketeer can now have specific configurations for stages and connections** - **Better handling of multiple connections** - **Added facade shortcuts `Rocketeer::execute(Task)` and `Rocketeer::on(connection[s], Task)` to execute commands on the remote servers** -- Added the `--on` flag to all commands to specify which connections the task should be executed on +- Added the `--list` flag on the `rollback` command to show a list of available releases and pick one to rollback to +- Added the `--on` flag to all commands to specify which connections the task should be executed on (ex. `production`, `staging,production`) - Added `deploy:flush` to clear Rocketeer's cache of credentials ### 0.7.0 (stable) diff --git a/src/Rocketeer/Commands/DeployRollbackCommand.php b/src/Rocketeer/Commands/DeployRollbackCommand.php index 228031b41..eb7688877 100644 --- a/src/Rocketeer/Commands/DeployRollbackCommand.php +++ b/src/Rocketeer/Commands/DeployRollbackCommand.php @@ -1,6 +1,7 @@ getRollbackRelease(); + // If no release specified, display the available ones + if ($this->command->option('list')) { + $releases = $this->releasesManager->getReleases(); + $this->command->info('Here are the available releases :'); + + foreach ($releases as $key => $name) { + $name = DateTime::createFromFormat('YmdHis', $name); + $name = $name->format('Y-m-d H:i:s'); + + $this->command->comment(sprintf('[%d] %s', $key, $name)); + } + + // Get actual release name from date + $rollbackRelease = $this->command->ask('Which one do you want to go back to ? (0)', 0); + $rollbackRelease = $releases[$rollbackRelease]; + } + + // Rollback release $this->command->info('Rolling back to release '.$rollbackRelease); $this->updateSymlink($rollbackRelease); From d9a6ef5f98e80d854d974cea42b5ed192de0a428 Mon Sep 17 00:00:00 2001 From: Maxime Fabre Date: Sat, 19 Oct 2013 14:41:45 +0200 Subject: [PATCH 18/20] Code tweaks --- src/Rocketeer/Rocketeer.php | 2 +- src/Rocketeer/RocketeerServiceProvider.php | 4 ++-- tests/Tasks/IgniteTest.php | 2 +- tests/Tasks/TeardownTest.php | 2 +- tests/TasksQueueTest.php | 6 +++--- tests/meta/coverage.txt | 12 ++++++------ 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Rocketeer/Rocketeer.php b/src/Rocketeer/Rocketeer.php index 07a4460d6..de398789e 100644 --- a/src/Rocketeer/Rocketeer.php +++ b/src/Rocketeer/Rocketeer.php @@ -195,7 +195,7 @@ public function getConnections() // Remove invalid connections $instance = $this; - $connections = array_filter($connections, function($value) use ($instance) { + $connections = array_filter($connections, function ($value) use ($instance) { return $instance->isValidConnection($value); }); diff --git a/src/Rocketeer/RocketeerServiceProvider.php b/src/Rocketeer/RocketeerServiceProvider.php index 61bc23a15..1cd251588 100644 --- a/src/Rocketeer/RocketeerServiceProvider.php +++ b/src/Rocketeer/RocketeerServiceProvider.php @@ -103,7 +103,7 @@ public function bindCoreClasses(Container $app) return new Repository($fileloader, 'config'); }, true); - $app->bindIf('remote', function($app) { + $app->bindIf('remote', function ($app) { return new RemoteManager($app); }, true); @@ -269,7 +269,7 @@ protected function registerConfig(Container $app) // Register custom config $custom = $app['path.base'].'/rocketeer.php'; if (file_exists($custom)) { - $app['config']->afterLoading('rocketeer', function($me, $group, $items) use ($custom) { + $app['config']->afterLoading('rocketeer', function ($me, $group, $items) use ($custom) { $custom = include $custom; return array_replace_recursive($items, $custom); }); diff --git a/tests/Tasks/IgniteTest.php b/tests/Tasks/IgniteTest.php index 3df3ec627..af0dc906c 100644 --- a/tests/Tasks/IgniteTest.php +++ b/tests/Tasks/IgniteTest.php @@ -27,7 +27,7 @@ public function testCanIgniteConfigurationInLaravel() $root = $this->app['path.base'].'/rocketeer.php'; $command = $this->getCommand(); - $command->shouldReceive('call')->with('config:publish', array('package' => 'anahkiasen/rocketeer'))->andReturnUsing(function() use ($root) { + $command->shouldReceive('call')->with('config:publish', array('package' => 'anahkiasen/rocketeer'))->andReturnUsing(function () use ($root) { file_put_contents($root, 'foobar'); }); diff --git a/tests/Tasks/TeardownTest.php b/tests/Tasks/TeardownTest.php index d00cd66d7..6d896eb20 100644 --- a/tests/Tasks/TeardownTest.php +++ b/tests/Tasks/TeardownTest.php @@ -14,7 +14,7 @@ public function testCanAbortTeardown() { $command = Mockery::mock('Command');; $command->shouldReceive('confirm')->andReturn(false); - $command->shouldReceive('info')->andReturnUsing(function($message) { return $message; }); + $command->shouldReceive('info')->andReturnUsing(function ($message) { return $message; }); $message = $this->task('Teardown', $command)->execute(); diff --git a/tests/TasksQueueTest.php b/tests/TasksQueueTest.php index abb74401b..e31962eeb 100644 --- a/tests/TasksQueueTest.php +++ b/tests/TasksQueueTest.php @@ -163,7 +163,7 @@ public function testCanRunQueueOnDifferentConnectionsAndStages() $output = array(); $queue = array( - function($task) use (&$output) { + function ($task) use (&$output) { $output[] = $task->rocketeer->getConnection(). ' - ' .$task->rocketeer->getStage(); } ); @@ -187,7 +187,7 @@ public function testCanRunQueueViaExecute() $output = $this->tasksQueue()->execute(array( 'ls -a', - function($task) { + function ($task) { return 'JOEY DOESNT SHARE FOOD'; } )); @@ -204,7 +204,7 @@ public function testCanRunOnMultipleConnectionsViaOn() 'rocketeer::stages.stages' => array('first', 'second'), )); - $output = $this->tasksQueue()->on(array('staging', 'production'), function($task) { + $output = $this->tasksQueue()->on(array('staging', 'production'), function ($task) { return $task->rocketeer->getConnection(). ' - ' .$task->rocketeer->getStage(); }); diff --git a/tests/meta/coverage.txt b/tests/meta/coverage.txt index e8ee0c2e9..f3578deff 100644 --- a/tests/meta/coverage.txt +++ b/tests/meta/coverage.txt @@ -1,12 +1,12 @@ Code Coverage Report - 2013-10-19 13:56:15 + 2013-10-19 14:41:47 Summary: - Classes: 60.00% (12/20) - Methods: 87.80% (108/123) - Lines: 91.30% (577/632) + Classes: 55.00% (11/20) + Methods: 86.18% (106/123) + Lines: 89.88% (586/652) \Rocketeer::Bash Methods: 100.00% (17/17) Lines: 93.52% (101/108) @@ -33,7 +33,7 @@ Code Coverage Report \Rocketeer\Tasks::Ignite Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 8/ 8) \Rocketeer\Tasks::Rollback - Methods: 100.00% ( 2/ 2) Lines: 100.00% ( 5/ 5) + Methods: 100.00% ( 2/ 2) Lines: 50.00% ( 10/ 20) \Rocketeer\Tasks::Setup Methods: 100.00% ( 2/ 2) Lines: 88.89% ( 24/ 27) \Rocketeer\Tasks::Teardown @@ -45,4 +45,4 @@ Code Coverage Report \Rocketeer\Traits::Scm Methods: 100.00% ( 3/ 3) Lines: 100.00% ( 7/ 7) \Rocketeer\Traits::Task - Methods: 93.75% (15/16) Lines: 95.83% ( 69/ 72) + Methods: 93.75% (15/16) Lines: 94.81% ( 73/ 77) From 946ce1ebbed75ba68b6e88022c40bd0faa014ec8 Mon Sep 17 00:00:00 2001 From: Maxime Fabre Date: Sat, 19 Oct 2013 14:43:56 +0200 Subject: [PATCH 19/20] Add some tests --- tests/RocketeerTest.php | 3 +++ tests/meta/coverage.txt | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/RocketeerTest.php b/tests/RocketeerTest.php index 96b00333f..51434cbb5 100644 --- a/tests/RocketeerTest.php +++ b/tests/RocketeerTest.php @@ -34,6 +34,9 @@ public function testCanChangeConnection() $this->app['rocketeer.rocketeer']->setConnection('staging'); $this->assertEquals('staging', $this->app['rocketeer.rocketeer']->getConnection()); + + $this->app['rocketeer.rocketeer']->setConnections('staging,production'); + $this->assertEquals(array('staging', 'production'), $this->app['rocketeer.rocketeer']->getConnections()); } public function testCanUseSshRepository() diff --git a/tests/meta/coverage.txt b/tests/meta/coverage.txt index f3578deff..109488dfd 100644 --- a/tests/meta/coverage.txt +++ b/tests/meta/coverage.txt @@ -1,19 +1,19 @@ Code Coverage Report - 2013-10-19 14:41:47 + 2013-10-19 14:44:37 Summary: - Classes: 55.00% (11/20) - Methods: 86.18% (106/123) - Lines: 89.88% (586/652) + Classes: 60.00% (12/20) + Methods: 86.99% (107/123) + Lines: 90.18% (588/652) \Rocketeer::Bash Methods: 100.00% (17/17) Lines: 93.52% (101/108) \Rocketeer::ReleasesManager Methods: 100.00% ( 9/ 9) Lines: 100.00% ( 22/ 22) \Rocketeer::Rocketeer - Methods: 100.00% (22/22) Lines: 97.94% ( 95/ 97) + Methods: 100.00% (22/22) Lines: 100.00% ( 97/ 97) \Rocketeer::Server Methods: 100.00% (10/10) Lines: 91.11% ( 41/ 45) \Rocketeer::TasksQueue From b0248edfdf01993d3fe13f1591cc847a4641e9f6 Mon Sep 17 00:00:00 2001 From: Maxime Fabre Date: Sat, 19 Oct 2013 15:06:09 +0200 Subject: [PATCH 20/20] Bump version --- CHANGELOG.md | 4 ++-- src/Rocketeer/Rocketeer.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7fc914c1..23b838bf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ### Changelog -### 0.8.0 (develop) +### 0.8.0 - **Rocketeer can now have specific configurations for stages and connections** - **Better handling of multiple connections** @@ -9,7 +9,7 @@ - Added the `--on` flag to all commands to specify which connections the task should be executed on (ex. `production`, `staging,production`) - Added `deploy:flush` to clear Rocketeer's cache of credentials -### 0.7.0 (stable) +### 0.7.0 - **Rocketeer can now work outside of Laravel** - **Better handling of SSH keys** diff --git a/src/Rocketeer/Rocketeer.php b/src/Rocketeer/Rocketeer.php index de398789e..e7920a816 100644 --- a/src/Rocketeer/Rocketeer.php +++ b/src/Rocketeer/Rocketeer.php @@ -43,7 +43,7 @@ class Rocketeer * * @var string */ - const VERSION = '0.7.0'; + const VERSION = '0.8.0'; /** * Build a new ReleasesManager