fix: apply stop grace period within container spec

This commit is contained in:
Lucas Manchine
2025-11-20 16:15:52 -03:00
parent a5abd46386
commit 1c652477fb
7 changed files with 24 additions and 16 deletions
@@ -4,7 +4,11 @@ import type { ApplicationNested } from "@dokploy/server/utils/builders";
import { mechanizeDockerContainer } from "@dokploy/server/utils/builders"; import { mechanizeDockerContainer } from "@dokploy/server/utils/builders";
type MockCreateServiceOptions = { type MockCreateServiceOptions = {
StopGracePeriod?: number; TaskTemplate?: {
ContainerSpec?: {
StopGracePeriod?: number;
};
};
[key: string]: unknown; [key: string]: unknown;
}; };
@@ -82,8 +86,10 @@ describe("mechanizeDockerContainer", () => {
throw new Error("createServiceMock should have been called once"); throw new Error("createServiceMock should have been called once");
} }
const [settings] = call; const [settings] = call;
expect(settings.StopGracePeriod).toBe(0); expect(settings.TaskTemplate?.ContainerSpec?.StopGracePeriod).toBe(0);
expect(typeof settings.StopGracePeriod).toBe("number"); expect(typeof settings.TaskTemplate?.ContainerSpec?.StopGracePeriod).toBe(
"number",
);
}); });
it("omits StopGracePeriod when stopGracePeriodSwarm is null", async () => { it("omits StopGracePeriod when stopGracePeriodSwarm is null", async () => {
@@ -97,6 +103,8 @@ describe("mechanizeDockerContainer", () => {
throw new Error("createServiceMock should have been called once"); throw new Error("createServiceMock should have been called once");
} }
const [settings] = call; const [settings] = call;
expect(settings).not.toHaveProperty("StopGracePeriod"); expect(settings.TaskTemplate?.ContainerSpec).not.toHaveProperty(
"StopGracePeriod",
);
}); });
}); });
+2 -2
View File
@@ -125,6 +125,8 @@ export const mechanizeDockerContainer = async (
Image: image, Image: image,
Env: envVariables, Env: envVariables,
Mounts: [...volumesMount, ...bindsMount, ...filesMount], Mounts: [...volumesMount, ...bindsMount, ...filesMount],
...(StopGracePeriod !== undefined &&
StopGracePeriod !== null && { StopGracePeriod }),
...(command ...(command
? { ? {
Command: ["/bin/sh"], Command: ["/bin/sh"],
@@ -153,8 +155,6 @@ export const mechanizeDockerContainer = async (
})), })),
}, },
UpdateConfig, UpdateConfig,
...(StopGracePeriod !== undefined &&
StopGracePeriod !== null && { StopGracePeriod }),
}; };
try { try {
@@ -73,6 +73,8 @@ export const buildMariadb = async (mariadb: MariadbNested) => {
Image: dockerImage, Image: dockerImage,
Env: envVariables, Env: envVariables,
Mounts: [...volumesMount, ...bindsMount, ...filesMount], Mounts: [...volumesMount, ...bindsMount, ...filesMount],
...(StopGracePeriod !== undefined &&
StopGracePeriod !== null && { StopGracePeriod }),
...(command ...(command
? { ? {
Command: ["/bin/sh"], Command: ["/bin/sh"],
@@ -106,8 +108,6 @@ export const buildMariadb = async (mariadb: MariadbNested) => {
: [], : [],
}, },
UpdateConfig, UpdateConfig,
...(StopGracePeriod !== undefined &&
StopGracePeriod !== null && { StopGracePeriod }),
}; };
try { try {
const service = docker.getService(appName); const service = docker.getService(appName);
+2 -2
View File
@@ -121,6 +121,8 @@ ${command ?? "wait $MONGOD_PID"}`;
Image: dockerImage, Image: dockerImage,
Env: envVariables, Env: envVariables,
Mounts: [...volumesMount, ...bindsMount, ...filesMount], Mounts: [...volumesMount, ...bindsMount, ...filesMount],
...(StopGracePeriod !== undefined &&
StopGracePeriod !== null && { StopGracePeriod }),
...(replicaSets ...(replicaSets
? { ? {
Command: ["/bin/bash"], Command: ["/bin/bash"],
@@ -159,8 +161,6 @@ ${command ?? "wait $MONGOD_PID"}`;
: [], : [],
}, },
UpdateConfig, UpdateConfig,
...(StopGracePeriod !== undefined &&
StopGracePeriod !== null && { StopGracePeriod }),
}; };
try { try {
+2 -2
View File
@@ -79,6 +79,8 @@ export const buildMysql = async (mysql: MysqlNested) => {
Image: dockerImage, Image: dockerImage,
Env: envVariables, Env: envVariables,
Mounts: [...volumesMount, ...bindsMount, ...filesMount], Mounts: [...volumesMount, ...bindsMount, ...filesMount],
...(StopGracePeriod !== undefined &&
StopGracePeriod !== null && { StopGracePeriod }),
...(command ...(command
? { ? {
Command: ["/bin/sh"], Command: ["/bin/sh"],
@@ -112,8 +114,6 @@ export const buildMysql = async (mysql: MysqlNested) => {
: [], : [],
}, },
UpdateConfig, UpdateConfig,
...(StopGracePeriod !== undefined &&
StopGracePeriod !== null && { StopGracePeriod }),
}; };
try { try {
const service = docker.getService(appName); const service = docker.getService(appName);
@@ -72,6 +72,8 @@ export const buildPostgres = async (postgres: PostgresNested) => {
Image: dockerImage, Image: dockerImage,
Env: envVariables, Env: envVariables,
Mounts: [...volumesMount, ...bindsMount, ...filesMount], Mounts: [...volumesMount, ...bindsMount, ...filesMount],
...(StopGracePeriod !== undefined &&
StopGracePeriod !== null && { StopGracePeriod }),
...(command ...(command
? { ? {
Command: ["/bin/sh"], Command: ["/bin/sh"],
@@ -105,8 +107,6 @@ export const buildPostgres = async (postgres: PostgresNested) => {
: [], : [],
}, },
UpdateConfig, UpdateConfig,
...(StopGracePeriod !== undefined &&
StopGracePeriod !== null && { StopGracePeriod }),
}; };
try { try {
const service = docker.getService(appName); const service = docker.getService(appName);
+2 -2
View File
@@ -70,6 +70,8 @@ export const buildRedis = async (redis: RedisNested) => {
Image: dockerImage, Image: dockerImage,
Env: envVariables, Env: envVariables,
Mounts: [...volumesMount, ...bindsMount, ...filesMount], Mounts: [...volumesMount, ...bindsMount, ...filesMount],
...(StopGracePeriod !== undefined &&
StopGracePeriod !== null && { StopGracePeriod }),
Command: ["/bin/sh"], Command: ["/bin/sh"],
Args: [ Args: [
"-c", "-c",
@@ -102,8 +104,6 @@ export const buildRedis = async (redis: RedisNested) => {
: [], : [],
}, },
UpdateConfig, UpdateConfig,
...(StopGracePeriod !== undefined &&
StopGracePeriod !== null && { StopGracePeriod }),
}; };
try { try {