Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
REBELinBLUE committed Nov 15, 2015
2 parents 73920fb + b5e8b98 commit fbf84f1
Show file tree
Hide file tree
Showing 10 changed files with 294 additions and 258 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,20 @@ The `master` branch of this repository is a development branch and **should not*
$ npm install --production
```

4. Run the installer and follow the instructions
4. Make sure the storage and upload directories are writable

```shell
$ chmod -R 777 storage
$ chmod -R 777 public/upload
```

5. Run the installer and follow the instructions

```shell
$ php artisan app:install
```

5. (Optional) Make any additional configuration changes
6. (Optional) Make any additional configuration changes

```shell
$ editor .env
Expand Down
6 changes: 4 additions & 2 deletions app/Console/Commands/InstallApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,11 @@ public function handle()
$this->line('');
$this->comment('3. Setup the socket server and queue runner, see "supervisor.conf" for an example of how to do this with supervisor');
$this->line('');
$this->comment('4. (Optional) Setup logrotate, see "logrotate.conf"');
$this->comment('4. Ensure that "storage" and "public/upload" are writable by the webserver, for example run "chmod -R 777 storage"');
$this->line('');
$this->comment('5. Visit ' . $config['app']['url'] . ' and login with the details you provided to get started');
$this->comment('5. (Optional) Setup logrotate, see "logrotate.conf"');
$this->line('');
$this->comment('6. Visit ' . $config['app']['url'] . ' and login with the details you provided to get started');
$this->line('');
}

Expand Down
14 changes: 0 additions & 14 deletions app/Deployment.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,18 +318,4 @@ public function getRepoFailureAttribute()
{
return ($this->commit === self::LOADING && $this->status === self::FAILED);
}

/**
* A little hack to reconnect to the database if we're in console mode and trying to find a deployment.
* Should fix the error sending STMT_PREPARE problem that causes deployments to sit "pending" forever.
* @return mixed
*/
public function findOrFail()
{
if (App::runningInConsole()) {
DB::reconnect();
}

return parent::__call('findOrFail', func_get_args());
}
}
51 changes: 33 additions & 18 deletions app/Http/Controllers/WebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,43 @@ public function webhook($hash)

$success = false;
if ($project->servers->where('deploy_code', true)->count() > 0) {
$optional = [];
// Get the branch if it is the rquest, otherwise deploy the default branch
$branch = Input::has('branch') ? Input::get('branch') : $project->branch;

// Check if the commands input is set, if so explode on comma and filter out any invalid commands
if (Input::has('commands')) {
$valid = $project->commands->lists('id');
$do_deploy = true;
if (Input::has('update_only') && Input::get('update_only') === 'true') {
// Get the latest deployment and check the branch matches
$deployment = $this->deploymentRepository->getLatestSuccessful($project->id);

$optional = collect(explode(',', Input::get('commands')))
->unique()
->intersect($valid);
if (!$deployment || $deployment->branch !== $branch) {
$do_deploy = false;
}
}

// TODO: Validate URL and only accept it if source is set?
$this->deploymentRepository->create([
'reason' => Input::get('reason'),
'project_id' => $project->id,
'branch' => $project->branch,
'optional' => $optional,
'source' => Input::get('source'),
'build_url' => Input::get('url'),
]);

$success = true;
if ($do_deploy) {
$optional = [];

// Check if the commands input is set, if so explode on comma and filter out any invalid commands
if (Input::has('commands')) {
$valid = $project->commands->lists('id');

$optional = collect(explode(',', Input::get('commands')))
->unique()
->intersect($valid);
}

// TODO: Validate URL and only accept it if source is set?
$this->deploymentRepository->create([
'reason' => Input::get('reason'),
'project_id' => $project->id,
'branch' => $branch,
'optional' => $optional,
'source' => Input::get('source'),
'build_url' => Input::get('url'),
]);

$success = true;
}
}

return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface DeploymentRepositoryInterface
public function create(array $fields);
public function getById($model_id);
public function getLatest($project_id, $paginate = 15);
public function getLatestSuccessful($project_id);
public function getTimeline();
public function getTodayCount($project_id);
public function getLastWeekCount($project_id);
Expand Down
21 changes: 20 additions & 1 deletion app/Repositories/EloquentDeploymentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function create(array $fields)

$deployment = $this->model->create($fields);

// FIXME: Catch an erorr here and rollback model if it fails
$this->dispatch(new QueueDeployment(
$deployment->project,
$deployment,
Expand All @@ -55,18 +56,34 @@ public function create(array $fields)
/**
* Gets the latest deployments for a project.
*
* @param int $project
* @param int $project_id
* @param int $paginate
* @return array
*/
public function getLatest($project_id, $paginate = 15)
{
return $this->model->where('project_id', $project_id)
->with('user', 'project')
->whereNotNull('started_at')
->orderBy('started_at', 'DESC')
->paginate($paginate);
}

/**
* Get the latest successful deployment for a project.
*
* @param int $project_id
* @return array
*/
public function getLatestSuccessful($project_id)
{
return $this->model->where('project_id', $project_id)
->where('status', Deployment::COMPLETED)
->whereNotNull('started_at')
->orderBy('started_at', 'DESC')
->first();
}

/**
* Gets the latest deployments for all projects.
*
Expand All @@ -77,6 +94,7 @@ public function getTimeline()
$raw_sql = 'project_id IN (SELECT id FROM projects WHERE deleted_at IS NULL)';

return $this->model->whereRaw($raw_sql)
->whereNotNull('started_at')
->with('project')
->take(15)
->orderBy('started_at', 'DESC')
Expand Down Expand Up @@ -160,6 +178,7 @@ private function getStatus($status)

return $this->model->whereRaw($raw_sql)
->where('status', $status)
->whereNotNull('started_at')
->orderBy('started_at', 'DESC')
->get();
}
Expand Down
Loading

0 comments on commit fbf84f1

Please sign in to comment.