wowowowowo
This commit is contained in:
102
app/Http/Controllers/ServiceReplicaController.php
Normal file
102
app/Http/Controllers/ServiceReplicaController.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Enums\OperationKind;
|
||||
use App\Enums\OperationStatus;
|
||||
use App\Models\Organisation;
|
||||
use App\Models\ServiceReplica;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Response;
|
||||
|
||||
class ServiceReplicaController extends Controller
|
||||
{
|
||||
public function show(Request $request): Response
|
||||
{
|
||||
$organisation = Organisation::findOrFail($request->route('organisation'));
|
||||
$server = $organisation->servers()->findOrFail($request->route('server'));
|
||||
$service = $server->services()->with('environment.application')->findOrFail($request->route('service'));
|
||||
$replica = $service->replicas()
|
||||
->with(['server', 'operation.steps', 'operations.steps', 'operations.children.target'])
|
||||
->findOrFail($request->route('replica'));
|
||||
|
||||
return inertia('service-replicas/Show', [
|
||||
'server' => $server,
|
||||
'service' => $service,
|
||||
'replica' => $replica,
|
||||
]);
|
||||
}
|
||||
|
||||
public function restart(Request $request): RedirectResponse
|
||||
{
|
||||
$organisation = Organisation::findOrFail($request->route('organisation'));
|
||||
$server = $organisation->servers()->findOrFail($request->route('server'));
|
||||
$service = $server->services()->findOrFail($request->route('service'));
|
||||
$replica = $service->replicas()->findOrFail($request->route('replica'));
|
||||
|
||||
$this->queueLifecycleOperation($replica, 'Restart replica', "docker restart {$replica->container_name}");
|
||||
|
||||
return redirect()
|
||||
->route('service-replicas.show', [
|
||||
'organisation' => $organisation->id,
|
||||
'server' => $server->id,
|
||||
'service' => $service->id,
|
||||
'replica' => $replica->id,
|
||||
])
|
||||
->with('success', 'Replica restart queued.');
|
||||
}
|
||||
|
||||
public function start(Request $request): RedirectResponse
|
||||
{
|
||||
$organisation = Organisation::findOrFail($request->route('organisation'));
|
||||
$server = $organisation->servers()->findOrFail($request->route('server'));
|
||||
$service = $server->services()->findOrFail($request->route('service'));
|
||||
$replica = $service->replicas()->findOrFail($request->route('replica'));
|
||||
|
||||
$this->queueLifecycleOperation($replica, 'Start replica', "docker start {$replica->container_name}");
|
||||
|
||||
return redirect()
|
||||
->route('service-replicas.show', [
|
||||
'organisation' => $organisation->id,
|
||||
'server' => $server->id,
|
||||
'service' => $service->id,
|
||||
'replica' => $replica->id,
|
||||
])
|
||||
->with('success', 'Replica start queued.');
|
||||
}
|
||||
|
||||
public function stop(Request $request): RedirectResponse
|
||||
{
|
||||
$organisation = Organisation::findOrFail($request->route('organisation'));
|
||||
$server = $organisation->servers()->findOrFail($request->route('server'));
|
||||
$service = $server->services()->findOrFail($request->route('service'));
|
||||
$replica = $service->replicas()->findOrFail($request->route('replica'));
|
||||
|
||||
$this->queueLifecycleOperation($replica, 'Stop replica', "docker stop {$replica->container_name}");
|
||||
|
||||
return redirect()
|
||||
->route('service-replicas.show', [
|
||||
'organisation' => $organisation->id,
|
||||
'server' => $server->id,
|
||||
'service' => $service->id,
|
||||
'replica' => $replica->id,
|
||||
])
|
||||
->with('success', 'Replica stop queued.');
|
||||
}
|
||||
|
||||
private function queueLifecycleOperation(ServiceReplica $replica, string $name, string $script): void
|
||||
{
|
||||
$operation = $replica->operations()->create([
|
||||
'kind' => OperationKind::REPLICA_DEPLOY,
|
||||
'status' => OperationStatus::PENDING,
|
||||
]);
|
||||
|
||||
$operation->steps()->create([
|
||||
'name' => $name,
|
||||
'order' => 1,
|
||||
'status' => OperationStatus::PENDING,
|
||||
'script' => $script,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user