mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-16 17:05:17 +00:00
refactor(traefik): improve config removal logic and error handling
- Consolidated command execution for removing Traefik config files by using a single command string. - Enhanced error handling to log issues encountered during the removal process for both local and remote configurations.
This commit is contained in:
@@ -5,7 +5,7 @@ import { paths } from "@dokploy/server/constants";
|
|||||||
import type { Domain } from "@dokploy/server/services/domain";
|
import type { Domain } from "@dokploy/server/services/domain";
|
||||||
import { parse, stringify } from "yaml";
|
import { parse, stringify } from "yaml";
|
||||||
import { encodeBase64 } from "../docker/utils";
|
import { encodeBase64 } from "../docker/utils";
|
||||||
import { execAsyncRemote } from "../process/execAsync";
|
import { execAsync, execAsyncRemote } from "../process/execAsync";
|
||||||
import type { FileConfig, HttpLoadBalancerService } from "./file-types";
|
import type { FileConfig, HttpLoadBalancerService } from "./file-types";
|
||||||
|
|
||||||
export const createTraefikConfig = (appName: string) => {
|
export const createTraefikConfig = (appName: string) => {
|
||||||
@@ -57,18 +57,16 @@ export const removeTraefikConfig = async (
|
|||||||
try {
|
try {
|
||||||
const { DYNAMIC_TRAEFIK_PATH } = paths(!!serverId);
|
const { DYNAMIC_TRAEFIK_PATH } = paths(!!serverId);
|
||||||
const configPath = path.join(DYNAMIC_TRAEFIK_PATH, `${appName}.yml`);
|
const configPath = path.join(DYNAMIC_TRAEFIK_PATH, `${appName}.yml`);
|
||||||
|
const command = `rm -f ${configPath}`;
|
||||||
|
|
||||||
if (serverId) {
|
if (serverId) {
|
||||||
await execAsyncRemote(serverId, `rm ${configPath}`);
|
await execAsyncRemote(serverId, command);
|
||||||
} else {
|
} else {
|
||||||
if (fs.existsSync(configPath)) {
|
await execAsync(command);
|
||||||
await fs.promises.unlink(configPath);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (fs.existsSync(configPath)) {
|
} catch (error) {
|
||||||
await fs.promises.unlink(configPath);
|
console.error(`Error removing traefik config for ${appName}:`, error);
|
||||||
}
|
}
|
||||||
} catch {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const removeTraefikConfigRemote = async (
|
export const removeTraefikConfigRemote = async (
|
||||||
@@ -78,8 +76,13 @@ export const removeTraefikConfigRemote = async (
|
|||||||
try {
|
try {
|
||||||
const { DYNAMIC_TRAEFIK_PATH } = paths(true);
|
const { DYNAMIC_TRAEFIK_PATH } = paths(true);
|
||||||
const configPath = path.join(DYNAMIC_TRAEFIK_PATH, `${appName}.yml`);
|
const configPath = path.join(DYNAMIC_TRAEFIK_PATH, `${appName}.yml`);
|
||||||
await execAsyncRemote(serverId, `rm ${configPath}`);
|
await execAsyncRemote(serverId, `rm -f ${configPath}`);
|
||||||
} catch {}
|
} catch (error) {
|
||||||
|
console.error(
|
||||||
|
`Error removing remote traefik config for ${appName}:`,
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const loadOrCreateConfig = (appName: string): FileConfig => {
|
export const loadOrCreateConfig = (appName: string): FileConfig => {
|
||||||
|
|||||||
Reference in New Issue
Block a user