feat: container logs
This commit is contained in:
@@ -1100,7 +1100,7 @@ class ApplicationsController extends Controller
|
|||||||
], 422);
|
], 422);
|
||||||
}
|
}
|
||||||
if (! $request->has('name')) {
|
if (! $request->has('name')) {
|
||||||
$request->offsetSet('name', 'dockerfile-' . new Cuid2);
|
$request->offsetSet('name', 'dockerfile-'.new Cuid2);
|
||||||
}
|
}
|
||||||
|
|
||||||
$return = $this->validateDataApplications($request, $server);
|
$return = $this->validateDataApplications($request, $server);
|
||||||
@@ -1187,7 +1187,7 @@ class ApplicationsController extends Controller
|
|||||||
], 422);
|
], 422);
|
||||||
}
|
}
|
||||||
if (! $request->has('name')) {
|
if (! $request->has('name')) {
|
||||||
$request->offsetSet('name', 'docker-image-' . new Cuid2);
|
$request->offsetSet('name', 'docker-image-'.new Cuid2);
|
||||||
}
|
}
|
||||||
$return = $this->validateDataApplications($request, $server);
|
$return = $this->validateDataApplications($request, $server);
|
||||||
if ($return instanceof \Illuminate\Http\JsonResponse) {
|
if ($return instanceof \Illuminate\Http\JsonResponse) {
|
||||||
@@ -1253,7 +1253,7 @@ class ApplicationsController extends Controller
|
|||||||
], 422);
|
], 422);
|
||||||
}
|
}
|
||||||
if (! $request->has('name')) {
|
if (! $request->has('name')) {
|
||||||
$request->offsetSet('name', 'service' . new Cuid2);
|
$request->offsetSet('name', 'service'.new Cuid2);
|
||||||
}
|
}
|
||||||
$validationRules = [
|
$validationRules = [
|
||||||
'docker_compose_raw' => 'string|required',
|
'docker_compose_raw' => 'string|required',
|
||||||
@@ -1452,6 +1452,25 @@ class ApplicationsController extends Controller
|
|||||||
if (! $application) {
|
if (! $application) {
|
||||||
return response()->json(['message' => 'Application not found.'], 404);
|
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(
|
#[OA\Delete(
|
||||||
@@ -1756,7 +1775,7 @@ class ApplicationsController extends Controller
|
|||||||
$fqdn = str($fqdn)->trim()->explode(',')->map(function ($domain) use (&$errors) {
|
$fqdn = str($fqdn)->trim()->explode(',')->map(function ($domain) use (&$errors) {
|
||||||
$domain = trim($domain);
|
$domain = trim($domain);
|
||||||
if (filter_var($domain, FILTER_VALIDATE_URL) === false || ! preg_match('/^https?:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,}/', $domain)) {
|
if (filter_var($domain, FILTER_VALIDATE_URL) === false || ! preg_match('/^https?:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,}/', $domain)) {
|
||||||
$errors[] = 'Invalid domain: ' . $domain;
|
$errors[] = 'Invalid domain: '.$domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $domain;
|
return $domain;
|
||||||
@@ -2992,7 +3011,7 @@ class ApplicationsController extends Controller
|
|||||||
$errors = [];
|
$errors = [];
|
||||||
$fqdn = str($fqdn)->trim()->explode(',')->map(function ($domain) use (&$errors) {
|
$fqdn = str($fqdn)->trim()->explode(',')->map(function ($domain) use (&$errors) {
|
||||||
if (filter_var($domain, FILTER_VALIDATE_URL) === false) {
|
if (filter_var($domain, FILTER_VALIDATE_URL) === false) {
|
||||||
$errors[] = 'Invalid domain: ' . $domain;
|
$errors[] = 'Invalid domain: '.$domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
return str($domain)->trim()->lower();
|
return str($domain)->trim()->lower();
|
||||||
|
@@ -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)
|
function escapeEnvVariables($value)
|
||||||
{
|
{
|
||||||
$search = ['\\', "\r", "\t", "\x0", '"', "'"];
|
$search = ['\\', "\r", "\t", "\x0", '"', "'"];
|
||||||
|
Reference in New Issue
Block a user