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 @@ -34,13 +34,13 @@ import { ShowDeployment } from "./show-deployment";
interface Props {
id: string;
type:
| "application"
| "compose"
| "schedule"
| "server"
| "backup"
| "previewDeployment"
| "volumeBackup";
| "application"
| "compose"
| "schedule"
| "server"
| "backup"
| "previewDeployment"
| "volumeBackup";
refreshToken?: string;
serverId?: string;
}
Expand Down Expand Up @@ -225,9 +225,8 @@ export const ShowDeployments = ({
<span>Webhook URL: </span>
<div className="flex flex-row items-center gap-2">
<span className="break-all text-muted-foreground">
{`${url}/api/deploy${
type === "compose" ? "/compose" : ""
}/${refreshToken}`}
{`${url}/api/deploy${type === "compose" ? "/compose" : ""
}/${refreshToken}`}
</span>
{(type === "application" || type === "compose") && (
<RefreshToken id={id} type={type} />
Expand Down Expand Up @@ -335,7 +334,7 @@ export const ShowDeployments = ({
Math.floor(
(new Date(deployment.finishedAt).getTime() -
new Date(deployment.startedAt).getTime()) /
1000,
1000,
),
)}
</Badge>
Expand Down Expand Up @@ -408,7 +407,7 @@ export const ShowDeployments = ({

{deployment?.rollback &&
deployment.status === "done" &&
type === "application" && (
(type === "application" || type === "compose") && (
<DialogAction
title="Rollback to this deployment"
description={
Expand All @@ -418,8 +417,7 @@ export const ShowDeployments = ({
deployment?
</p>
<AlertBlock type="info" className="text-sm">
Please wait a few seconds while the image is
pulled from the registry. Your application
Please wait a few seconds while the previous version is deployed. Your service
should be running shortly.
</AlertBlock>
</div>
Expand Down
9 changes: 6 additions & 3 deletions apps/dokploy/server/api/routers/rollbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ export const rollbackRouter = createTRPCRouter({
.mutation(async ({ input, ctx }) => {
try {
const currentRollback = await findRollbackById(input.rollbackId);
if (
const organizationId =
currentRollback?.deployment?.application?.environment?.project
.organizationId !== ctx.session.activeOrganizationId
) {
?.organizationId ??
currentRollback?.deployment?.compose?.environment?.project
?.organizationId;

if (!organizationId || organizationId !== ctx.session.activeOrganizationId) {
throw new TRPCError({
code: "UNAUTHORIZED",
message: "You are not authorized to rollback this deployment",
Expand Down
12 changes: 10 additions & 2 deletions packages/server/src/db/schema/rollbacks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Application } from "@dokploy/server/services/application";
import type { Compose } from "@dokploy/server/services/compose";
import type { Mount } from "@dokploy/server/services/mount";
import type { Port } from "@dokploy/server/services/port";
import type { Project } from "@dokploy/server/services/project";
Expand Down Expand Up @@ -26,14 +27,20 @@ export const rollbacks = pgTable("rollback", {
.notNull()
.$defaultFn(() => new Date().toISOString()),
fullContext: jsonb("fullContext").$type<
Application & {
| (Application & {
environment: {
project: Project;
};
mounts: Mount[];
ports: Port[];
registry?: Registry | null;
}
})
| (Compose & {
environment: {
project: Project;
};
commitHash?: string;
})
>(),
});

Expand All @@ -48,6 +55,7 @@ export const rollbacksRelations = relations(rollbacks, ({ one }) => ({

export const createRollbackSchema = createInsertSchema(rollbacks).extend({
appName: z.string().min(1),
commitHash: z.string().optional(),
});

export const updateRollbackSchema = createRollbackSchema.extend({
Expand Down
42 changes: 32 additions & 10 deletions packages/server/src/services/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,19 @@ export const deployCompose = async ({
composeId,
titleLog = "Manual deployment",
descriptionLog = "",
commitHash,
isRollback = false,
}: {
composeId: string;
titleLog: string;
descriptionLog: string;
titleLog?: string;
descriptionLog?: string;
commitHash?: string;
isRollback?: boolean;
}) => {
const compose = await findComposeById(composeId);

const buildLink = `${await getDokployUrl()}/dashboard/project/${
compose.environment.projectId
}/environment/${compose.environmentId}/services/compose/${compose.composeId}?tab=deployments`;
const buildLink = `${await getDokployUrl()}/dashboard/project/${compose.environment.projectId
}/environment/${compose.environmentId}/services/compose/${compose.composeId}?tab=deployments`;
const deployment = await createDeploymentCompose({
composeId: composeId,
title: titleLog,
Expand All @@ -229,6 +232,7 @@ export const deployCompose = async ({
const entity = {
...compose,
type: "compose" as const,
commitHash,
};
let command = "set -e;";
if (compose.sourceType === "github") {
Expand Down Expand Up @@ -273,6 +277,26 @@ export const deployCompose = async ({
composeStatus: "done",
});

if (!isRollback) {
let hashToSave = commitHash;
if (compose.sourceType !== "raw" && !hashToSave) {
const commitInfo = await getGitCommitInfo({
...compose,
type: "compose",
});
if (commitInfo) {
hashToSave = commitInfo.hash;
}
}

const { createRollback } = await import("./rollbacks");
await createRollback({
appName: compose.name,
deploymentId: deployment.deploymentId,
commitHash: hashToSave,
});
}

await sendBuildSuccessNotifications({
projectName: compose.environment.project.name,
applicationName: compose.name,
Expand Down Expand Up @@ -417,9 +441,8 @@ export const removeCompose = async (
} else {
const command = `
docker network disconnect ${compose.appName} dokploy-traefik;
cd ${projectPath} && env -i PATH="$PATH" docker compose -p ${compose.appName} down ${
deleteVolumes ? "--volumes" : ""
} && rm -rf ${projectPath}`;
cd ${projectPath} && env -i PATH="$PATH" docker compose -p ${compose.appName} down ${deleteVolumes ? "--volumes" : ""
} && rm -rf ${projectPath}`;

if (compose.serverId) {
await execAsyncRemote(compose.serverId, command);
Expand Down Expand Up @@ -479,8 +502,7 @@ export const stopCompose = async (composeId: string) => {
if (compose.serverId) {
await execAsyncRemote(
compose.serverId,
`cd ${join(COMPOSE_PATH, compose.appName)} && env -i PATH="$PATH" docker compose -p ${
compose.appName
`cd ${join(COMPOSE_PATH, compose.appName)} && env -i PATH="$PATH" docker compose -p ${compose.appName
} stop`,
);
} else {
Expand Down
Loading