Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ import {
CardHeader,
CardTitle,
} from "@/components/ui/card";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { api, type RouterOutputs } from "@/utils/api";
import { ShowRollbackSettings } from "../rollbacks/show-rollback-settings";
import { CancelQueues } from "./cancel-queues";
Expand Down Expand Up @@ -59,11 +66,13 @@ export const ShowDeployments = ({
const [activeLog, setActiveLog] = useState<
RouterOutputs["deployment"]["all"][number] | null
>(null);
const [deploymentLimit, setDeploymentLimit] = useState<number>(10);
const { data: deployments, isLoading: isLoadingDeployments } =
api.deployment.allByType.useQuery(
{
id,
type,
limit: deploymentLimit,
},
{
enabled: !!id,
Expand Down Expand Up @@ -140,10 +149,29 @@ export const ShowDeployments = ({
<div className="flex flex-col gap-2">
<CardTitle className="text-xl">Deployments</CardTitle>
<CardDescription>
See the last 10 deployments for this {type}
See the last {deploymentLimit} deployments for this {type}
</CardDescription>
</div>
<div className="flex flex-row items-center flex-wrap gap-2">
<div className="flex items-center gap-2">
<span className="text-sm text-muted-foreground whitespace-nowrap">
Show:
</span>
<Select
value={deploymentLimit.toString()}
onValueChange={(value) => setDeploymentLimit(Number(value))}
>
<SelectTrigger className="w-20 h-10">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="10">10</SelectItem>
<SelectItem value="25">25</SelectItem>
<SelectItem value="50">50</SelectItem>
<SelectItem value="100">100</SelectItem>
</SelectContent>
</Select>
</div>
{(type === "application" || type === "compose") && (
<KillBuild id={id} type={type} />
)}
Expand Down
11 changes: 7 additions & 4 deletions apps/dokploy/server/api/routers/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ export const deploymentRouter = createTRPCRouter({
message: "You are not authorized to access this application",
});
}
return await findAllDeploymentsByApplicationId(input.applicationId);
return await findAllDeploymentsByApplicationId(
input.applicationId,
input.limit,
);
}),

allByCompose: protectedProcedure
Expand All @@ -53,7 +56,7 @@ export const deploymentRouter = createTRPCRouter({
message: "You are not authorized to access this compose",
});
}
return await findAllDeploymentsByComposeId(input.composeId);
return await findAllDeploymentsByComposeId(input.composeId, input.limit);
}),
allByServer: protectedProcedure
.input(apiFindAllByServer)
Expand All @@ -65,7 +68,7 @@ export const deploymentRouter = createTRPCRouter({
message: "You are not authorized to access this server",
});
}
return await findAllDeploymentsByServerId(input.serverId);
return await findAllDeploymentsByServerId(input.serverId, input.limit);
}),

allByType: protectedProcedure
Expand All @@ -74,11 +77,11 @@ export const deploymentRouter = createTRPCRouter({
const deploymentsList = await db.query.deployments.findMany({
where: eq(deployments[`${input.type}Id`], input.id),
orderBy: desc(deployments.createdAt),
limit: input.limit,
with: {
rollback: true,
},
});

return deploymentsList;
}),

Expand Down
4 changes: 4 additions & 0 deletions packages/server/src/db/schema/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ export const apiFindAllByApplication = schema
})
.extend({
applicationId: z.string().min(1),
limit: z.number().min(1).max(100).optional().default(10),
})
.required();

Expand All @@ -225,6 +226,7 @@ export const apiFindAllByCompose = schema
})
.extend({
composeId: z.string().min(1),
limit: z.number().min(1).max(100).optional().default(10),
})
.required();

Expand All @@ -234,6 +236,7 @@ export const apiFindAllByServer = schema
})
.extend({
serverId: z.string().min(1),
limit: z.number().min(1).max(100).optional().default(10),
})
.required();

Expand All @@ -249,5 +252,6 @@ export const apiFindAllByType = z
"backup",
"volumeBackup",
]),
limit: z.number().min(1).max(100).optional().default(10),
})
.required();
41 changes: 30 additions & 11 deletions packages/server/src/services/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from "@dokploy/server/db/schema";
import { removeDirectoryIfExistsContent } from "@dokploy/server/utils/filesystem/directory";
import { execAsyncRemote } from "@dokploy/server/utils/process/execAsync";
import { logger } from "../lib/logger";
import { TRPCError } from "@trpc/server";
import { format } from "date-fns";
import { desc, eq } from "drizzle-orm";
Expand Down Expand Up @@ -75,7 +76,7 @@ export const createDeployment = async (
) => {
const application = await findApplicationById(deployment.applicationId);
try {
await removeLastTenDeployments(
await removeLastOneHundredDeployments(
deployment.applicationId,
"application",
application.serverId,
Expand Down Expand Up @@ -158,7 +159,7 @@ export const createDeploymentPreview = async (
deployment.previewDeploymentId,
);
try {
await removeLastTenDeployments(
await removeLastOneHundredDeployments(
deployment.previewDeploymentId,
"previewDeployment",
previewDeployment?.application?.serverId,
Expand Down Expand Up @@ -239,7 +240,7 @@ export const createDeploymentCompose = async (
) => {
const compose = await findComposeById(deployment.composeId);
try {
await removeLastTenDeployments(
await removeLastOneHundredDeployments(
deployment.composeId,
"compose",
compose.serverId,
Expand Down Expand Up @@ -327,7 +328,11 @@ export const createDeploymentBackup = async (
serverId = backup.compose?.serverId;
}
try {
await removeLastTenDeployments(deployment.backupId, "backup", serverId);
await removeLastOneHundredDeployments(
deployment.backupId,
"backup",
serverId,
);
const { LOGS_PATH } = paths(!!serverId);
const formattedDateTime = format(new Date(), "yyyy-MM-dd:HH:mm:ss");
const fileName = `${backup.appName}-${formattedDateTime}.log`;
Expand Down Expand Up @@ -401,7 +406,11 @@ export const createDeploymentSchedule = async (
schedule.application?.serverId ||
schedule.compose?.serverId ||
schedule.server?.serverId;
await removeLastTenDeployments(deployment.scheduleId, "schedule", serverId);
await removeLastOneHundredDeployments(
deployment.scheduleId,
"schedule",
serverId,
);
const { SCHEDULES_PATH } = paths(!!serverId);
const formattedDateTime = format(new Date(), "yyyy-MM-dd:HH:mm:ss");
const fileName = `${schedule.appName}-${formattedDateTime}.log`;
Expand Down Expand Up @@ -475,7 +484,7 @@ export const createDeploymentVolumeBackup = async (
try {
const serverId =
volumeBackup.application?.serverId || volumeBackup.compose?.serverId;
await removeLastTenDeployments(
await removeLastOneHundredDeployments(
deployment.volumeBackupId,
"volumeBackup",
serverId,
Expand Down Expand Up @@ -608,7 +617,7 @@ export const removeDeployments = async (application: Application) => {
await removeDeploymentsByApplicationId(applicationId);
};

const removeLastTenDeployments = async (
const removeLastOneHundredDeployments = async (
id: string,
type:
| "application"
Expand All @@ -621,8 +630,8 @@ const removeLastTenDeployments = async (
serverId?: string | null,
) => {
const deploymentList = await getDeploymentsByType(id, type);
if (deploymentList.length > 10) {
const deploymentsToDelete = deploymentList.slice(10);
if (deploymentList.length > 100) {
const deploymentsToDelete = deploymentList.slice(100);
if (serverId) {
let command = "";
for (const oldDeployment of deploymentsToDelete) {
Expand Down Expand Up @@ -701,18 +710,24 @@ export const removeDeploymentsByComposeId = async (compose: Compose) => {

export const findAllDeploymentsByApplicationId = async (
applicationId: string,
limit?: number,
) => {
const deploymentsList = await db.query.deployments.findMany({
where: eq(deployments.applicationId, applicationId),
orderBy: desc(deployments.createdAt),
...(limit ? { limit } : {}),
});
return deploymentsList;
};

export const findAllDeploymentsByComposeId = async (composeId: string) => {
export const findAllDeploymentsByComposeId = async (
composeId: string,
limit?: number,
) => {
const deploymentsList = await db.query.deployments.findMany({
where: eq(deployments.composeId, composeId),
orderBy: desc(deployments.createdAt),
...(limit ? { limit } : {}),
});
return deploymentsList;
};
Expand Down Expand Up @@ -824,10 +839,14 @@ export const removeDeploymentsByServerId = async (server: Server) => {
.returning();
};

export const findAllDeploymentsByServerId = async (serverId: string) => {
export const findAllDeploymentsByServerId = async (
serverId: string,
limit?: number,
) => {
const deploymentsList = await db.query.deployments.findMany({
where: eq(deployments.serverId, serverId),
orderBy: desc(deployments.createdAt),
...(limit ? { limit } : {}),
});
return deploymentsList;
};