45 lines
1.2 KiB
PHP
45 lines
1.2 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 CreateManagedRegistryProvisionOperation
|
|
{
|
|
public function __construct(
|
|
private readonly ManagedRegistryOperationScripts $scripts,
|
|
) {}
|
|
|
|
public function execute(Registry $registry): Operation
|
|
{
|
|
$server = $registry->controlServer;
|
|
|
|
if (! $server instanceof Server) {
|
|
throw new RuntimeException('A control/build server is required to provision the managed registry.');
|
|
}
|
|
|
|
$provision = $this->scripts->provision($registry);
|
|
|
|
$operation = $server->operations()->create([
|
|
'kind' => OperationKind::REGISTRY_PROVISION,
|
|
'status' => OperationStatus::PENDING,
|
|
]);
|
|
|
|
$operation->steps()->create([
|
|
'name' => 'Install managed Docker registry',
|
|
'order' => 1,
|
|
'status' => OperationStatus::PENDING,
|
|
'script' => $provision['script'],
|
|
'secrets' => $provision['secrets'],
|
|
]);
|
|
|
|
return $operation->refresh();
|
|
}
|
|
}
|