Skip to content

Commit b23ba17

Browse files
authored
Merge pull request #3073 from perinm/fix/stop-grace-period-swarm
fix: apply stop grace period within container spec
2 parents f94d5b9 + 218c077 commit b23ba17

File tree

7 files changed

+18
-16
lines changed

7 files changed

+18
-16
lines changed

apps/dokploy/__test__/server/mechanizeDockerContainer.test.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import type { ApplicationNested } from "@dokploy/server/utils/builders";
44
import { mechanizeDockerContainer } from "@dokploy/server/utils/builders";
55

66
type MockCreateServiceOptions = {
7-
StopGracePeriod?: number;
7+
TaskTemplate?: {
8+
ContainerSpec?: {
9+
StopGracePeriod?: number;
10+
};
11+
};
812
[key: string]: unknown;
913
};
1014

@@ -82,8 +86,10 @@ describe("mechanizeDockerContainer", () => {
8286
throw new Error("createServiceMock should have been called once");
8387
}
8488
const [settings] = call;
85-
expect(settings.StopGracePeriod).toBe(0);
86-
expect(typeof settings.StopGracePeriod).toBe("number");
89+
expect(settings.TaskTemplate?.ContainerSpec?.StopGracePeriod).toBe(0);
90+
expect(typeof settings.TaskTemplate?.ContainerSpec?.StopGracePeriod).toBe(
91+
"number",
92+
);
8793
});
8894

8995
it("omits StopGracePeriod when stopGracePeriodSwarm is null", async () => {
@@ -97,6 +103,8 @@ describe("mechanizeDockerContainer", () => {
97103
throw new Error("createServiceMock should have been called once");
98104
}
99105
const [settings] = call;
100-
expect(settings).not.toHaveProperty("StopGracePeriod");
106+
expect(settings.TaskTemplate?.ContainerSpec).not.toHaveProperty(
107+
"StopGracePeriod",
108+
);
101109
});
102110
});

packages/server/src/utils/builders/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export const mechanizeDockerContainer = async (
125125
Image: image,
126126
Env: envVariables,
127127
Mounts: [...volumesMount, ...bindsMount, ...filesMount],
128+
...(StopGracePeriod && { StopGracePeriod }),
128129
...(command
129130
? {
130131
Command: ["/bin/sh"],
@@ -153,8 +154,6 @@ export const mechanizeDockerContainer = async (
153154
})),
154155
},
155156
UpdateConfig,
156-
...(StopGracePeriod !== undefined &&
157-
StopGracePeriod !== null && { StopGracePeriod }),
158157
};
159158

160159
try {

packages/server/src/utils/databases/mariadb.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export const buildMariadb = async (mariadb: MariadbNested) => {
7373
Image: dockerImage,
7474
Env: envVariables,
7575
Mounts: [...volumesMount, ...bindsMount, ...filesMount],
76+
...(StopGracePeriod && { StopGracePeriod }),
7677
...(command
7778
? {
7879
Command: ["/bin/sh"],
@@ -106,8 +107,6 @@ export const buildMariadb = async (mariadb: MariadbNested) => {
106107
: [],
107108
},
108109
UpdateConfig,
109-
...(StopGracePeriod !== undefined &&
110-
StopGracePeriod !== null && { StopGracePeriod }),
111110
};
112111
try {
113112
const service = docker.getService(appName);

packages/server/src/utils/databases/mongo.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ ${command ?? "wait $MONGOD_PID"}`;
121121
Image: dockerImage,
122122
Env: envVariables,
123123
Mounts: [...volumesMount, ...bindsMount, ...filesMount],
124+
...(StopGracePeriod && { StopGracePeriod }),
124125
...(replicaSets
125126
? {
126127
Command: ["/bin/bash"],
@@ -159,8 +160,6 @@ ${command ?? "wait $MONGOD_PID"}`;
159160
: [],
160161
},
161162
UpdateConfig,
162-
...(StopGracePeriod !== undefined &&
163-
StopGracePeriod !== null && { StopGracePeriod }),
164163
};
165164

166165
try {

packages/server/src/utils/databases/mysql.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export const buildMysql = async (mysql: MysqlNested) => {
7979
Image: dockerImage,
8080
Env: envVariables,
8181
Mounts: [...volumesMount, ...bindsMount, ...filesMount],
82+
...(StopGracePeriod && { StopGracePeriod }),
8283
...(command
8384
? {
8485
Command: ["/bin/sh"],
@@ -112,8 +113,6 @@ export const buildMysql = async (mysql: MysqlNested) => {
112113
: [],
113114
},
114115
UpdateConfig,
115-
...(StopGracePeriod !== undefined &&
116-
StopGracePeriod !== null && { StopGracePeriod }),
117116
};
118117
try {
119118
const service = docker.getService(appName);

packages/server/src/utils/databases/postgres.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export const buildPostgres = async (postgres: PostgresNested) => {
7272
Image: dockerImage,
7373
Env: envVariables,
7474
Mounts: [...volumesMount, ...bindsMount, ...filesMount],
75+
...(StopGracePeriod && { StopGracePeriod }),
7576
...(command
7677
? {
7778
Command: ["/bin/sh"],
@@ -105,8 +106,6 @@ export const buildPostgres = async (postgres: PostgresNested) => {
105106
: [],
106107
},
107108
UpdateConfig,
108-
...(StopGracePeriod !== undefined &&
109-
StopGracePeriod !== null && { StopGracePeriod }),
110109
};
111110
try {
112111
const service = docker.getService(appName);

packages/server/src/utils/databases/redis.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export const buildRedis = async (redis: RedisNested) => {
7070
Image: dockerImage,
7171
Env: envVariables,
7272
Mounts: [...volumesMount, ...bindsMount, ...filesMount],
73+
...(StopGracePeriod && { StopGracePeriod }),
7374
Command: ["/bin/sh"],
7475
Args: [
7576
"-c",
@@ -102,8 +103,6 @@ export const buildRedis = async (redis: RedisNested) => {
102103
: [],
103104
},
104105
UpdateConfig,
105-
...(StopGracePeriod !== undefined &&
106-
StopGracePeriod !== null && { StopGracePeriod }),
107106
};
108107

109108
try {

0 commit comments

Comments
 (0)