Skip to content

Commit

Permalink
Merge pull request #20 from REBELinBLUE/deploy_from_branch
Browse files Browse the repository at this point in the history
Allowing deploying specific tags and branches
  • Loading branch information
REBELinBLUE committed May 13, 2015
2 parents d4fff7f + c1f67ce commit 48d3d84
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 36 deletions.
8 changes: 4 additions & 4 deletions app/Commands/DeployProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ private function updateRepoInfo()

$process = new Process(sprintf(
$cmd,
$this->deployment->project->branch,
$this->deployment->branch,
$this->deployment->project->repository,
$this->deployment->project->branch
$this->deployment->branch
));

$process->setTimeout(null);
Expand Down Expand Up @@ -298,12 +298,12 @@ private function getScript(DeployStep $step, Server $server)
sprintf('export GIT_SSH="%s"', $remote_wrapper_file),
sprintf(
'git clone --branch %s --depth 1 --recursive %s %s',
$project->branch,
$this->deployment->branch,
$project->repository,
$latest_release_dir
),
sprintf('cd %s', $latest_release_dir),
sprintf('git checkout %s', $project->branch),
sprintf('git checkout %s', $this->deployment->branch),
sprintf('rm %s %s', $remote_key_file, $remote_wrapper_file)
];
} elseif ($step->stage === Stage::DO_INSTALL) { // Install composer dependencies
Expand Down
20 changes: 19 additions & 1 deletion app/Deployment.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function notificationPayload()
'value' => $this->committer,
'short' => true
], [
'title' => Lang::get('notifications.branch'),
'title' => Lang::get('notifications.proanch'),
'value' => $this->project->branch,
'short' => true
]
Expand All @@ -180,4 +180,22 @@ public function getPresenter()
{
return new DeploymentPresenter($this);
}

/**
* Gets the HTTP URL to the branch
*
* @return string|false
* @see \App\Project::accessDetails()
* @todo Should this be an attribute?
*/
public function branchURL()
{
$info = $this->project->accessDetails();

if (isset($info['domain']) && isset($info['reference'])) {
return 'http://' . $info['domain'] . '/' . $info['reference'] . '/tree/' . $this->branch;
}

return false;
}
}
8 changes: 8 additions & 0 deletions app/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ public function deploy(Project $project)
$deployment = new Deployment;
$deployment->reason = Input::get('reason');

if (Input::has('source') && Input::has('source_' . Input::get('source'))) {
$deployment->branch = Input::get('source_' . Input::get('source'));
}

if (empty($deployment->branch)) {
$deployment->branch = $project->branch;
}

$optional = [];

if (Input::has('optional')) {
Expand Down
37 changes: 37 additions & 0 deletions database/migrations/2015_05_13_121650_set_deployment_branch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

use App\Deployment;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class SetDeploymentBranch extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('deployments', function (Blueprint $table) {
$table->string('branch')->default('master');
});

foreach (Deployment::all() as $deployment) {
$deployment->branch = $deployment->project->branch;
$deployment->save();
}
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('deployments', function (Blueprint $table) {
$table->dropColumn('branch');
});
}
}
4 changes: 4 additions & 0 deletions resources/assets/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,8 @@ body.dragging * {
/* Make sure there is always a space between the icon and the label as HTMLMin removes it */
span.label i.fa {
margin-right: 2px;
}

input[type=text].deployment-source {
display: none;
}
30 changes: 29 additions & 1 deletion resources/assets/js/projects.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
var app = app || {};

(function ($) {
$('.deployment-source:radio').on('change', function (event) {
var target = $(event.currentTarget);

$('input[type=text].deployment-source').hide();
if (target.val() === 'branch') {
$('#deployment_branch').show();
} else if (target.val() === 'tag') {
$('#deployment_tag').show();
}
});

$('#reason').on('show.bs.modal', function (event) {
var modal = $(this);
$('.callout-danger', modal).hide();
});

$('#reason button').on('click', function (event) {
$('#reason button.btn-save').on('click', function (event) {
var target = $(event.currentTarget);
var icon = target.find('i');
var dialog = target.parents('.modal');
var source = $('input[name=source]:checked').val();

$('.has-error', source).removeClass('has-error');

if (source === 'branch' || source === 'tag') {
if ($('#deployment_' + source).val() === '') {
$('#deployment_' + source).parentsUntil('div').addClass('has-error');

$('.callout-danger', dialog).show();
event.stopPropagation();
return;
}
}

icon.addClass('fa-refresh fa-spin').removeClass('fa-save');
$('button.close', dialog).hide();
Expand Down
64 changes: 35 additions & 29 deletions resources/lang/en/deployments.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,40 @@

return [

'label' => 'Deployments',
'latest' => 'Latest Deployments',
'none' => 'There have not been any deployments yet.',
'started' => 'Started',
'deployer' => 'Deployer',
'committer' => 'Committer',
'commit' => 'Commit',
'manually' => 'Manually',
'webhook' => 'Webhook',
'reactivate' => 'Re-activate',
'loading' => 'Loading',
'process' => 'Process Output',
'server' => 'Server',
'status' => 'Status',
'started' => 'Started',
'finished' => 'Finished',
'duration' => 'Duration',
'output' => 'View the output',
'details' => 'Deployment Details',
'pending' => 'Pending',
'deploying' => 'Deploying',
'completed' => 'Completed',
'failed' => 'Failed',
'running' => 'Running',
'cancelled' => 'Cancelled',
'loading' => 'Loading',
'reason' => 'Reason for deployment',
'describe_reason' => 'Please describe briefly the reason for this deployment',
'optional' => 'Select the optional deploy steps to run'
'label' => 'Deployments',
'latest' => 'Latest Deployments',
'none' => 'There have not been any deployments yet.',
'started' => 'Started',
'deployer' => 'Deployer',
'committer' => 'Committer',
'commit' => 'Commit',
'manually' => 'Manually',
'webhook' => 'Webhook',
'reactivate' => 'Re-activate',
'loading' => 'Loading',
'process' => 'Process Output',
'server' => 'Server',
'status' => 'Status',
'started' => 'Started',
'finished' => 'Finished',
'duration' => 'Duration',
'output' => 'View the output',
'details' => 'Deployment Details',
'pending' => 'Pending',
'deploying' => 'Deploying',
'completed' => 'Completed',
'failed' => 'Failed',
'running' => 'Running',
'cancelled' => 'Cancelled',
'loading' => 'Loading',
'reason' => 'Reason for deployment',
'source' => 'Source',
'default' => 'Default branch (:branch)',
'different_branch' => 'A different branch',
'tag' => 'A tag',
'branch' => 'Branch',
'warning' => 'The deployment could not be started, please make sure you have entered all required values.',
'describe_reason' => 'Please describe briefly the reason for this deployment',
'optional' => 'Select the optional deploy steps to run'

];
2 changes: 1 addition & 1 deletion resources/lang/en/projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'group' => 'Group',
'repository' => 'Repository',
'builds' => 'Builds to keep',
'branch' => 'Branch',
'branch' => 'Default Branch',
'image' => 'Build Image',
'latest' => 'Latest Deploy',
'create' => 'Add a new project',
Expand Down
34 changes: 34 additions & 0 deletions resources/views/dialogs/reason.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,40 @@
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
<input type="hidden" name="project_id" value="{{ $project->id }}" />
<div class="modal-body">

<div class="callout callout-danger">
<i class="icon fa fa-warning"></i> {{ Lang::get('deployments.warning') }}
</div>

<div class="form-group">
<label for="deployment_source">{{ Lang::get('deployments.source') }}</label>
<ul class="list-unstyled">
<li>
<div class="checkbox">
<label for="deployment_source_default">
<input type="radio" class="deployment-source" name="source" id="deployment_source_default" value="{{ $project->branch }}" checked /> {{ Lang::get('deployments.default', [ 'branch' => $project->branch ]) }}
</label>
</div>
</li>
<li>
<div class="checkbox">
<label for="deployment_source_branch">
<input type="radio" class="deployment-source" name="source" id="deployment_source_branch" value="branch" /> {{ Lang::get('deployments.branch') }}
<input type="text" class="form-control deployment-source" name="source_branch" id="deployment_branch" placeholder="master" />
</label>
</div>
</li>
<li>
<div class="checkbox">
<label for="deployment_source_tag">
<input type="radio" class="deployment-source" name="source" id="deployment_source_tag" value="tag" /> {{ Lang::get('deployments.tag') }}
<input type="text" class="form-control deployment-source" name="source_tag" id="deployment_tag" placeholder="1.0.0" />
</label>
</div>
</li>
</ul>
</div>
<hr />
<div class="form-group">
<label for="deployment_reason">{{ Lang::get('deployments.describe_reason') }}</label>
<textarea rows="10" id="deployment_reason" class="form-control" name="reason" placeholder="For example, Allows users to reset their password"></textarea>
Expand Down
3 changes: 3 additions & 0 deletions resources/views/projects/_partials/deployments.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<th>{{ Lang::get('deployments.deployer') }}</th>
<th>{{ Lang::get('deployments.committer') }}</th>
<th>{{ Lang::get('deployments.commit') }}</th>
<th>{{ Lang::get('deployments.branch') }}</th>
<th>{{ Lang::get('app.status') }}</th>
<th>&nbsp;</th>
</tr>
Expand Down Expand Up @@ -45,6 +46,8 @@
@else
{{ $deployment->short_commit_hash }}
@endif
</td>
<td><a href="{{ $deployment->branchURL() }}" target="_blank"><span class="label label-default">{{ $deployment->branch }}</span></a></td>
<td>
<span class="label label-{{ $deployment->css_class }}"><i class="fa fa-{{ $deployment->icon }}"></i> {{ $deployment->readable_status }}</span>
</td>
Expand Down

0 comments on commit 48d3d84

Please sign in to comment.