Add managed registry provisioning, pruning, and readiness tracking
This commit is contained in:
64
app/Services/Registries/ManagedRegistryProvisioner.php
Normal file
64
app/Services/Registries/ManagedRegistryProvisioner.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Registries;
|
||||
|
||||
use App\Enums\RegistryType;
|
||||
use App\Models\Organisation;
|
||||
use App\Models\Registry;
|
||||
use App\Models\Server;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ManagedRegistryProvisioner
|
||||
{
|
||||
public function provision(Organisation $organisation, string $url, ?Server $controlServer = null, ?string $storagePath = null, ?int $retention = null): Registry
|
||||
{
|
||||
$registry = $organisation->registries()->firstOrNew([
|
||||
'type' => RegistryType::MANAGED->value,
|
||||
]);
|
||||
|
||||
$registry->fill([
|
||||
'name' => 'Managed Registry',
|
||||
'url' => $this->registryHost($url),
|
||||
'storage_path' => $storagePath ?: (string) config('keystone.managed_registry.storage_path'),
|
||||
'retention_successful_artifacts' => $retention ?: (int) config('keystone.managed_registry.retention.successful_artifacts_per_environment', 3),
|
||||
'control_server_id' => $controlServer?->id,
|
||||
'credentials' => $this->credentials($registry->credentials ?? []),
|
||||
]);
|
||||
|
||||
if ($registry->health_status === null) {
|
||||
$registry->health_status = 'pending';
|
||||
}
|
||||
|
||||
$registry->save();
|
||||
|
||||
if ($controlServer instanceof Server) {
|
||||
$controlServer->forceFill([
|
||||
'is_control_node' => true,
|
||||
'build_enabled' => true,
|
||||
])->save();
|
||||
}
|
||||
|
||||
return $registry->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $existing
|
||||
* @return array<string, string>
|
||||
*/
|
||||
private function credentials(array $existing): array
|
||||
{
|
||||
return [
|
||||
'build_username' => (string) ($existing['build_username'] ?? 'keystone-build'),
|
||||
'build_password' => (string) ($existing['build_password'] ?? Str::password(40)),
|
||||
'runtime_username' => (string) ($existing['runtime_username'] ?? 'keystone-runtime'),
|
||||
'runtime_password' => (string) ($existing['runtime_password'] ?? Str::password(40)),
|
||||
];
|
||||
}
|
||||
|
||||
private function registryHost(string $url): string
|
||||
{
|
||||
$host = preg_replace('#^https?://#', '', trim($url));
|
||||
|
||||
return rtrim($host === null ? trim($url) : $host, '/');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user