mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-19 10:25:20 +00:00
Merge pull request #2142 from Dokploy/fix/rollbacks-dns-issue
fix(rollbacks): correct dns issue resolution
This commit is contained in:
@@ -6,6 +6,9 @@ import { z } from "zod";
|
|||||||
import { deployments } from "./deployment";
|
import { deployments } from "./deployment";
|
||||||
import type { Application } from "@dokploy/server/services/application";
|
import type { Application } from "@dokploy/server/services/application";
|
||||||
import type { Project } from "@dokploy/server/services/project";
|
import type { Project } from "@dokploy/server/services/project";
|
||||||
|
import type { Mount } from "@dokploy/server/services/mount";
|
||||||
|
import type { Port } from "@dokploy/server/services/port";
|
||||||
|
import type { Registry } from "@dokploy/server/services/registry";
|
||||||
|
|
||||||
export const rollbacks = pgTable("rollback", {
|
export const rollbacks = pgTable("rollback", {
|
||||||
rollbackId: text("rollbackId")
|
rollbackId: text("rollbackId")
|
||||||
@@ -22,7 +25,14 @@ export const rollbacks = pgTable("rollback", {
|
|||||||
createdAt: text("createdAt")
|
createdAt: text("createdAt")
|
||||||
.notNull()
|
.notNull()
|
||||||
.$defaultFn(() => new Date().toISOString()),
|
.$defaultFn(() => new Date().toISOString()),
|
||||||
fullContext: jsonb("fullContext").$type<Application & { project: Project }>(),
|
fullContext: jsonb("fullContext").$type<
|
||||||
|
Application & {
|
||||||
|
project: Project;
|
||||||
|
mounts: Mount[];
|
||||||
|
ports: Port[];
|
||||||
|
registry?: Registry | null;
|
||||||
|
}
|
||||||
|
>(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type Rollback = typeof rollbacks.$inferSelect;
|
export type Rollback = typeof rollbacks.$inferSelect;
|
||||||
|
|||||||
@@ -6,13 +6,22 @@ import {
|
|||||||
deployments as deploymentsSchema,
|
deployments as deploymentsSchema,
|
||||||
} from "../db/schema";
|
} from "../db/schema";
|
||||||
import type { z } from "zod";
|
import type { z } from "zod";
|
||||||
import { findApplicationById } from "./application";
|
import { type Application, findApplicationById } from "./application";
|
||||||
import { getRemoteDocker } from "../utils/servers/remote-docker";
|
import { getRemoteDocker } from "../utils/servers/remote-docker";
|
||||||
import type { ApplicationNested } from "../utils/builders";
|
import { getAuthConfig, type ApplicationNested } from "../utils/builders";
|
||||||
import { execAsync, execAsyncRemote } from "../utils/process/execAsync";
|
import { execAsync, execAsyncRemote } from "../utils/process/execAsync";
|
||||||
import type { CreateServiceOptions } from "dockerode";
|
import type { CreateServiceOptions } from "dockerode";
|
||||||
import { findDeploymentById } from "./deployment";
|
import { findDeploymentById } from "./deployment";
|
||||||
import { prepareEnvironmentVariables } from "../utils/docker/utils";
|
import {
|
||||||
|
prepareEnvironmentVariables,
|
||||||
|
calculateResources,
|
||||||
|
generateBindMounts,
|
||||||
|
generateConfigContainer,
|
||||||
|
generateVolumeMounts,
|
||||||
|
} from "../utils/docker/utils";
|
||||||
|
import type { Project } from "./project";
|
||||||
|
import type { Mount } from "./mount";
|
||||||
|
import type { Port } from "./port";
|
||||||
|
|
||||||
export const createRollback = async (
|
export const createRollback = async (
|
||||||
input: z.infer<typeof createRollbackSchema>,
|
input: z.infer<typeof createRollbackSchema>,
|
||||||
@@ -152,16 +161,16 @@ export const rollback = async (rollbackId: string) => {
|
|||||||
|
|
||||||
const application = await findApplicationById(deployment.applicationId);
|
const application = await findApplicationById(deployment.applicationId);
|
||||||
|
|
||||||
const envVariables = prepareEnvironmentVariables(
|
if (!result.fullContext) {
|
||||||
result?.fullContext?.env || "",
|
throw new Error("Rollback context not found");
|
||||||
result.fullContext?.project?.env || "",
|
}
|
||||||
);
|
|
||||||
|
|
||||||
|
// Use the full context for rollback
|
||||||
await rollbackApplication(
|
await rollbackApplication(
|
||||||
application.appName,
|
application.appName,
|
||||||
result.image || "",
|
result.image || "",
|
||||||
application.serverId,
|
application.serverId,
|
||||||
envVariables,
|
result.fullContext,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -169,18 +178,94 @@ const rollbackApplication = async (
|
|||||||
appName: string,
|
appName: string,
|
||||||
image: string,
|
image: string,
|
||||||
serverId?: string | null,
|
serverId?: string | null,
|
||||||
env: string[] = [],
|
fullContext?: Application & {
|
||||||
|
project: Project;
|
||||||
|
mounts: Mount[];
|
||||||
|
ports: Port[];
|
||||||
|
},
|
||||||
) => {
|
) => {
|
||||||
|
if (!fullContext) {
|
||||||
|
throw new Error("Full context is required for rollback");
|
||||||
|
}
|
||||||
|
|
||||||
const docker = await getRemoteDocker(serverId);
|
const docker = await getRemoteDocker(serverId);
|
||||||
|
|
||||||
|
// Use the same configuration as mechanizeDockerContainer
|
||||||
|
const {
|
||||||
|
env,
|
||||||
|
mounts,
|
||||||
|
cpuLimit,
|
||||||
|
memoryLimit,
|
||||||
|
memoryReservation,
|
||||||
|
cpuReservation,
|
||||||
|
command,
|
||||||
|
ports,
|
||||||
|
} = fullContext;
|
||||||
|
|
||||||
|
const resources = calculateResources({
|
||||||
|
memoryLimit,
|
||||||
|
memoryReservation,
|
||||||
|
cpuLimit,
|
||||||
|
cpuReservation,
|
||||||
|
});
|
||||||
|
|
||||||
|
const volumesMount = generateVolumeMounts(mounts);
|
||||||
|
|
||||||
|
const {
|
||||||
|
HealthCheck,
|
||||||
|
RestartPolicy,
|
||||||
|
Placement,
|
||||||
|
Labels,
|
||||||
|
Mode,
|
||||||
|
RollbackConfig,
|
||||||
|
UpdateConfig,
|
||||||
|
Networks,
|
||||||
|
} = generateConfigContainer(fullContext as ApplicationNested);
|
||||||
|
|
||||||
|
const bindsMount = generateBindMounts(mounts);
|
||||||
|
const envVariables = prepareEnvironmentVariables(
|
||||||
|
env,
|
||||||
|
fullContext.project.env,
|
||||||
|
);
|
||||||
|
|
||||||
|
// For rollback, we use the provided image instead of calculating it
|
||||||
|
const authConfig = getAuthConfig(fullContext as ApplicationNested);
|
||||||
|
|
||||||
const settings: CreateServiceOptions = {
|
const settings: CreateServiceOptions = {
|
||||||
|
authconfig: authConfig,
|
||||||
Name: appName,
|
Name: appName,
|
||||||
TaskTemplate: {
|
TaskTemplate: {
|
||||||
ContainerSpec: {
|
ContainerSpec: {
|
||||||
|
HealthCheck,
|
||||||
Image: image,
|
Image: image,
|
||||||
Env: env,
|
Env: envVariables,
|
||||||
|
Mounts: [...volumesMount, ...bindsMount],
|
||||||
|
...(command
|
||||||
|
? {
|
||||||
|
Command: ["/bin/sh"],
|
||||||
|
Args: ["-c", command],
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
|
Labels,
|
||||||
|
},
|
||||||
|
Networks,
|
||||||
|
RestartPolicy,
|
||||||
|
Placement,
|
||||||
|
Resources: {
|
||||||
|
...resources,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Mode,
|
||||||
|
RollbackConfig,
|
||||||
|
EndpointSpec: {
|
||||||
|
Ports: ports.map((port) => ({
|
||||||
|
PublishMode: port.publishMode,
|
||||||
|
Protocol: port.protocol,
|
||||||
|
TargetPort: port.targetPort,
|
||||||
|
PublishedPort: port.publishedPort,
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
UpdateConfig,
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -227,7 +227,7 @@ const getImageName = (application: ApplicationNested) => {
|
|||||||
return imageName;
|
return imageName;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getAuthConfig = (application: ApplicationNested) => {
|
export const getAuthConfig = (application: ApplicationNested) => {
|
||||||
const { registry, username, password, sourceType, registryUrl } = application;
|
const { registry, username, password, sourceType, registryUrl } = application;
|
||||||
|
|
||||||
if (sourceType === "docker") {
|
if (sourceType === "docker") {
|
||||||
|
|||||||
Reference in New Issue
Block a user