feat: add deploy API endpoints
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Dashboard\UI\API\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Process;
|
||||
|
||||
class DeployController extends Controller
|
||||
{
|
||||
private string $statusFile = '/tmp/deploy-status.json';
|
||||
private string $lockFile = '/tmp/deploy.lock';
|
||||
|
||||
public function store(): JsonResponse
|
||||
{
|
||||
if (File::exists($this->lockFile)) {
|
||||
return response()->json([
|
||||
'error' => 'Deploy already in progress'
|
||||
], 409);
|
||||
}
|
||||
|
||||
Process::run('nohup php artisan deploy:run > /dev/null 2>&1 &');
|
||||
|
||||
return response()->json(['message' => 'Deploy started']);
|
||||
}
|
||||
|
||||
public function status(): JsonResponse
|
||||
{
|
||||
if (!File::exists($this->statusFile)) {
|
||||
return response()->json([
|
||||
'running' => false,
|
||||
'step' => 0,
|
||||
'total_steps' => 12,
|
||||
'current_step' => '',
|
||||
'logs' => [],
|
||||
'error' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
$status = json_decode(File::get($this->statusFile), true);
|
||||
return response()->json($status);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Containers\Dashboard\UI\API\Controllers\DeployController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::post('/deploy', [DeployController::class, 'store']);
|
||||
Route::get('/deploy/status', [DeployController::class, 'status']);
|
||||
@@ -1,3 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::middleware(['access-check', 'dashboard.auth'])->group(function () {
|
||||
require __DIR__.'/../Containers/Dashboard/UI/API/Routes/api.php';
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user