mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-07-08 23:45:22 +02:00
Compare commits
20 Commits
fix/delete
...
v0.25.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9398b9558 | ||
|
|
788dbe4050 | ||
|
|
6934f44778 | ||
|
|
457a6db00f | ||
|
|
81f89a0796 | ||
|
|
d8a98f3936 | ||
|
|
ec11325165 | ||
|
|
abcbd2d599 | ||
|
|
1664ae9b92 | ||
|
|
24729f35ec | ||
|
|
3eaeaa1db4 | ||
|
|
de4a00f1e9 | ||
|
|
2f5cd620c5 | ||
|
|
1763000070 | ||
|
|
3519913886 | ||
|
|
63e578f13c | ||
|
|
d80ada7c00 | ||
|
|
766cd20e90 | ||
|
|
4e69c70697 | ||
|
|
3b7d009841 |
@@ -5,7 +5,11 @@ import { zValidator } from "@hono/zod-validator";
|
|||||||
import { Inngest } from "inngest";
|
import { Inngest } from "inngest";
|
||||||
import { serve as serveInngest } from "inngest/hono";
|
import { serve as serveInngest } from "inngest/hono";
|
||||||
import { logger } from "./logger.js";
|
import { logger } from "./logger.js";
|
||||||
import { type DeployJob, deployJobSchema } from "./schema.js";
|
import {
|
||||||
|
cancelDeploymentSchema,
|
||||||
|
type DeployJob,
|
||||||
|
deployJobSchema,
|
||||||
|
} from "./schema.js";
|
||||||
import { deploy } from "./utils.js";
|
import { deploy } from "./utils.js";
|
||||||
|
|
||||||
const app = new Hono();
|
const app = new Hono();
|
||||||
@@ -27,6 +31,13 @@ export const deploymentFunction = inngest.createFunction(
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
retries: 0,
|
retries: 0,
|
||||||
|
cancelOn: [
|
||||||
|
{
|
||||||
|
event: "deployment/cancelled",
|
||||||
|
if: "async.data.applicationId == event.data.applicationId || async.data.composeId == event.data.composeId",
|
||||||
|
timeout: "1h", // Allow cancellation for up to 1 hour
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{ event: "deployment/requested" },
|
{ event: "deployment/requested" },
|
||||||
|
|
||||||
@@ -119,6 +130,48 @@ app.post("/deploy", zValidator("json", deployJobSchema), async (c) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.post(
|
||||||
|
"/cancel-deployment",
|
||||||
|
zValidator("json", cancelDeploymentSchema),
|
||||||
|
async (c) => {
|
||||||
|
const data = c.req.valid("json");
|
||||||
|
logger.info("Received cancel deployment request", data);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Send cancellation event to Inngest
|
||||||
|
|
||||||
|
await inngest.send({
|
||||||
|
name: "deployment/cancelled",
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
|
||||||
|
const identifier =
|
||||||
|
data.applicationType === "application"
|
||||||
|
? `applicationId: ${data.applicationId}`
|
||||||
|
: `composeId: ${data.composeId}`;
|
||||||
|
|
||||||
|
logger.info("Deployment cancellation event sent", {
|
||||||
|
...data,
|
||||||
|
identifier,
|
||||||
|
});
|
||||||
|
|
||||||
|
return c.json({
|
||||||
|
message: "Deployment cancellation requested",
|
||||||
|
applicationType: data.applicationType,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Failed to send deployment cancellation event", error);
|
||||||
|
return c.json(
|
||||||
|
{
|
||||||
|
message: "Failed to cancel deployment",
|
||||||
|
error: error instanceof Error ? error.message : String(error),
|
||||||
|
},
|
||||||
|
500,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
app.get("/health", async (c) => {
|
app.get("/health", async (c) => {
|
||||||
return c.json({ status: "ok" });
|
return c.json({ status: "ok" });
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -32,3 +32,16 @@ export const deployJobSchema = z.discriminatedUnion("applicationType", [
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
export type DeployJob = z.infer<typeof deployJobSchema>;
|
export type DeployJob = z.infer<typeof deployJobSchema>;
|
||||||
|
|
||||||
|
export const cancelDeploymentSchema = z.discriminatedUnion("applicationType", [
|
||||||
|
z.object({
|
||||||
|
applicationId: z.string(),
|
||||||
|
applicationType: z.literal("application"),
|
||||||
|
}),
|
||||||
|
z.object({
|
||||||
|
composeId: z.string(),
|
||||||
|
applicationType: z.literal("compose"),
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
export type CancelDeploymentJob = z.infer<typeof cancelDeploymentSchema>;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Clock, Loader2, RefreshCcw, RocketIcon, Settings } from "lucide-react";
|
import { Clock, Loader2, RefreshCcw, RocketIcon, Settings } from "lucide-react";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useMemo, useState } from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
import { AlertBlock } from "@/components/shared/alert-block";
|
||||||
import { DateTooltip } from "@/components/shared/date-tooltip";
|
import { DateTooltip } from "@/components/shared/date-tooltip";
|
||||||
import { DialogAction } from "@/components/shared/dialog-action";
|
import { DialogAction } from "@/components/shared/dialog-action";
|
||||||
import { StatusTooltip } from "@/components/shared/status-tooltip";
|
import { StatusTooltip } from "@/components/shared/status-tooltip";
|
||||||
@@ -61,12 +62,48 @@ export const ShowDeployments = ({
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const { data: isCloud } = api.settings.isCloud.useQuery();
|
||||||
|
|
||||||
const { mutateAsync: rollback, isLoading: isRollingBack } =
|
const { mutateAsync: rollback, isLoading: isRollingBack } =
|
||||||
api.rollback.rollback.useMutation();
|
api.rollback.rollback.useMutation();
|
||||||
const { mutateAsync: killProcess, isLoading: isKillingProcess } =
|
const { mutateAsync: killProcess, isLoading: isKillingProcess } =
|
||||||
api.deployment.killProcess.useMutation();
|
api.deployment.killProcess.useMutation();
|
||||||
|
|
||||||
|
// Cancel deployment mutations
|
||||||
|
const {
|
||||||
|
mutateAsync: cancelApplicationDeployment,
|
||||||
|
isLoading: isCancellingApp,
|
||||||
|
} = api.application.cancelDeployment.useMutation();
|
||||||
|
const {
|
||||||
|
mutateAsync: cancelComposeDeployment,
|
||||||
|
isLoading: isCancellingCompose,
|
||||||
|
} = api.compose.cancelDeployment.useMutation();
|
||||||
|
|
||||||
const [url, setUrl] = React.useState("");
|
const [url, setUrl] = React.useState("");
|
||||||
|
|
||||||
|
// Check for stuck deployment (more than 9 minutes) - only for the most recent deployment
|
||||||
|
const stuckDeployment = useMemo(() => {
|
||||||
|
if (!isCloud || !deployments || deployments.length === 0) return null;
|
||||||
|
|
||||||
|
const now = Date.now();
|
||||||
|
const NINE_MINUTES = 10 * 60 * 1000; // 9 minutes in milliseconds
|
||||||
|
|
||||||
|
// Get the most recent deployment (first in the list since they're sorted by date)
|
||||||
|
const mostRecentDeployment = deployments[0];
|
||||||
|
|
||||||
|
if (
|
||||||
|
!mostRecentDeployment ||
|
||||||
|
mostRecentDeployment.status !== "running" ||
|
||||||
|
!mostRecentDeployment.startedAt
|
||||||
|
) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const startTime = new Date(mostRecentDeployment.startedAt).getTime();
|
||||||
|
const elapsed = now - startTime;
|
||||||
|
|
||||||
|
return elapsed > NINE_MINUTES ? mostRecentDeployment : null;
|
||||||
|
}, [isCloud, deployments]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setUrl(document.location.origin);
|
setUrl(document.location.origin);
|
||||||
}, []);
|
}, []);
|
||||||
@@ -94,6 +131,54 @@ export const ShowDeployments = ({
|
|||||||
</div>
|
</div>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="flex flex-col gap-4">
|
<CardContent className="flex flex-col gap-4">
|
||||||
|
{stuckDeployment && (type === "application" || type === "compose") && (
|
||||||
|
<AlertBlock
|
||||||
|
type="warning"
|
||||||
|
className="flex-col items-start w-full p-4"
|
||||||
|
>
|
||||||
|
<div className="flex flex-col gap-3">
|
||||||
|
<div>
|
||||||
|
<div className="font-medium text-sm mb-1">
|
||||||
|
Build appears to be stuck
|
||||||
|
</div>
|
||||||
|
<p className="text-sm">
|
||||||
|
Hey! Looks like the build has been running for more than 10
|
||||||
|
minutes. Would you like to cancel this deployment?
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
variant="destructive"
|
||||||
|
size="sm"
|
||||||
|
className="w-fit"
|
||||||
|
isLoading={
|
||||||
|
type === "application" ? isCancellingApp : isCancellingCompose
|
||||||
|
}
|
||||||
|
onClick={async () => {
|
||||||
|
try {
|
||||||
|
if (type === "application") {
|
||||||
|
await cancelApplicationDeployment({
|
||||||
|
applicationId: id,
|
||||||
|
});
|
||||||
|
} else if (type === "compose") {
|
||||||
|
await cancelComposeDeployment({
|
||||||
|
composeId: id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
toast.success("Deployment cancellation requested");
|
||||||
|
} catch (error) {
|
||||||
|
toast.error(
|
||||||
|
error instanceof Error
|
||||||
|
? error.message
|
||||||
|
: "Failed to cancel deployment",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Cancel Deployment
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</AlertBlock>
|
||||||
|
)}
|
||||||
{refreshToken && (
|
{refreshToken && (
|
||||||
<div className="flex flex-col gap-2 text-sm">
|
<div className="flex flex-col gap-2 text-sm">
|
||||||
<span>
|
<span>
|
||||||
|
|||||||
@@ -102,9 +102,9 @@ export const ShowExternalMariadbCredentials = ({ mariadbId }: Props) => {
|
|||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="text-xl">External Credentials</CardTitle>
|
<CardTitle className="text-xl">External Credentials</CardTitle>
|
||||||
<CardDescription>
|
<CardDescription>
|
||||||
In order to make the database reachable through the internet,
|
In order to make the database reachable through the internet, you
|
||||||
you must set a port and ensure that the port is not being used by another
|
must set a port and ensure that the port is not being used by
|
||||||
application or database
|
another application or database
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="flex w-full flex-col gap-4">
|
<CardContent className="flex w-full flex-col gap-4">
|
||||||
|
|||||||
@@ -102,9 +102,9 @@ export const ShowExternalMongoCredentials = ({ mongoId }: Props) => {
|
|||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="text-xl">External Credentials</CardTitle>
|
<CardTitle className="text-xl">External Credentials</CardTitle>
|
||||||
<CardDescription>
|
<CardDescription>
|
||||||
In order to make the database reachable through the internet,
|
In order to make the database reachable through the internet, you
|
||||||
you must set a port and ensure that the port is not being used by another
|
must set a port and ensure that the port is not being used by
|
||||||
application or database
|
another application or database
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="flex w-full flex-col gap-4">
|
<CardContent className="flex w-full flex-col gap-4">
|
||||||
|
|||||||
@@ -102,9 +102,9 @@ export const ShowExternalMysqlCredentials = ({ mysqlId }: Props) => {
|
|||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="text-xl">External Credentials</CardTitle>
|
<CardTitle className="text-xl">External Credentials</CardTitle>
|
||||||
<CardDescription>
|
<CardDescription>
|
||||||
In order to make the database reachable through the internet,
|
In order to make the database reachable through the internet, you
|
||||||
you must set a port and ensure that the port is not being used by another
|
must set a port and ensure that the port is not being used by
|
||||||
application or database
|
another application or database
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="flex w-full flex-col gap-4">
|
<CardContent className="flex w-full flex-col gap-4">
|
||||||
|
|||||||
@@ -104,9 +104,9 @@ export const ShowExternalPostgresCredentials = ({ postgresId }: Props) => {
|
|||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="text-xl">External Credentials</CardTitle>
|
<CardTitle className="text-xl">External Credentials</CardTitle>
|
||||||
<CardDescription>
|
<CardDescription>
|
||||||
In order to make the database reachable through the internet,
|
In order to make the database reachable through the internet, you
|
||||||
you must set a port and ensure that the port is not being used by another
|
must set a port and ensure that the port is not being used by
|
||||||
application or database
|
another application or database
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="flex w-full flex-col gap-4">
|
<CardContent className="flex w-full flex-col gap-4">
|
||||||
|
|||||||
@@ -80,6 +80,29 @@ export const DuplicateProject = ({
|
|||||||
api.project.duplicate.useMutation({
|
api.project.duplicate.useMutation({
|
||||||
onSuccess: async (newProject) => {
|
onSuccess: async (newProject) => {
|
||||||
await utils.project.all.invalidate();
|
await utils.project.all.invalidate();
|
||||||
|
|
||||||
|
// If duplicating to same project+environment, invalidate the environment query
|
||||||
|
// to refresh the services list
|
||||||
|
if (duplicateType === "existing-environment") {
|
||||||
|
await utils.environment.one.invalidate({
|
||||||
|
environmentId: selectedTargetEnvironment,
|
||||||
|
});
|
||||||
|
await utils.environment.byProjectId.invalidate({
|
||||||
|
projectId: selectedTargetProject,
|
||||||
|
});
|
||||||
|
|
||||||
|
// If duplicating to the same environment we're currently viewing,
|
||||||
|
// also invalidate the current environment to refresh the services list
|
||||||
|
if (selectedTargetEnvironment === environmentId) {
|
||||||
|
await utils.environment.one.invalidate({ environmentId });
|
||||||
|
// Also invalidate the project query to refresh the project data
|
||||||
|
const projectId = router.query.projectId as string;
|
||||||
|
if (projectId) {
|
||||||
|
await utils.project.one.invalidate({ projectId });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
toast.success(
|
toast.success(
|
||||||
duplicateType === "new-project"
|
duplicateType === "new-project"
|
||||||
? "Project duplicated successfully"
|
? "Project duplicated successfully"
|
||||||
|
|||||||
@@ -96,9 +96,9 @@ export const ShowExternalRedisCredentials = ({ redisId }: Props) => {
|
|||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="text-xl">External Credentials</CardTitle>
|
<CardTitle className="text-xl">External Credentials</CardTitle>
|
||||||
<CardDescription>
|
<CardDescription>
|
||||||
In order to make the database reachable through the internet,
|
In order to make the database reachable through the internet, you
|
||||||
you must set a port and ensure that the port is not being used by another
|
must set a port and ensure that the port is not being used by
|
||||||
application or database
|
another application or database
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="flex w-full flex-col gap-4">
|
<CardContent className="flex w-full flex-col gap-4">
|
||||||
|
|||||||
@@ -89,7 +89,6 @@ export const SearchCommand = () => {
|
|||||||
<CommandGroup heading={"Projects"}>
|
<CommandGroup heading={"Projects"}>
|
||||||
<CommandList>
|
<CommandList>
|
||||||
{data?.map((project) => {
|
{data?.map((project) => {
|
||||||
console.log("project", project);
|
|
||||||
const productionEnvironment = project.environments.find(
|
const productionEnvironment = project.environments.find(
|
||||||
(environment) => environment.name === "production",
|
(environment) => environment.name === "production",
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -97,11 +97,7 @@ export const ShowTraefikActions = ({ serverId }: Props) => {
|
|||||||
);
|
);
|
||||||
refetchDashboard();
|
refetchDashboard();
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {});
|
||||||
toast.error(
|
|
||||||
`${haveTraefikDashboardPortEnabled ? "Disabled" : "Enabled"} Dashboard`,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}}
|
}}
|
||||||
className="w-full cursor-pointer space-x-3"
|
className="w-full cursor-pointer space-x-3"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "dokploy",
|
"name": "dokploy",
|
||||||
"version": "v0.25.0",
|
"version": "v0.25.2",
|
||||||
"private": true,
|
"private": true,
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import {
|
|||||||
unzipDrop,
|
unzipDrop,
|
||||||
updateApplication,
|
updateApplication,
|
||||||
updateApplicationStatus,
|
updateApplicationStatus,
|
||||||
|
updateDeploymentStatus,
|
||||||
writeConfig,
|
writeConfig,
|
||||||
writeConfigRemote,
|
writeConfigRemote,
|
||||||
// uploadFileSchema
|
// uploadFileSchema
|
||||||
@@ -58,7 +59,7 @@ import {
|
|||||||
} from "@/server/db/schema";
|
} from "@/server/db/schema";
|
||||||
import type { DeploymentJob } from "@/server/queues/queue-types";
|
import type { DeploymentJob } from "@/server/queues/queue-types";
|
||||||
import { cleanQueuesByApplication, myQueue } from "@/server/queues/queueSetup";
|
import { cleanQueuesByApplication, myQueue } from "@/server/queues/queueSetup";
|
||||||
import { deploy } from "@/server/utils/deploy";
|
import { cancelDeployment, deploy } from "@/server/utils/deploy";
|
||||||
import { uploadFileSchema } from "@/utils/schema";
|
import { uploadFileSchema } from "@/utils/schema";
|
||||||
|
|
||||||
export const applicationRouter = createTRPCRouter({
|
export const applicationRouter = createTRPCRouter({
|
||||||
@@ -896,4 +897,55 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
|
|
||||||
return updatedApplication;
|
return updatedApplication;
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
cancelDeployment: protectedProcedure
|
||||||
|
.input(apiFindOneApplication)
|
||||||
|
.mutation(async ({ input, ctx }) => {
|
||||||
|
const application = await findApplicationById(input.applicationId);
|
||||||
|
if (
|
||||||
|
application.environment.project.organizationId !==
|
||||||
|
ctx.session.activeOrganizationId
|
||||||
|
) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "UNAUTHORIZED",
|
||||||
|
message: "You are not authorized to cancel this deployment",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IS_CLOUD && application.serverId) {
|
||||||
|
try {
|
||||||
|
await updateApplicationStatus(input.applicationId, "idle");
|
||||||
|
|
||||||
|
if (application.deployments[0]) {
|
||||||
|
await updateDeploymentStatus(
|
||||||
|
application.deployments[0].deploymentId,
|
||||||
|
"done",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await cancelDeployment({
|
||||||
|
applicationId: input.applicationId,
|
||||||
|
applicationType: "application",
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Deployment cancellation requested",
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "INTERNAL_SERVER_ERROR",
|
||||||
|
message:
|
||||||
|
error instanceof Error
|
||||||
|
? error.message
|
||||||
|
: "Failed to cancel deployment",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "BAD_REQUEST",
|
||||||
|
message: "Deployment cancellation only available in cloud version",
|
||||||
|
});
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import {
|
|||||||
startCompose,
|
startCompose,
|
||||||
stopCompose,
|
stopCompose,
|
||||||
updateCompose,
|
updateCompose,
|
||||||
|
updateDeploymentStatus,
|
||||||
} from "@dokploy/server";
|
} from "@dokploy/server";
|
||||||
import {
|
import {
|
||||||
type CompleteTemplate,
|
type CompleteTemplate,
|
||||||
@@ -58,7 +59,7 @@ import {
|
|||||||
} from "@/server/db/schema";
|
} from "@/server/db/schema";
|
||||||
import type { DeploymentJob } from "@/server/queues/queue-types";
|
import type { DeploymentJob } from "@/server/queues/queue-types";
|
||||||
import { cleanQueuesByCompose, myQueue } from "@/server/queues/queueSetup";
|
import { cleanQueuesByCompose, myQueue } from "@/server/queues/queueSetup";
|
||||||
import { deploy } from "@/server/utils/deploy";
|
import { cancelDeployment, deploy } from "@/server/utils/deploy";
|
||||||
import { generatePassword } from "@/templates/utils";
|
import { generatePassword } from "@/templates/utils";
|
||||||
import { createTRPCRouter, protectedProcedure, publicProcedure } from "../trpc";
|
import { createTRPCRouter, protectedProcedure, publicProcedure } from "../trpc";
|
||||||
|
|
||||||
@@ -928,4 +929,57 @@ export const composeRouter = createTRPCRouter({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
cancelDeployment: protectedProcedure
|
||||||
|
.input(apiFindCompose)
|
||||||
|
.mutation(async ({ input, ctx }) => {
|
||||||
|
const compose = await findComposeById(input.composeId);
|
||||||
|
if (
|
||||||
|
compose.environment.project.organizationId !==
|
||||||
|
ctx.session.activeOrganizationId
|
||||||
|
) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "UNAUTHORIZED",
|
||||||
|
message: "You are not authorized to cancel this deployment",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IS_CLOUD && compose.serverId) {
|
||||||
|
try {
|
||||||
|
await updateCompose(input.composeId, {
|
||||||
|
composeStatus: "idle",
|
||||||
|
});
|
||||||
|
|
||||||
|
if (compose.deployments[0]) {
|
||||||
|
await updateDeploymentStatus(
|
||||||
|
compose.deployments[0].deploymentId,
|
||||||
|
"done",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await cancelDeployment({
|
||||||
|
composeId: input.composeId,
|
||||||
|
applicationType: "compose",
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Deployment cancellation requested",
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "INTERNAL_SERVER_ERROR",
|
||||||
|
message:
|
||||||
|
error instanceof Error
|
||||||
|
? error.message
|
||||||
|
: "Failed to cancel deployment",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "BAD_REQUEST",
|
||||||
|
message: "Deployment cancellation only available in cloud version",
|
||||||
|
});
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -23,3 +23,30 @@ export const deploy = async (jobData: DeploymentJob) => {
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type CancelDeploymentData =
|
||||||
|
| { applicationId: string; applicationType: "application" }
|
||||||
|
| { composeId: string; applicationType: "compose" };
|
||||||
|
|
||||||
|
export const cancelDeployment = async (cancelData: CancelDeploymentData) => {
|
||||||
|
try {
|
||||||
|
const result = await fetch(`${process.env.SERVER_URL}/cancel-deployment`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"X-API-Key": process.env.API_KEY || "NO-DEFINED",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(cancelData),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!result.ok) {
|
||||||
|
const errorData = await result.json().catch(() => ({}));
|
||||||
|
throw new Error(errorData.message || "Failed to cancel deployment");
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await result.json();
|
||||||
|
return data;
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
} from "./queue.js";
|
} from "./queue.js";
|
||||||
import { jobQueueSchema } from "./schema.js";
|
import { jobQueueSchema } from "./schema.js";
|
||||||
import { initializeJobs } from "./utils.js";
|
import { initializeJobs } from "./utils.js";
|
||||||
import { firstWorker, secondWorker } from "./workers.js";
|
import { firstWorker, secondWorker, thirdWorker } from "./workers.js";
|
||||||
|
|
||||||
const app = new Hono();
|
const app = new Hono();
|
||||||
|
|
||||||
@@ -91,6 +91,7 @@ export const gracefulShutdown = async (signal: string) => {
|
|||||||
logger.warn(`Received ${signal}, closing server...`);
|
logger.warn(`Received ${signal}, closing server...`);
|
||||||
await firstWorker.close();
|
await firstWorker.close();
|
||||||
await secondWorker.close();
|
await secondWorker.close();
|
||||||
|
await thirdWorker.close();
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -7,22 +7,34 @@ import { runJobs } from "./utils.js";
|
|||||||
export const firstWorker = new Worker(
|
export const firstWorker = new Worker(
|
||||||
"backupQueue",
|
"backupQueue",
|
||||||
async (job: Job<QueueJob>) => {
|
async (job: Job<QueueJob>) => {
|
||||||
logger.info({ data: job.data }, "Running job");
|
logger.info({ data: job.data }, "Running job first worker");
|
||||||
await runJobs(job.data);
|
await runJobs(job.data);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
concurrency: 50,
|
concurrency: 100,
|
||||||
connection,
|
connection,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
export const secondWorker = new Worker(
|
export const secondWorker = new Worker(
|
||||||
"backupQueue",
|
"backupQueue",
|
||||||
async (job: Job<QueueJob>) => {
|
async (job: Job<QueueJob>) => {
|
||||||
logger.info({ data: job.data }, "Running job");
|
logger.info({ data: job.data }, "Running job second worker");
|
||||||
await runJobs(job.data);
|
await runJobs(job.data);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
concurrency: 50,
|
concurrency: 100,
|
||||||
|
connection,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export const thirdWorker = new Worker(
|
||||||
|
"backupQueue",
|
||||||
|
async (job: Job<QueueJob>) => {
|
||||||
|
logger.info({ data: job.data }, "Running job third worker");
|
||||||
|
await runJobs(job.data);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
concurrency: 100,
|
||||||
connection,
|
connection,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -342,6 +342,8 @@ export const readPorts = async (
|
|||||||
command = `docker service inspect ${resourceName} --format '{{json .Spec.EndpointSpec.Ports}}'`;
|
command = `docker service inspect ${resourceName} --format '{{json .Spec.EndpointSpec.Ports}}'`;
|
||||||
} else if (resourceType === "standalone") {
|
} else if (resourceType === "standalone") {
|
||||||
command = `docker container inspect ${resourceName} --format '{{json .NetworkSettings.Ports}}'`;
|
command = `docker container inspect ${resourceName} --format '{{json .NetworkSettings.Ports}}'`;
|
||||||
|
} else {
|
||||||
|
throw new Error("Resource type not found");
|
||||||
}
|
}
|
||||||
let result = "";
|
let result = "";
|
||||||
if (serverId) {
|
if (serverId) {
|
||||||
@@ -397,17 +399,20 @@ export const writeTraefikSetup = async (input: TraefikOptions) => {
|
|||||||
"dokploy-traefik",
|
"dokploy-traefik",
|
||||||
input.serverId,
|
input.serverId,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (resourceType === "service") {
|
if (resourceType === "service") {
|
||||||
await initializeTraefikService({
|
await initializeTraefikService({
|
||||||
env: input.env,
|
env: input.env,
|
||||||
additionalPorts: input.additionalPorts,
|
additionalPorts: input.additionalPorts,
|
||||||
serverId: input.serverId,
|
serverId: input.serverId,
|
||||||
});
|
});
|
||||||
} else {
|
} else if (resourceType === "standalone") {
|
||||||
await initializeStandaloneTraefik({
|
await initializeStandaloneTraefik({
|
||||||
env: input.env,
|
env: input.env,
|
||||||
additionalPorts: input.additionalPorts,
|
additionalPorts: input.additionalPorts,
|
||||||
serverId: input.serverId,
|
serverId: input.serverId,
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
throw new Error("Traefik resource type not found");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -87,16 +87,27 @@ export const initializeStandaloneTraefik = async ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const docker = await getRemoteDocker(serverId);
|
const docker = await getRemoteDocker(serverId);
|
||||||
|
try {
|
||||||
|
await docker.pull(imageName);
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 3000));
|
||||||
|
console.log("Traefik Image Pulled ✅");
|
||||||
|
} catch (error) {
|
||||||
|
console.log("Traefik Image Not Found: Pulling ", error);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const container = docker.getContainer(containerName);
|
const container = docker.getContainer(containerName);
|
||||||
await container.remove({ force: true });
|
await container.remove({ force: true });
|
||||||
await new Promise((resolve) => setTimeout(resolve, 5000));
|
await new Promise((resolve) => setTimeout(resolve, 5000));
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|
||||||
await docker.createContainer(settings);
|
try {
|
||||||
const newContainer = docker.getContainer(containerName);
|
await docker.createContainer(settings);
|
||||||
await newContainer.start();
|
const newContainer = docker.getContainer(containerName);
|
||||||
console.log("Traefik Started ✅");
|
await newContainer.start();
|
||||||
|
console.log("Traefik Started ✅");
|
||||||
|
} catch (error) {
|
||||||
|
console.log("Traefik Not Found: Starting ", error);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const initializeTraefikService = async ({
|
export const initializeTraefikService = async ({
|
||||||
|
|||||||
@@ -251,11 +251,15 @@ export const addDomainToCompose = async (
|
|||||||
}
|
}
|
||||||
labels.unshift(...httpLabels);
|
labels.unshift(...httpLabels);
|
||||||
if (!compose.isolatedDeployment) {
|
if (!compose.isolatedDeployment) {
|
||||||
if (!labels.includes("traefik.docker.network=dokploy-network")) {
|
if (compose.composeType === "docker-compose") {
|
||||||
labels.unshift("traefik.docker.network=dokploy-network");
|
if (!labels.includes("traefik.docker.network=dokploy-network")) {
|
||||||
}
|
labels.unshift("traefik.docker.network=dokploy-network");
|
||||||
if (!labels.includes("traefik.swarm.network=dokploy-network")) {
|
}
|
||||||
labels.unshift("traefik.swarm.network=dokploy-network");
|
} else {
|
||||||
|
// Stack Case
|
||||||
|
if (!labels.includes("traefik.swarm.network=dokploy-network")) {
|
||||||
|
labels.unshift("traefik.swarm.network=dokploy-network");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ export const cloneGithubRepository = async ({
|
|||||||
const cloneUrl = `https://oauth2:${token}@${repoclone}`;
|
const cloneUrl = `https://oauth2:${token}@${repoclone}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
writeStream.write(`\nClonning Repo ${repoclone} to ${outputPath}: ✅\n`);
|
writeStream.write(`\nCloning Repo ${repoclone} to ${outputPath}: ✅\n`);
|
||||||
const cloneArgs = [
|
const cloneArgs = [
|
||||||
"clone",
|
"clone",
|
||||||
"--branch",
|
"--branch",
|
||||||
|
|||||||
Reference in New Issue
Block a user