mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor(traefik): streamline container removal and service management
- Remove dokploy-service before Traefik container initialization - Simplify error handling and logging during container setup - Add support for remote server service removal
This commit is contained in:
@@ -7,6 +7,7 @@ import { pullImage, pullRemoteImage } from "../utils/docker/utils";
|
|||||||
import { getRemoteDocker } from "../utils/servers/remote-docker";
|
import { getRemoteDocker } from "../utils/servers/remote-docker";
|
||||||
import type { FileConfig } from "../utils/traefik/file-types";
|
import type { FileConfig } from "../utils/traefik/file-types";
|
||||||
import type { MainTraefikConfig } from "../utils/traefik/types";
|
import type { MainTraefikConfig } from "../utils/traefik/types";
|
||||||
|
import { execAsync, execAsyncRemote } from "../utils/process/execAsync";
|
||||||
|
|
||||||
export const TRAEFIK_SSL_PORT =
|
export const TRAEFIK_SSL_PORT =
|
||||||
Number.parseInt(process.env.TRAEFIK_SSL_PORT!, 10) || 443;
|
Number.parseInt(process.env.TRAEFIK_SSL_PORT!, 10) || 443;
|
||||||
@@ -95,6 +96,14 @@ export const initializeTraefik = async ({
|
|||||||
await pullImage(imageName);
|
await pullImage(imageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove dokploy-service if it exists
|
||||||
|
const command = "docker service rm dokploy-service > /dev/null 2>&1";
|
||||||
|
if (serverId) {
|
||||||
|
await execAsyncRemote(command, serverId);
|
||||||
|
} else {
|
||||||
|
await execAsync(command);
|
||||||
|
}
|
||||||
|
|
||||||
const container = docker.getContainer(containerName);
|
const container = docker.getContainer(containerName);
|
||||||
try {
|
try {
|
||||||
const inspect = await container.inspect();
|
const inspect = await container.inspect();
|
||||||
@@ -104,19 +113,14 @@ export const initializeTraefik = async ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
await container.remove({ force: true });
|
await container.remove({ force: true });
|
||||||
console.log("Removed existing container");
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("Traefik Not Found: Starting1 ✅");
|
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
await docker.createContainer(settings);
|
await docker.createContainer(settings);
|
||||||
const newContainer = docker.getContainer(containerName);
|
const newContainer = docker.getContainer(containerName);
|
||||||
await newContainer.start();
|
await newContainer.start();
|
||||||
|
|
||||||
console.log("Traefik Started ✅");
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("Traefik Not Found: Starting2 ✅", error);
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user