Skip to content

Commit 558d809

Browse files
committed
feat(deployment): add readLogs procedure to fetch deployment logs
- Introduced a new `readLogs` procedure that allows users to retrieve logs for a specific deployment by providing the deployment ID and an optional tail parameter. - Implemented permission checks to ensure users have access to the requested logs. - Enhanced log retrieval for both cloud and non-cloud environments, utilizing appropriate commands based on the server context. Resolve Dokploy/mcp#14
1 parent f8fcf68 commit 558d809

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

‎apps/dokploy/server/api/routers/deployment.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,39 @@ export const deploymentRouter = createTRPCRouter({
197197
});
198198
return result;
199199
}),
200+
201+
readLogs: protectedProcedure
202+
.input(
203+
z.object({
204+
deploymentId: z.string().min(1),
205+
tail: z.number().int().min(1).max(10000).default(100),
206+
}),
207+
)
208+
.query(async ({ input, ctx }) => {
209+
const deployment = await findDeploymentById(input.deploymentId);
210+
const serviceId = deployment.applicationId || deployment.composeId;
211+
if (serviceId) {
212+
await checkServicePermissionAndAccess(ctx, serviceId, {
213+
deployment: ["read"],
214+
});
215+
}
216+
217+
if (!deployment.logPath) {
218+
return "";
219+
}
220+
221+
const command = `tail -n ${input.tail} "${deployment.logPath}" 2>/dev/null || echo ""`;
222+
const serverId = deployment.serverId || deployment.schedule?.serverId;
223+
if (serverId) {
224+
const { stdout } = await execAsyncRemote(serverId, command);
225+
return stdout;
226+
}
227+
228+
if (IS_CLOUD) {
229+
return "";
230+
}
231+
232+
const { stdout } = await execAsync(command);
233+
return stdout;
234+
}),
200235
});

0 commit comments

Comments
 (0)