Skip to content

Commit 2a89be6

Browse files
authored
Merge pull request #2069 from Dokploy/2065-rollback-feature-dns-issues
feat(rollbacks): enhance fullContext type and refactor createRollback…
2 parents 892f272 + 412bb9e commit 2a89be6

File tree

5 files changed

+39
-21
lines changed

5 files changed

+39
-21
lines changed

apps/dokploy/components/dashboard/application/rollbacks/show-rollback-settings.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { AlertBlock } from "@/components/shared/alert-block";
12
import { Button } from "@/components/ui/button";
23
import {
34
Dialog,
@@ -79,6 +80,11 @@ export const ShowRollbackSettings = ({ applicationId, children }: Props) => {
7980
<DialogDescription>
8081
Configure how rollbacks work for this application
8182
</DialogDescription>
83+
<AlertBlock>
84+
Having rollbacks enabled increases storage usage. Be careful with
85+
this option. Note that manually cleaning the cache may delete
86+
rollback images, making them unavailable for future rollbacks.
87+
</AlertBlock>
8288
</DialogHeader>
8389

8490
<Form {...form}>

apps/dokploy/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dokploy",
3-
"version": "v0.23.2",
3+
"version": "v0.23.3",
44
"private": true,
55
"license": "Apache-2.0",
66
"type": "module",

apps/dokploy/reset-2fa.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@ import { users_temp } from "@dokploy/server/db/schema";
44
import { eq } from "drizzle-orm";
55

66
(async () => {
7-
try {
8-
const result = await findAdmin();
7+
try {
8+
const result = await findAdmin();
99

10-
const update = await db
11-
.update(users_temp)
12-
.set({
13-
twoFactorEnabled: false,
14-
})
15-
.where(eq(users_temp.id, result.userId));
10+
const update = await db
11+
.update(users_temp)
12+
.set({
13+
twoFactorEnabled: false,
14+
})
15+
.where(eq(users_temp.id, result.userId));
1616

17-
if (update) {
18-
console.log("2FA reset successful");
19-
} else {
20-
console.log("Password reset failed");
21-
}
17+
if (update) {
18+
console.log("2FA reset successful");
19+
} else {
20+
console.log("Password reset failed");
21+
}
2222

23-
process.exit(0);
24-
} catch (error) {
25-
console.log("Error resetting 2FA", error);
26-
}
23+
process.exit(0);
24+
} catch (error) {
25+
console.log("Error resetting 2FA", error);
26+
}
2727
})();

packages/server/src/db/schema/rollbacks.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { createInsertSchema } from "drizzle-zod";
44
import { nanoid } from "nanoid";
55
import { z } from "zod";
66
import { deployments } from "./deployment";
7+
import type { Application } from "@dokploy/server/services/application";
8+
import type { Project } from "@dokploy/server/services/project";
79

810
export const rollbacks = pgTable("rollback", {
911
rollbackId: text("rollbackId")
@@ -20,7 +22,7 @@ export const rollbacks = pgTable("rollback", {
2022
createdAt: text("createdAt")
2123
.notNull()
2224
.$defaultFn(() => new Date().toISOString()),
23-
fullContext: jsonb("fullContext"),
25+
fullContext: jsonb("fullContext").$type<Application & { project: Project }>(),
2426
});
2527

2628
export type Rollback = typeof rollbacks.$inferSelect;

packages/server/src/services/rollbacks.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ import type { ApplicationNested } from "../utils/builders";
1212
import { execAsync, execAsyncRemote } from "../utils/process/execAsync";
1313
import type { CreateServiceOptions } from "dockerode";
1414
import { findDeploymentById } from "./deployment";
15+
import { prepareEnvironmentVariables } from "../utils/docker/utils";
1516

1617
export const createRollback = async (
1718
input: z.infer<typeof createRollbackSchema>,
1819
) => {
1920
await db.transaction(async (tx) => {
21+
const { fullContext, ...other } = input;
2022
const rollback = await tx
2123
.insert(rollbacks)
22-
.values(input)
24+
.values(other)
2325
.returning()
2426
.then((res) => res[0]);
2527

@@ -47,7 +49,7 @@ export const createRollback = async (
4749
.update(rollbacks)
4850
.set({
4951
image: tagImage,
50-
fullContext: JSON.stringify(rest),
52+
fullContext: rest,
5153
})
5254
.where(eq(rollbacks.rollbackId, rollback.rollbackId));
5355

@@ -150,17 +152,24 @@ export const rollback = async (rollbackId: string) => {
150152

151153
const application = await findApplicationById(deployment.applicationId);
152154

155+
const envVariables = prepareEnvironmentVariables(
156+
result?.fullContext?.env || "",
157+
result.fullContext?.project?.env || "",
158+
);
159+
153160
await rollbackApplication(
154161
application.appName,
155162
result.image || "",
156163
application.serverId,
164+
envVariables,
157165
);
158166
};
159167

160168
const rollbackApplication = async (
161169
appName: string,
162170
image: string,
163171
serverId?: string | null,
172+
env: string[] = [],
164173
) => {
165174
const docker = await getRemoteDocker(serverId);
166175

@@ -169,6 +178,7 @@ const rollbackApplication = async (
169178
TaskTemplate: {
170179
ContainerSpec: {
171180
Image: image,
181+
Env: env,
172182
},
173183
},
174184
};

0 commit comments

Comments
 (0)