Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom deploy path #75

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null


DEPLOY_FILE_PATH=false
DEPLOY_EXE_PATH=false
3 changes: 3 additions & 0 deletions app/Http/Controllers/ProjectsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function __construct(ProjectInterface $project, ProjectForm $projectForm,
$this->recipe = $recipe;
$this->server = $server;
$this->user = $user;
$this->usingCustomDeployFile = (bool)env('DEPLOY_FILE_PATH',false);
}

/**
Expand Down Expand Up @@ -81,6 +82,7 @@ public function create()
$users = ['' => ''] + $users;

return view('projects.create')
->with('usingCustomDeployFile',$this->usingCustomDeployFile)
->with('recipes', $recipes)
->with('servers', $servers)
->with('users', $users);
Expand Down Expand Up @@ -145,6 +147,7 @@ public function edit(Project $project)
$users = ['' => ''] + $users;

return view('projects.edit')
->with('usingCustomDeployFile',$this->usingCustomDeployFile)
->with('project', $project)
->with('recipes', $recipes)
->with('servers', $servers)
Expand Down
47 changes: 26 additions & 21 deletions app/Jobs/Deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Deploy extends Job implements ShouldQueue
public function __construct(Model $deployment)
{
$this->deployment = $deployment;
$this->executable = base_path('vendor/bin/dep');
$this->executable = env('DEPLOY_EXE_PATH',false)?:base_path('vendor/bin/dep');
}

/**
Expand All @@ -48,34 +48,39 @@ public function handle(ProjectInterface $projectRepository, ServerInterface $ser
{
$deployment = $this->deployment;
$project = $projectRepository->byId($deployment->project_id);
$server = $serverRepository->byId($project->server_id);

$app = app();
$deploymentFilePath = env('DEPLOY_FILE_PATH',false);
if(!$deploymentFilePath) {
$server = $serverRepository->byId($project->server_id);

// Create a server list file
$serverListFileBuilder = $app->make('App\Services\Deployment\DeployerServerListFileBuilder')
->setServer($server)
->setProject($project);
$serverListFile = $app->make('App\Services\Deployment\DeployerFileDirector', [$serverListFileBuilder])->construct();
$app = app();

// Create recipe files
foreach ($project->getRecipes() as $i => $recipe) {
// HACK: If an instance of DeployerRecipeFileBuilder class is not stored in an array, a destructor is called and a recipe file is deleted immediately.
$recipeFileBuilders[] = $app->make('App\Services\Deployment\DeployerRecipeFileBuilder')->setRecipe($recipe);
$recipeFiles[] = $app->make('App\Services\Deployment\DeployerFileDirector', [$recipeFileBuilders[$i]])->construct();
}
// Create a server list file
$serverListFileBuilder = $app->make('App\Services\Deployment\DeployerServerListFileBuilder')
->setServer($server)
->setProject($project);
$serverListFile = $app->make('App\Services\Deployment\DeployerFileDirector', [$serverListFileBuilder])->construct();

// Create recipe files
foreach ($project->getRecipes() as $i => $recipe) {
// HACK: If an instance of DeployerRecipeFileBuilder class is not stored in an array, a destructor is called and a recipe file is deleted immediately.
$recipeFileBuilders[] = $app->make('App\Services\Deployment\DeployerRecipeFileBuilder')->setRecipe($recipe);
$recipeFiles[] = $app->make('App\Services\Deployment\DeployerFileDirector', [$recipeFileBuilders[$i]])->construct();
}

// Create a deployment file
$deploymentFileBuilder = $app->make('App\Services\Deployment\DeployerDeploymentFileBuilder')
->setProject($project)
->setServerListFile($serverListFile)
->setRecipeFile($recipeFiles);
$deploymentFile = $app->make('App\Services\Deployment\DeployerFileDirector', [$deploymentFileBuilder])->construct();
// Create a deployment file
$deploymentFileBuilder = $app->make('App\Services\Deployment\DeployerDeploymentFileBuilder')
->setProject($project)
->setServerListFile($serverListFile)
->setRecipeFile($recipeFiles);
$deploymentFile = $app->make('App\Services\Deployment\DeployerFileDirector', [$deploymentFileBuilder])->construct();
$deploymentFilePath = $deploymentFile->getFullPath();
}

// Create a command
$processBuilder
->add($this->executable)
->add("-f={$deploymentFile->getFullPath()}")
->add("-f={$deploymentFilePath}")
->add('--ansi')
->add('-n')
->add('-vv')
Expand Down
48 changes: 27 additions & 21 deletions app/Jobs/Rollback.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Rollback extends Job implements ShouldQueue
public function __construct(Model $deployment)
{
$this->deployment = $deployment;
$this->executable = base_path('vendor/bin/dep');
$this->executable = env('DEPLOY_EXE_PATH',false)?:base_path('vendor/bin/dep');
}

/**
Expand All @@ -46,36 +46,42 @@ public function __construct(Model $deployment)
*/
public function handle(ProjectInterface $projectRepository, ServerInterface $serverRepository, ProcessBuilder $processBuilder, NotifierInterface $notifier, SettingInterface $settingRepository)
{
//TODO factor most of this out, it is the same as in \App\Jobs
$deployment = $this->deployment;
$project = $projectRepository->byId($deployment->project_id);
$server = $serverRepository->byId($project->server_id);

$app = app();
$deploymentFilePath = env('DEPLOY_FILE_PATH',false);
if(!$deploymentFilePath) {
$server = $serverRepository->byId($project->server_id);

// Create a server list file
$serverListFileBuilder = $app->make('App\Services\Deployment\DeployerServerListFileBuilder')
->setServer($server)
->setProject($project);
$serverListFile = $app->make('App\Services\Deployment\DeployerFileDirector', [$serverListFileBuilder])->construct();
$app = app();

// Create recipe files
foreach ($project->getRecipes() as $i => $recipe) {
// HACK: If an instance of DeployerRecipeFileBuilder class is not stored in an array, a destructor is called and a recipe file is deleted immediately.
$recipeFileBuilders[] = $app->make('App\Services\Deployment\DeployerRecipeFileBuilder')->setRecipe($recipe);
$recipeFiles[] = $app->make('App\Services\Deployment\DeployerFileDirector', [$recipeFileBuilders[$i]])->construct();
}
// Create a server list file
$serverListFileBuilder = $app->make('App\Services\Deployment\DeployerServerListFileBuilder')
->setServer($server)
->setProject($project);
$serverListFile = $app->make('App\Services\Deployment\DeployerFileDirector', [$serverListFileBuilder])->construct();

// Create recipe files
foreach ($project->getRecipes() as $i => $recipe) {
// HACK: If an instance of DeployerRecipeFileBuilder class is not stored in an array, a destructor is called and a recipe file is deleted immediately.
$recipeFileBuilders[] = $app->make('App\Services\Deployment\DeployerRecipeFileBuilder')->setRecipe($recipe);
$recipeFiles[] = $app->make('App\Services\Deployment\DeployerFileDirector', [$recipeFileBuilders[$i]])->construct();
}

// Create a deployment file
$deploymentFileBuilder = $app->make('App\Services\Deployment\DeployerDeploymentFileBuilder')
->setProject($project)
->setServerListFile($serverListFile)
->setRecipeFile($recipeFiles);
$deploymentFile = $app->make('App\Services\Deployment\DeployerFileDirector', [$deploymentFileBuilder])->construct();
// Create a deployment file
$deploymentFileBuilder = $app->make('App\Services\Deployment\DeployerDeploymentFileBuilder')
->setProject($project)
->setServerListFile($serverListFile)
->setRecipeFile($recipeFiles);
$deploymentFile = $app->make('App\Services\Deployment\DeployerFileDirector', [$deploymentFileBuilder])->construct();
$deploymentFilePath = $deploymentFile->getFullPath();
}

// Create a command
$processBuilder
->add($this->executable)
->add("-f={$deploymentFile->getFullPath()}")
->add("-f={$deploymentFilePath}")
->add('--ansi')
->add('-n')
->add('-vv')
Expand Down
20 changes: 12 additions & 8 deletions app/Services/Form/Project/ProjectFormLaravelValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ class ProjectFormLaravelValidator extends AbstractLaravelValidator
protected $rules = [
'name' => 'required',
'stage' => 'required',
'recipe_id' => 'required',
'server_id' => 'required|exists:servers,id',
'repository' => 'required|url',
'deploy_path' => 'string',
'email_notification_recipient' => 'email',
'days_to_keep_deployments' => 'integer|min:1',
'max_number_of_deployments_to_keep' => 'integer|min:1',
Expand All @@ -24,12 +20,20 @@ protected function rules()
{
$rules = [];

if (isset($this->data['recipe_id'])) {
foreach ($this->data['recipe_id'] as $key => $val) {
$rules["recipe_id.$key"] = 'required|exists:recipes,id';
if(!env('DEPLOY_FILE_PATH')){
$rules = [
'recipe_id' => 'required',
'server_id' => 'required|exists:servers,id',
'repository' => 'required|url',
'deploy_path' => 'string',
];

if (isset($this->data['recipe_id'])) {
foreach ($this->data['recipe_id'] as $key => $val) {
$rules["recipe_id.$key"] = 'required|exists:recipes,id';
}
}
}

return $rules;
}
}
Empty file modified artisan
100644 → 100755
Empty file.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@
"sensiolabs/ansi-to-html": "~1.0",
"symfony/yaml": "~3.0",
"ngmy/eloquent-serialized-lob": "^0.1.0",
"fguillot/json-rpc": "@stable",
"deployer/deployer": "^4.0"
"fguillot/json-rpc": "@stable"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
Expand All @@ -58,7 +57,8 @@
"symfony/css-selector": "~3.0",
"mockery/mockery": "dev-master",
"satooshi/php-coveralls": "dev-master",
"mikey179/vfsStream": "~1"
"mikey179/vfsStream": "~1",
"doctrine/dbal": "^2.5"
},
"autoload": {
"classmap": [
Expand Down
Loading