feat: container logs

This commit is contained in:
Vann
2025-02-01 17:21:38 +00:00
parent b1d6167e89
commit e7988fc295
2 changed files with 39 additions and 5 deletions

View File

@@ -1452,6 +1452,25 @@ class ApplicationsController extends Controller
if (! $application) {
return response()->json(['message' => 'Application not found.'], 404);
}
$container = getCurrentApplicationContainerStatus($application->destination->server, $application->id)->firstOrFail();
// TODO: fix error when getting status
$status = getContainerStatus($application->destination->server, $container['name']);
// return response()->json([
// 'logs' => $status,
// ]);
if ($status !== 'running') {
return response()->json([
'message' => 'Application is not running.',
], 400);
}
$logs = getContainerLogs($application->destination->server, $container['Id']);
return response()->json([
'logs' => 'yey',
]);
}
#[OA\Delete(

View File

@@ -852,6 +852,21 @@ function validateComposeFile(string $compose, int $server_id): string|Throwable
}
}
function getContainerLogs(Server $server, string $container_id, int $lines = 100): string
{
if ($server->isSwarm()) {
$output = instant_remote_process([
"docker service logs -n {$lines} {$container_id}",
], $server);
} else {
$output = instant_remote_process([
"docker logs -n {$lines} {$container_id}",
], $server);
}
return $output;
}
function escapeEnvVariables($value)
{
$search = ['\\', "\r", "\t", "\x0", '"', "'"];