feat(docker): add support for standalone container log retrieval

This commit is contained in:
Mauricio Siu
2025-02-25 23:04:19 -06:00
parent 203da1a8fe
commit 29c1e4691e
4 changed files with 26 additions and 4 deletions

View File

@@ -79,7 +79,11 @@ export const ShowTraefikActions = ({ serverId }: Props) => {
>
<span>{t("settings.server.webServer.reload")}</span>
</DropdownMenuItem>
<ShowModalLogs appName="dokploy-traefik" serverId={serverId}>
<ShowModalLogs
appName="dokploy-traefik"
serverId={serverId}
type="standalone"
>
<DropdownMenuItem
onSelect={(e) => e.preventDefault()}
className="cursor-pointer"

View File

@@ -37,13 +37,20 @@ interface Props {
appName: string;
children?: React.ReactNode;
serverId?: string;
type: "standalone" | "swarm";
}
export const ShowModalLogs = ({ appName, children, serverId }: Props) => {
export const ShowModalLogs = ({
appName,
children,
serverId,
type = "swarm",
}: Props) => {
const { data, isLoading } = api.docker.getContainersByAppLabel.useQuery(
{
appName,
serverId,
type,
},
{
enabled: !!appName,

View File

@@ -65,10 +65,15 @@ export const dockerRouter = createTRPCRouter({
z.object({
appName: z.string().min(1),
serverId: z.string().optional(),
type: z.enum(["standalone", "swarm"]),
}),
)
.query(async ({ input }) => {
return await getContainersByAppLabel(input.appName, input.serverId);
return await getContainersByAppLabel(
input.appName,
input.type,
input.serverId,
);
}),
getStackContainersByAppName: protectedProcedure

View File

@@ -281,13 +281,19 @@ export const getServiceContainersByAppName = async (
export const getContainersByAppLabel = async (
appName: string,
type: "standalone" | "swarm",
serverId?: string,
) => {
try {
let stdout = "";
let stderr = "";
const command = `docker ps --filter "label=com.docker.swarm.service.name=${appName}" --format 'CONTAINER ID : {{.ID}} | Name: {{.Names}} | State: {{.State}}'`;
const command =
type === "swarm"
? `docker ps --filter "label=com.docker.swarm.service.name=${appName}" --format 'CONTAINER ID : {{.ID}} | Name: {{.Names}} | State: {{.State}}'`
: type === "standalone"
? `docker ps --filter "name=${appName}" --format 'CONTAINER ID : {{.ID}} | Name: {{.Names}} | State: {{.State}}'`
: `docker ps --filter "label=com.docker.compose.project=${appName}" --format 'CONTAINER ID : {{.ID}} | Name: {{.Names}} | State: {{.State}}'`;
if (serverId) {
const result = await execAsyncRemote(serverId, command);
stdout = result.stdout;