Skip to content
This repository has been archived by the owner on Sep 5, 2020. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Anahkiasen committed Jul 16, 2013
2 parents 4be13e3 + 7525afd commit aad5747
Show file tree
Hide file tree
Showing 24 changed files with 267 additions and 159 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@

- Ability to select which severs a Task executes on, on a per-task basis

### 0.6.3 (stable)
### 0.6.4 (stable)

- Make the output of commands in realtime when `--verbose` instead of when the command is done
- Fix a bug where custom Task classes would be analyzed as string commands
- Fix Rocketeeer not taking into account custom paths to **app/**, **storage/**, **public/** etc.
- Reverse sluggification of application name

### 0.6.3

- Application name is now always sluggified as a security
- Fix a bug where the Check task would fail on pretend mode
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ deploy
deploy:rollback {release} Rollback to a specific release
deploy:setup Set up the remote server for deployment
deploy:teardown Remove the remote applications and existing caches
deploy:test Run the tests on the server and displays the ouput
deploy:test Run the tests on the server and displays the output
deploy:update Update the remote server without doing a new release
```

## Tasks

An important concept in Rocketeer is Tasks : most of the commands you see right above are using predefined Tasks underneath : **Rocketeer\Tasks\Setup**, **Rocketeer\Tasks\Deploy**, etc.
Now, the core of Rocketeer is you can hook into any of those Tasks to peform additional actions, for this you'll use the `before` and `after` arrays of Rocketeer's config file.
Now, the core of Rocketeer is you can hook into any of those Tasks to perform additional actions, for this you'll use the `before` and `after` arrays of Rocketeer's config file.

You can read more about Tasks and what you can do with them [in the wiki](https://github.com/Anahkiasen/rocketeer/wiki/Tasks).

Expand All @@ -38,4 +38,10 @@ That's a question that's been asked to me, why not simply use Capistrano ? I've
But, it remains a Ruby package and one that's tightly coupled to Rails in some ways; Rocketeer makes it so that you don't have Ruby files hanging around your app. That way you configure it once and can use it wherever you want in the realm of Laravel, even outside of the deploy routine.
It's also meant to be a lot easier to comprehend, for first-time users or novices, Capistrano is a lot to take at once – Rocketeer aims to be as simple as possible by providing smart defaults and speeding up the time between installing it and first hitting `deploy`.

It's also more thought out for the PHP world – although you can configure Capistrano to run Composer and PHPUnit, that's not something it expects from the get go, while those tasks that are a part of every Laravel developper are integrated in Rocketeer's core deploy process.
It's also more thought out for the PHP world – although you can configure Capistrano to run Composer and PHPUnit, that's not something it expects from the get go, while those tasks that are a part of every Laravel developer are integrated in Rocketeer's core deploy process.

## Table of contents

- **[Getting Started](https://github.com/Anahkiasen/rocketeer/wiki/Getting-started)**
- **[Tasks](https://github.com/Anahkiasen/rocketeer/wiki/Tasks)**
- **[Architecture](https://github.com/Anahkiasen/rocketeer/wiki/Architecture)**
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs
Submodule docs updated from b9c05e to a56149
160 changes: 81 additions & 79 deletions src/Rocketeer/Bash.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@

use Illuminate\Console\Command;
use Illuminate\Container\Container;
use Illuminate\Remote\Connection;
use Illuminate\Support\Str;

/**
* An helper to execute commands on the remote server
* An helper to execute low-level commands on the remote server
*
* @property ReleasesManager $releasesManager
* @property Rocketeer $rocketeer
* @property Server $server
* @property Illuminate\Remote\Connection $remote
* @property Traits\Scm $scm
*/
class Bash
{
Expand All @@ -19,41 +24,6 @@ class Bash
*/
protected $app;

/**
* The Releases Manager instance
*
* @var ReleasesManager
*/
public $releasesManager;

/**
* The Server instance
*
* @var Server
*/
public $server;

/**
* The SCM
*
* @var Scm
*/
public $scm;

/**
* The Rocketeer instance
*
* @var Rocketeer
*/
public $rocketeer;

/**
* The Remote instance
*
* @var Connection
*/
public $remote;

/**
* The Command instance
*
Expand All @@ -69,13 +39,32 @@ class Bash
*/
public function __construct(Container $app, $command = null)
{
$this->app = $app;
$this->releasesManager = $app['rocketeer.releases'];
$this->server = $app['rocketeer.server'];
$this->rocketeer = $app['rocketeer.rocketeer'];
$this->scm = $app['rocketeer.scm'];
$this->remote = $app['remote'];
$this->command = $command;
$this->app = $app;
$this->command = $command;
}

/**
* Get an instance from the Container
*
* @param string $key
*
* @return object
*/
public function __get($key)
{
$shortcuts = array(
'releasesManager' => 'rocketeer.releases',
'server' => 'rocketeer.server',
'rocketeer' => 'rocketeer.rocketeer',
'scm' => 'rocketeer.scm',
);

// Replace shortcuts
if (array_key_exists($key, $shortcuts)) {
$key = $shortcuts[$key];
}

return $this->app[$key];
}

////////////////////////////////////////////////////////////////////
Expand All @@ -93,7 +82,10 @@ public function __construct(Container $app, $command = null)
*/
public function run($commands, $silent = false, $array = false)
{
$me = $this;
$output = null;
$commands = $this->processCommands($commands);
$verbose = $this->getOption('verbose') and !$silent;

// Log the commands for pretend
if ($this->getOption('pretend') and !$silent) {
Expand All @@ -103,13 +95,50 @@ public function run($commands, $silent = false, $array = false)
return $commands;
}

// Get output
$output = $this->runRemoteCommands($commands, $array);
$output = is_array($output) ? array_filter($output) : trim($output);
// Run commands
$this->remote->run($commands, function ($results) use (&$output, $verbose, $me) {
$output .= $results;

if ($verbose) {
$me->remote->display(trim($results));
}
});

// Explode output if necessary
if ($array) {
$output = explode($this->server->getLineEndings(), $output);
}

// Trim output
$output = is_array($output)
? array_filter($output)
: trim($output);

return $output;
}

/**
* Run a raw command, without any processing, and
* get its output as a string or array
*
* @param string|array $commands
* @param boolean $array Whether the output should be returned as an array
*
* @return string
*/
public function runRaw($commands, $array = false)
{
$output = null;

// Run commands
$this->remote->run($commands, function ($results) use (&$output) {
$output .= $results;
});

// Print if necessary
if ($this->getOption('verbose') and !$silent) {
print is_array($output) ? implode(PHP_EOL, $output) : $output;
// Explode output if necessary
if ($array) {
$output = explode($this->server->getLineEndings(), $output);
$output = array_filter($output);
}

return $output;
Expand Down Expand Up @@ -244,9 +273,9 @@ public function listContents($directory)
*/
public function fileExists($file)
{
$exists = $this->run('if [ -e ' .$file. ' ]; then echo "true"; fi', true);
$exists = $this->runRaw('if [ -e ' .$file. ' ]; then echo "true"; fi');

return $exists == 'true';
return trim($exists) == 'true';
}

/**
Expand Down Expand Up @@ -280,33 +309,6 @@ public function removeFolder($folder = null)
/////////////////////////////// HELPERS ////////////////////////////
////////////////////////////////////////////////////////////////////

/**
* Run a raw command, without any processing, and
* get its output as a string or array
*
* @param string|array $commands
* @param boolean $array Whether the output should be returned as an array
*
* @return string
*/
public function runRemoteCommands($commands, $array = false)
{
$output = null;

// Run commands
$this->remote->run($commands, function ($results) use (&$output) {
$output .= $results;
});

// Explode output if necessary
if ($array) {
$output = explode($this->server->getLineEndings(), $output);
$output = array_filter($output);
}

return $output;
}

/**
* Get an option from the Command
*
Expand Down
3 changes: 2 additions & 1 deletion src/Rocketeer/Commands/DeployTestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DeployTestCommand extends BaseDeployCommand
*
* @var string
*/
protected $description = 'Run the tests on the server and displays the ouput';
protected $description = 'Run the tests on the server and displays the output';

/**
* The tasks to execute
Expand All @@ -29,6 +29,7 @@ class DeployTestCommand extends BaseDeployCommand
public function fire()
{
$this->input->setOption('verbose', true);

return $this->fireTasksQueue('Rocketeer\Tasks\Test');
}
}
8 changes: 5 additions & 3 deletions src/Rocketeer/ReleasesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,15 @@ public function getCurrentRelease()
/**
* Get the release before the current one
*
* @param string $release A release name
*
* @return string
*/
public function getPreviousRelease()
public function getPreviousRelease($release = null)
{
// Get all releases and the current one
$releases = $this->getReleases();
$current = $this->getCurrentRelease();
$current = $release ?: $this->getCurrentRelease();

// Get the one before that, or default to current
$key = array_search($current, $releases);
Expand All @@ -128,7 +130,7 @@ public function getPreviousRelease()
/**
* Update the current release
*
* @param string $release
* @param string $release A release name
*
* @return void
*/
Expand Down
Loading

0 comments on commit aad5747

Please sign in to comment.