Skip to content

Commit

Permalink
Adding environmental variables for #133 and #108
Browse files Browse the repository at this point in the history
  • Loading branch information
REBELinBLUE committed Dec 31, 2015
1 parent 3b56b60 commit e2d12c0
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/Jobs/DeployProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,15 @@ private function getScript(DeployStep $step, Server $server)
$commands = implode(PHP_EOL, $commands);
}

return $commands;
$variables = '';
foreach($project->variables as $variable) {
$key = $variable->name;
$value = $variable->value;

$variables .= "export {$key}={$value}" . PHP_EOL;
}

return $variables . $commands;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions app/ProjectRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ public function commands()
return $this->hasMany('REBELinBLUE\Deployer\Command')->orderBy('order', 'ASC');
}

/**
* Has many relationship.
*
* @return Variable
*/
public function variables()
{
return $this->hasMany('REBELinBLUE\Deployer\Variable');
}

/**
* Has many relationship.
*
Expand Down
37 changes: 37 additions & 0 deletions app/Variable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace REBELinBLUE\Deployer;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use REBELinBLUE\Deployer\Traits\BroadcastChanges;


class Variable extends Model
{
use SoftDeletes, BroadcastChanges;

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['name', 'value', 'project_id'];

/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = ['created_at', 'updated_at', 'deleted_at'];

/**
* Belongs to relationship.
*
* @return Project
*/
public function project()
{
return $this->belongsTo('REBELinBLUE\Deployer\Project');
}
}
35 changes: 35 additions & 0 deletions database/migrations/2015_12_31_144850_create_variables_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

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

class CreateVariablesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('variables', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('value');
$table->unsignedInteger('project_id');
$table->timestamps();
$table->softDeletes();
$table->foreign('project_id')->references('id')->on('projects');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('variables');
}
}
1 change: 1 addition & 0 deletions database/seeds/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ public function run()
$this->call('NotificationTableSeeder');
$this->call('HeartbeatTableSeeder');
$this->call('TemplateSeeder');
$this->call('VariableTableSeeder');
}
}
18 changes: 18 additions & 0 deletions database/seeds/VariableTableSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

use Illuminate\Database\Seeder;
use REBELinBLUE\Deployer\Variable;

class VariableTableSeeder extends Seeder
{
public function run()
{
DB::table('variables')->delete();

Variable::create([
'project_id' => 1,
'name' => 'COMPOSER_TIMEOUT',
'value' => '500'
]);
}
}

0 comments on commit e2d12c0

Please sign in to comment.