Skip to content

Commit

Permalink
feat: #34 adjust deployment endpoint to the new structure
Browse files Browse the repository at this point in the history
  • Loading branch information
bohdan-shulha committed Jul 1, 2024
1 parent 0037a61 commit ee7fda4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/NodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function show(Node $node)
$initTaskGroup = null;
}

$lastAgentVersion = AgentRelease::latest()->sole()->tag_name;
$lastAgentVersion = AgentRelease::latest()->first()?->tag_name;

$taskGroup = $node->actualTaskGroup(NodeTaskGroupType::SelfUpgrade);

Expand Down
34 changes: 33 additions & 1 deletion app/Models/DeploymentData.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use App\Models\NodeTasks\CreateService\CreateServiceMeta;
use App\Rules\RequiredIfArrayHas;
use App\Util\Arrays;
use Illuminate\Validation\ValidationException;
use Spatie\LaravelData\Attributes\DataCollectionOf;
use Spatie\LaravelData\Attributes\Validation\Exists;
use Spatie\LaravelData\Attributes\Validation\RequiredIf;
Expand Down Expand Up @@ -75,7 +76,38 @@ public static function make(array $attributes): static

public function copyWith(array $attributes): DeploymentData
{
return DeploymentData::make(Arrays::niceMerge($this->toArray(), $attributes));
$result = $this->toArray();
$errors = [];

if (isset($attributes['processes'])) {
foreach ($attributes['processes'] as $idx => $process) {
if (!isset($process['name'])) {
$errors["processes.{$idx}.name"] = "Process name is required";

continue;
}

$processExists = false;

foreach ($result['processes'] as $existingIdx => $existingProcess) {
if ($existingProcess['name'] === $process['name']) {
$result['processes'][$existingIdx] = Arrays::niceMerge($existingProcess, $process);

$processExists = true;
}
}

if (!$processExists) {
$errors["processes.{$idx}.name"] = "Process {$process['name']} does not exist";
}
}
}

if (!empty($errors)) {
throw ValidationException::withMessages($errors);
}

return DeploymentData::validateAndCreate($result);
}

public function findProcess(string $dockerName): ?Process
Expand Down

0 comments on commit ee7fda4

Please sign in to comment.