fix(api): respect service_name query param in application logs endpoint

GET /applications/{uuid}/logs ignored service_name and always returned
logs from the first container, so 'coolify app logs --service' could show
logs from the wrong Compose service. When service_name is present, select
the container whose labels contain the matching
com.docker.compose.service entry and 404 when nothing matches.
This commit is contained in:
Furox-Art
2026-09-30 03:03:03 +03:00
parent 680f4e5d29
commit a9a9f0f30f
@@ -2472,6 +2472,13 @@ class ApplicationsController extends Controller
required: false,
schema: new OA\Schema(type: 'boolean', default: false),
),
new OA\Parameter(
name: 'service_name',
in: 'query',
description: 'For Docker Compose applications, return logs only from the Compose service with this name. Returns 404 when no running container matches. Ignored for non-Compose applications.',
required: false,
schema: new OA\Schema(type: 'string'),
),
],
responses: [
new OA\Response(
@@ -2597,7 +2604,27 @@ class ApplicationsController extends Controller
], 400);
}
$container = $containers->first();
$serviceName = $request->query('service_name');
if (filled($serviceName)) {
$matchingContainer = $containers->first(function ($container) use ($serviceName) {
$labels = data_get($container, 'Labels');
return $labels !== null && preg_match(
'/(?:^|,)com\.docker\.compose\.service='.preg_quote($serviceName, '/').'(?:,|$)/',
$labels
) === 1;
});
if (! $matchingContainer) {
return response()->json([
'message' => "No running container found for service_name '{$serviceName}'.",
], 404);
}
$container = $matchingContainer;
} else {
$container = $containers->first();
}
$status = getContainerStatus($application->destination->server, $container['Names']);
if ($status !== 'running') {