mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
feat(docker): add support for standalone container log retrieval
This commit is contained in:
@@ -79,7 +79,11 @@ export const ShowTraefikActions = ({ serverId }: Props) => {
|
|||||||
>
|
>
|
||||||
<span>{t("settings.server.webServer.reload")}</span>
|
<span>{t("settings.server.webServer.reload")}</span>
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
<ShowModalLogs appName="dokploy-traefik" serverId={serverId}>
|
<ShowModalLogs
|
||||||
|
appName="dokploy-traefik"
|
||||||
|
serverId={serverId}
|
||||||
|
type="standalone"
|
||||||
|
>
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onSelect={(e) => e.preventDefault()}
|
onSelect={(e) => e.preventDefault()}
|
||||||
className="cursor-pointer"
|
className="cursor-pointer"
|
||||||
|
|||||||
@@ -37,13 +37,20 @@ interface Props {
|
|||||||
appName: string;
|
appName: string;
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
serverId?: string;
|
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(
|
const { data, isLoading } = api.docker.getContainersByAppLabel.useQuery(
|
||||||
{
|
{
|
||||||
appName,
|
appName,
|
||||||
serverId,
|
serverId,
|
||||||
|
type,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
enabled: !!appName,
|
enabled: !!appName,
|
||||||
|
|||||||
@@ -65,10 +65,15 @@ export const dockerRouter = createTRPCRouter({
|
|||||||
z.object({
|
z.object({
|
||||||
appName: z.string().min(1),
|
appName: z.string().min(1),
|
||||||
serverId: z.string().optional(),
|
serverId: z.string().optional(),
|
||||||
|
type: z.enum(["standalone", "swarm"]),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.query(async ({ input }) => {
|
.query(async ({ input }) => {
|
||||||
return await getContainersByAppLabel(input.appName, input.serverId);
|
return await getContainersByAppLabel(
|
||||||
|
input.appName,
|
||||||
|
input.type,
|
||||||
|
input.serverId,
|
||||||
|
);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
getStackContainersByAppName: protectedProcedure
|
getStackContainersByAppName: protectedProcedure
|
||||||
|
|||||||
@@ -281,13 +281,19 @@ export const getServiceContainersByAppName = async (
|
|||||||
|
|
||||||
export const getContainersByAppLabel = async (
|
export const getContainersByAppLabel = async (
|
||||||
appName: string,
|
appName: string,
|
||||||
|
type: "standalone" | "swarm",
|
||||||
serverId?: string,
|
serverId?: string,
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
let stdout = "";
|
let stdout = "";
|
||||||
let stderr = "";
|
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) {
|
if (serverId) {
|
||||||
const result = await execAsyncRemote(serverId, command);
|
const result = await execAsyncRemote(serverId, command);
|
||||||
stdout = result.stdout;
|
stdout = result.stdout;
|
||||||
|
|||||||
Reference in New Issue
Block a user