Files
ABSDEV/Modules/CloudDevOps/Services/DeploymentManager.php
T
Mark Gregory bc9427ac33 Deployment environments
* Development, staging, and production environment types
* Protected-environment support
* Deployment targets
* Local, SSH, Docker, and Kubernetes driver foundation
* Deployment pipelines
* Configurable pipeline steps
* Manual and approval-based releases
* Deployment release history
* Individual deployment-step tracking
* HTTP health checks
* Response-time tracking
* Rollback records
* Secret-reference metadata
* Encrypted target configuration
* Encrypted environment variables
* Administration dashboard
* Authenticated API endpoints
* Health-check command
* Release-history pruning command
* Permissions
* Sidebar integration
* Module registration
* Feature test
2026-07-24 13:57:56 +01:00

40 lines
1.6 KiB
PHP

<?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();
}
}