move into sonardesk
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\CloudDevOps\Services;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Modules\CloudDevOps\Models\DeploymentEnvironment;
|
||||
use Modules\CloudDevOps\Models\DeploymentPipeline;
|
||||
use Modules\CloudDevOps\Models\DeploymentRelease;
|
||||
|
||||
final class DeploymentManager
|
||||
{
|
||||
public function createRelease(DeploymentEnvironment $environment, DeploymentPipeline $pipeline, array $attributes = []): DeploymentRelease
|
||||
{
|
||||
return DB::transaction(function () use ($environment, $pipeline, $attributes): DeploymentRelease {
|
||||
$release = $environment->releases()->create([
|
||||
'pipeline_id' => $pipeline->getKey(),
|
||||
'version' => $attributes['version'] ?? now()->format('YmdHis').'-'.Str::lower(Str::random(6)),
|
||||
'commit_hash' => $attributes['commit_hash'] ?? null,
|
||||
'status' => $pipeline->requires_approval ? 'awaiting_approval' : 'pending',
|
||||
'requested_by' => $attributes['requested_by'] ?? null,
|
||||
'metadata' => $attributes['metadata'] ?? [],
|
||||
]);
|
||||
|
||||
foreach ($pipeline->steps as $position => $step) {
|
||||
$release->steps()->create(['name' => $step['name'] ?? 'Step '.($position + 1), 'position' => $position]);
|
||||
}
|
||||
|
||||
return $release->load('steps');
|
||||
});
|
||||
}
|
||||
|
||||
public function execute(DeploymentRelease $release): DeploymentRelease
|
||||
{
|
||||
abort_unless(config('clouddevops.allow_execution'), 403, 'Deployment execution is disabled.');
|
||||
$release->update(['status' => 'running', 'started_at' => now()]);
|
||||
|
||||
return $release->refresh();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\CloudDevOps\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Modules\CloudDevOps\Models\DeploymentHealthCheck;
|
||||
|
||||
final class HealthCheckRunner
|
||||
{
|
||||
public function run(DeploymentHealthCheck $check): DeploymentHealthCheck
|
||||
{
|
||||
$started = microtime(true);
|
||||
try {
|
||||
$response = Http::timeout(10)->get((string) $check->endpoint);
|
||||
$status = $response->status() === $check->expected_status ? 'healthy' : 'unhealthy';
|
||||
$message = 'HTTP '.$response->status();
|
||||
} catch (\Throwable $e) {
|
||||
$status = 'unhealthy';
|
||||
$message = $e->getMessage();
|
||||
} $check->update(['status' => $status, 'response_time_ms' => (int) ((microtime(true) - $started) * 1000), 'checked_at' => now(), 'message' => $message]);
|
||||
|
||||
return $check->refresh();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user