Skip to content

Commit de4a00f

Browse files
authored
Merge pull request #2556 from Dokploy/2552-traefik-container-no-auto-start
feat(settings): add error handling for unsupported resource types in …
2 parents 1763000 + 2f5cd62 commit de4a00f

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

packages/server/src/services/settings.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ export const readPorts = async (
342342
command = `docker service inspect ${resourceName} --format '{{json .Spec.EndpointSpec.Ports}}'`;
343343
} else if (resourceType === "standalone") {
344344
command = `docker container inspect ${resourceName} --format '{{json .NetworkSettings.Ports}}'`;
345+
} else {
346+
throw new Error("Resource type not found");
345347
}
346348
let result = "";
347349
if (serverId) {
@@ -397,17 +399,20 @@ export const writeTraefikSetup = async (input: TraefikOptions) => {
397399
"dokploy-traefik",
398400
input.serverId,
399401
);
402+
400403
if (resourceType === "service") {
401404
await initializeTraefikService({
402405
env: input.env,
403406
additionalPorts: input.additionalPorts,
404407
serverId: input.serverId,
405408
});
406-
} else {
409+
} else if (resourceType === "standalone") {
407410
await initializeStandaloneTraefik({
408411
env: input.env,
409412
additionalPorts: input.additionalPorts,
410413
serverId: input.serverId,
411414
});
415+
} else {
416+
throw new Error("Traefik resource type not found");
412417
}
413418
};

packages/server/src/setup/traefik-setup.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,27 @@ export const initializeStandaloneTraefik = async ({
8787
};
8888

8989
const docker = await getRemoteDocker(serverId);
90+
try {
91+
await docker.pull(imageName);
92+
await new Promise((resolve) => setTimeout(resolve, 3000));
93+
console.log("Traefik Image Pulled ✅");
94+
} catch (error) {
95+
console.log("Traefik Image Not Found: Pulling ", error);
96+
}
9097
try {
9198
const container = docker.getContainer(containerName);
9299
await container.remove({ force: true });
93100
await new Promise((resolve) => setTimeout(resolve, 5000));
94101
} catch {}
95102

96-
await docker.createContainer(settings);
97-
const newContainer = docker.getContainer(containerName);
98-
await newContainer.start();
99-
console.log("Traefik Started ✅");
103+
try {
104+
await docker.createContainer(settings);
105+
const newContainer = docker.getContainer(containerName);
106+
await newContainer.start();
107+
console.log("Traefik Started ✅");
108+
} catch (error) {
109+
console.log("Traefik Not Found: Starting ", error);
110+
}
100111
};
101112

102113
export const initializeTraefikService = async ({

0 commit comments

Comments
 (0)