87 lines
2.8 KiB
PHP
87 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Actions\Registries;
|
|
|
|
use App\Enums\OperationKind;
|
|
use App\Enums\OperationStatus;
|
|
use App\Models\Operation;
|
|
use App\Models\Registry;
|
|
use App\Models\Server;
|
|
use App\Services\Registries\ManagedRegistryOperationScripts;
|
|
use RuntimeException;
|
|
|
|
class CreateManagedRegistrySmokeCheckOperation
|
|
{
|
|
public function __construct(
|
|
private readonly ManagedRegistryOperationScripts $scripts,
|
|
) {}
|
|
|
|
/**
|
|
* @param iterable<int, Server> $runtimeServers
|
|
*/
|
|
public function execute(Registry $registry, ?Server $buildServer = null, iterable $runtimeServers = []): Operation
|
|
{
|
|
$controlServer = $registry->controlServer;
|
|
|
|
if (! $controlServer instanceof Server) {
|
|
throw new RuntimeException('A control/build server is required to check the managed registry.');
|
|
}
|
|
|
|
$buildServer ??= $controlServer;
|
|
$smokeRef = rtrim((string) $registry->url, '/').'/keystone/smoke/server-'.$buildServer->id.':latest';
|
|
$checks = [
|
|
'control_https' => 'pending',
|
|
'build_push' => 'pending',
|
|
];
|
|
|
|
foreach ($runtimeServers as $server) {
|
|
$checks['runtime_pull_server_'.$server->id] = 'pending';
|
|
}
|
|
|
|
$registry->forceFill([
|
|
'readiness_checks' => $checks,
|
|
'health_status' => 'pending',
|
|
'ready_at' => null,
|
|
])->save();
|
|
|
|
$operation = $controlServer->operations()->create([
|
|
'kind' => OperationKind::REGISTRY_HEALTH_CHECK,
|
|
'status' => OperationStatus::PENDING,
|
|
'metadata' => [
|
|
'registry_id' => $registry->id,
|
|
],
|
|
]);
|
|
|
|
$build = $this->scripts->smokeCheck($registry, $buildServer, 'build', $smokeRef);
|
|
$operation->steps()->create([
|
|
'name' => 'Check registry HTTPS and build push',
|
|
'order' => 1,
|
|
'status' => OperationStatus::PENDING,
|
|
'script' => $build['script'],
|
|
'secrets' => $build['secrets'],
|
|
]);
|
|
|
|
$order = 2;
|
|
foreach ($runtimeServers as $server) {
|
|
$runtime = $this->scripts->smokeCheck($registry, $server, 'runtime', $smokeRef);
|
|
$child = $server->operations()->create([
|
|
'kind' => OperationKind::REGISTRY_HEALTH_CHECK,
|
|
'parent_id' => $operation->id,
|
|
'status' => OperationStatus::PENDING,
|
|
'metadata' => [
|
|
'registry_id' => $registry->id,
|
|
],
|
|
]);
|
|
$child->steps()->create([
|
|
'name' => 'Check runtime registry pull on '.$server->name,
|
|
'order' => $order++,
|
|
'status' => OperationStatus::PENDING,
|
|
'script' => $runtime['script'],
|
|
'secrets' => $runtime['secrets'],
|
|
]);
|
|
}
|
|
|
|
return $operation->refresh();
|
|
}
|
|
}
|