mirror of
https://github.com/LukeHagar/dokploy.git
synced 2025-12-09 20:37:45 +00:00
refactor: replace js-yaml with yaml package for YAML parsing and stringifying across the application
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import jsyaml from "js-yaml";
|
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
import { parse, stringify, YAMLParseError } from "yaml";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { AlertBlock } from "@/components/shared/alert-block";
|
import { AlertBlock } from "@/components/shared/alert-block";
|
||||||
import { CodeEditor } from "@/components/shared/code-editor";
|
import { CodeEditor } from "@/components/shared/code-editor";
|
||||||
@@ -38,11 +38,11 @@ interface Props {
|
|||||||
|
|
||||||
export const validateAndFormatYAML = (yamlText: string) => {
|
export const validateAndFormatYAML = (yamlText: string) => {
|
||||||
try {
|
try {
|
||||||
const obj = jsyaml.load(yamlText);
|
const obj = parse(yamlText);
|
||||||
const formattedYaml = jsyaml.dump(obj, { indent: 4 });
|
const formattedYaml = stringify(obj, { indent: 4 });
|
||||||
return { valid: true, formattedYaml, error: null };
|
return { valid: true, formattedYaml, error: null };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof jsyaml.YAMLException) {
|
if (error instanceof YAMLParseError) {
|
||||||
return {
|
return {
|
||||||
valid: false,
|
valid: false,
|
||||||
formattedYaml: yamlText,
|
formattedYaml: yamlText,
|
||||||
@@ -89,7 +89,7 @@ export const UpdateTraefikConfig = ({ applicationId }: Props) => {
|
|||||||
if (!valid) {
|
if (!valid) {
|
||||||
form.setError("traefikConfig", {
|
form.setError("traefikConfig", {
|
||||||
type: "manual",
|
type: "manual",
|
||||||
message: error || "Invalid YAML",
|
message: (error as string) || "Invalid YAML",
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,7 +112,7 @@
|
|||||||
"i18next": "^23.16.8",
|
"i18next": "^23.16.8",
|
||||||
"input-otp": "^1.4.2",
|
"input-otp": "^1.4.2",
|
||||||
"js-cookie": "^3.0.5",
|
"js-cookie": "^3.0.5",
|
||||||
"js-yaml": "4.1.0",
|
"yaml": "2.8.1",
|
||||||
"lodash": "4.17.21",
|
"lodash": "4.17.21",
|
||||||
"lucide-react": "^0.469.0",
|
"lucide-react": "^0.469.0",
|
||||||
"micromatch": "4.0.8",
|
"micromatch": "4.0.8",
|
||||||
@@ -160,7 +160,6 @@
|
|||||||
"@types/adm-zip": "^0.5.7",
|
"@types/adm-zip": "^0.5.7",
|
||||||
"@types/bcrypt": "5.0.2",
|
"@types/bcrypt": "5.0.2",
|
||||||
"@types/js-cookie": "^3.0.6",
|
"@types/js-cookie": "^3.0.6",
|
||||||
"@types/js-yaml": "4.0.9",
|
|
||||||
"@types/lodash": "4.17.4",
|
"@types/lodash": "4.17.4",
|
||||||
"@types/micromatch": "4.0.9",
|
"@types/micromatch": "4.0.9",
|
||||||
"@types/node": "^18.19.104",
|
"@types/node": "^18.19.104",
|
||||||
|
|||||||
@@ -39,10 +39,10 @@ import {
|
|||||||
import { processTemplate } from "@dokploy/server/templates/processors";
|
import { processTemplate } from "@dokploy/server/templates/processors";
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
import { dump } from "js-yaml";
|
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
import { parse } from "toml";
|
import { parse } from "toml";
|
||||||
|
import { stringify } from "yaml";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { slugify } from "@/lib/slug";
|
import { slugify } from "@/lib/slug";
|
||||||
import { db } from "@/server/db";
|
import { db } from "@/server/db";
|
||||||
@@ -364,7 +364,7 @@ export const composeRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
const domains = await findDomainsByComposeId(input.composeId);
|
const domains = await findDomainsByComposeId(input.composeId);
|
||||||
const composeFile = await addDomainToCompose(compose, domains);
|
const composeFile = await addDomainToCompose(compose, domains);
|
||||||
return dump(composeFile, {
|
return stringify(composeFile, {
|
||||||
lineWidth: 1000,
|
lineWidth: 1000,
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -46,8 +46,8 @@ import {
|
|||||||
import { generateOpenApiDocument } from "@dokploy/trpc-openapi";
|
import { generateOpenApiDocument } from "@dokploy/trpc-openapi";
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
import { eq, sql } from "drizzle-orm";
|
import { eq, sql } from "drizzle-orm";
|
||||||
import { dump, load } from "js-yaml";
|
|
||||||
import { scheduledJobs, scheduleJob } from "node-schedule";
|
import { scheduledJobs, scheduleJob } from "node-schedule";
|
||||||
|
import { parse, stringify } from "yaml";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { db } from "@/server/db";
|
import { db } from "@/server/db";
|
||||||
import {
|
import {
|
||||||
@@ -657,7 +657,7 @@ export const settingsRouter = createTRPCRouter({
|
|||||||
const config = readMainConfig();
|
const config = readMainConfig();
|
||||||
|
|
||||||
if (!config) return false;
|
if (!config) return false;
|
||||||
const parsedConfig = load(config) as {
|
const parsedConfig = parse(config) as {
|
||||||
accessLog?: {
|
accessLog?: {
|
||||||
filePath: string;
|
filePath: string;
|
||||||
};
|
};
|
||||||
@@ -678,7 +678,7 @@ export const settingsRouter = createTRPCRouter({
|
|||||||
const mainConfig = readMainConfig();
|
const mainConfig = readMainConfig();
|
||||||
if (!mainConfig) return false;
|
if (!mainConfig) return false;
|
||||||
|
|
||||||
const currentConfig = load(mainConfig) as {
|
const currentConfig = parse(mainConfig) as {
|
||||||
accessLog?: {
|
accessLog?: {
|
||||||
filePath: string;
|
filePath: string;
|
||||||
};
|
};
|
||||||
@@ -701,7 +701,7 @@ export const settingsRouter = createTRPCRouter({
|
|||||||
currentConfig.accessLog = undefined;
|
currentConfig.accessLog = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
writeMainConfig(dump(currentConfig));
|
writeMainConfig(stringify(currentConfig));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -57,7 +57,7 @@
|
|||||||
"drizzle-orm": "^0.39.3",
|
"drizzle-orm": "^0.39.3",
|
||||||
"drizzle-zod": "0.5.1",
|
"drizzle-zod": "0.5.1",
|
||||||
"hi-base32": "^0.5.1",
|
"hi-base32": "^0.5.1",
|
||||||
"js-yaml": "4.1.0",
|
"yaml": "2.8.1",
|
||||||
"lodash": "4.17.21",
|
"lodash": "4.17.21",
|
||||||
"micromatch": "4.0.8",
|
"micromatch": "4.0.8",
|
||||||
"nanoid": "3.3.11",
|
"nanoid": "3.3.11",
|
||||||
@@ -85,7 +85,6 @@
|
|||||||
"@types/adm-zip": "^0.5.7",
|
"@types/adm-zip": "^0.5.7",
|
||||||
"@types/bcrypt": "5.0.2",
|
"@types/bcrypt": "5.0.2",
|
||||||
"@types/dockerode": "3.3.23",
|
"@types/dockerode": "3.3.23",
|
||||||
"@types/js-yaml": "4.0.9",
|
|
||||||
"@types/lodash": "4.17.4",
|
"@types/lodash": "4.17.4",
|
||||||
"@types/micromatch": "4.0.9",
|
"@types/micromatch": "4.0.9",
|
||||||
"@types/node": "^18.19.104",
|
"@types/node": "^18.19.104",
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
import { removeDirectoryIfExistsContent } from "@dokploy/server/utils/filesystem/directory";
|
import { removeDirectoryIfExistsContent } from "@dokploy/server/utils/filesystem/directory";
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
import { dump } from "js-yaml";
|
import { stringify } from "yaml";
|
||||||
import type { z } from "zod";
|
import type { z } from "zod";
|
||||||
import { encodeBase64 } from "../utils/docker/utils";
|
import { encodeBase64 } from "../utils/docker/utils";
|
||||||
import { execAsyncRemote } from "../utils/process/execAsync";
|
import { execAsyncRemote } from "../utils/process/execAsync";
|
||||||
@@ -101,7 +101,7 @@ const createCertificateFiles = async (certificate: Certificate) => {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const yamlConfig = dump(traefikConfig);
|
const yamlConfig = stringify(traefikConfig);
|
||||||
const configFile = path.join(certDir, "certificate.yml");
|
const configFile = path.join(certDir, "certificate.yml");
|
||||||
|
|
||||||
if (certificate.serverId) {
|
if (certificate.serverId) {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
} from "node:fs";
|
} from "node:fs";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import type { ContainerCreateOptions, CreateServiceOptions } from "dockerode";
|
import type { ContainerCreateOptions, CreateServiceOptions } from "dockerode";
|
||||||
import { dump } from "js-yaml";
|
import { stringify } from "yaml";
|
||||||
import { paths } from "../constants";
|
import { paths } from "../constants";
|
||||||
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";
|
||||||
@@ -241,7 +241,7 @@ export const createDefaultServerTraefikConfig = () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const yamlStr = dump(config);
|
const yamlStr = stringify(config);
|
||||||
mkdirSync(DYNAMIC_TRAEFIK_PATH, { recursive: true });
|
mkdirSync(DYNAMIC_TRAEFIK_PATH, { recursive: true });
|
||||||
writeFileSync(
|
writeFileSync(
|
||||||
path.join(DYNAMIC_TRAEFIK_PATH, `${appName}.yml`),
|
path.join(DYNAMIC_TRAEFIK_PATH, `${appName}.yml`),
|
||||||
@@ -315,7 +315,7 @@ export const getDefaultTraefikConfig = () => {
|
|||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
const yamlStr = dump(configObject);
|
const yamlStr = stringify(configObject);
|
||||||
|
|
||||||
return yamlStr;
|
return yamlStr;
|
||||||
};
|
};
|
||||||
@@ -369,7 +369,7 @@ export const getDefaultServerTraefikConfig = () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const yamlStr = dump(configObject);
|
const yamlStr = stringify(configObject);
|
||||||
|
|
||||||
return yamlStr;
|
return yamlStr;
|
||||||
};
|
};
|
||||||
@@ -417,7 +417,7 @@ export const getDefaultMiddlewares = () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const yamlStr = dump(defaultMiddlewares);
|
const yamlStr = stringify(defaultMiddlewares);
|
||||||
return yamlStr;
|
return yamlStr;
|
||||||
};
|
};
|
||||||
export const createDefaultMiddlewares = () => {
|
export const createDefaultMiddlewares = () => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { findComposeById } from "@dokploy/server/services/compose";
|
import { findComposeById } from "@dokploy/server/services/compose";
|
||||||
import { dump } from "js-yaml";
|
import { stringify } from "yaml";
|
||||||
import { addAppNameToAllServiceNames } from "./collision/root-network";
|
import { addAppNameToAllServiceNames } from "./collision/root-network";
|
||||||
import { generateRandomHash } from "./compose";
|
import { generateRandomHash } from "./compose";
|
||||||
import { addSuffixToAllVolumes } from "./compose/volume";
|
import { addSuffixToAllVolumes } from "./compose/volume";
|
||||||
@@ -59,7 +59,7 @@ export const randomizeIsolatedDeploymentComposeFile = async (
|
|||||||
)
|
)
|
||||||
: composeData;
|
: composeData;
|
||||||
|
|
||||||
return dump(newComposeFile);
|
return stringify(newComposeFile);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const randomizeDeployableSpecificationFile = (
|
export const randomizeDeployableSpecificationFile = (
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import crypto from "node:crypto";
|
import crypto from "node:crypto";
|
||||||
import { findComposeById } from "@dokploy/server/services/compose";
|
import { findComposeById } from "@dokploy/server/services/compose";
|
||||||
import { dump, load } from "js-yaml";
|
import { parse, stringify } from "yaml";
|
||||||
import { addSuffixToAllConfigs } from "./compose/configs";
|
import { addSuffixToAllConfigs } from "./compose/configs";
|
||||||
import { addSuffixToAllNetworks } from "./compose/network";
|
import { addSuffixToAllNetworks } from "./compose/network";
|
||||||
import { addSuffixToAllSecrets } from "./compose/secrets";
|
import { addSuffixToAllSecrets } from "./compose/secrets";
|
||||||
@@ -18,13 +18,13 @@ export const randomizeComposeFile = async (
|
|||||||
) => {
|
) => {
|
||||||
const compose = await findComposeById(composeId);
|
const compose = await findComposeById(composeId);
|
||||||
const composeFile = compose.composeFile;
|
const composeFile = compose.composeFile;
|
||||||
const composeData = load(composeFile) as ComposeSpecification;
|
const composeData = parse(composeFile) as ComposeSpecification;
|
||||||
|
|
||||||
const randomSuffix = suffix || generateRandomHash();
|
const randomSuffix = suffix || generateRandomHash();
|
||||||
|
|
||||||
const newComposeFile = addSuffixToAllProperties(composeData, randomSuffix);
|
const newComposeFile = addSuffixToAllProperties(composeData, randomSuffix);
|
||||||
|
|
||||||
return dump(newComposeFile);
|
return stringify(newComposeFile);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const randomizeSpecificationFile = (
|
export const randomizeSpecificationFile = (
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { join } from "node:path";
|
|||||||
import { paths } from "@dokploy/server/constants";
|
import { paths } from "@dokploy/server/constants";
|
||||||
import type { Compose } from "@dokploy/server/services/compose";
|
import type { Compose } from "@dokploy/server/services/compose";
|
||||||
import type { Domain } from "@dokploy/server/services/domain";
|
import type { Domain } from "@dokploy/server/services/domain";
|
||||||
import { dump, load } from "js-yaml";
|
import { parse, stringify } from "yaml";
|
||||||
import { execAsyncRemote } from "../process/execAsync";
|
import { execAsyncRemote } from "../process/execAsync";
|
||||||
import {
|
import {
|
||||||
cloneRawBitbucketRepository,
|
cloneRawBitbucketRepository,
|
||||||
@@ -92,7 +92,7 @@ export const loadDockerCompose = async (
|
|||||||
|
|
||||||
if (existsSync(path)) {
|
if (existsSync(path)) {
|
||||||
const yamlStr = readFileSync(path, "utf8");
|
const yamlStr = readFileSync(path, "utf8");
|
||||||
const parsedConfig = load(yamlStr) as ComposeSpecification;
|
const parsedConfig = parse(yamlStr) as ComposeSpecification;
|
||||||
return parsedConfig;
|
return parsedConfig;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -115,7 +115,7 @@ export const loadDockerComposeRemote = async (
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (!stdout) return null;
|
if (!stdout) return null;
|
||||||
const parsedConfig = load(stdout) as ComposeSpecification;
|
const parsedConfig = parse(stdout) as ComposeSpecification;
|
||||||
return parsedConfig;
|
return parsedConfig;
|
||||||
} catch {
|
} catch {
|
||||||
return null;
|
return null;
|
||||||
@@ -141,7 +141,7 @@ export const writeDomainsToCompose = async (
|
|||||||
const composeConverted = await addDomainToCompose(compose, domains);
|
const composeConverted = await addDomainToCompose(compose, domains);
|
||||||
|
|
||||||
const path = getComposePath(compose);
|
const path = getComposePath(compose);
|
||||||
const composeString = dump(composeConverted, { lineWidth: 1000 });
|
const composeString = stringify(composeConverted, { lineWidth: 1000 });
|
||||||
try {
|
try {
|
||||||
await writeFile(path, composeString, "utf8");
|
await writeFile(path, composeString, "utf8");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -169,7 +169,7 @@ exit 1;
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
if (compose.serverId) {
|
if (compose.serverId) {
|
||||||
const composeString = dump(composeConverted, { lineWidth: 1000 });
|
const composeString = stringify(composeConverted, { lineWidth: 1000 });
|
||||||
const encodedContent = encodeBase64(composeString);
|
const encodedContent = encodeBase64(composeString);
|
||||||
return `echo "${encodedContent}" | base64 -d > "${path}";`;
|
return `echo "${encodedContent}" | base64 -d > "${path}";`;
|
||||||
}
|
}
|
||||||
@@ -287,7 +287,7 @@ export const writeComposeFile = async (
|
|||||||
const path = getComposePath(compose);
|
const path = getComposePath(compose);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const composeFile = dump(composeSpec, {
|
const composeFile = stringify(composeSpec, {
|
||||||
lineWidth: 1000,
|
lineWidth: 1000,
|
||||||
});
|
});
|
||||||
fs.writeFileSync(path, composeFile, "utf8");
|
fs.writeFileSync(path, composeFile, "utf8");
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import path from "node:path";
|
|||||||
import { createInterface } from "node:readline";
|
import { createInterface } from "node:readline";
|
||||||
import { paths } from "@dokploy/server/constants";
|
import { paths } from "@dokploy/server/constants";
|
||||||
import type { Domain } from "@dokploy/server/services/domain";
|
import type { Domain } from "@dokploy/server/services/domain";
|
||||||
import { dump, load } from "js-yaml";
|
import { parse, stringify } from "yaml";
|
||||||
import { encodeBase64 } from "../docker/utils";
|
import { encodeBase64 } from "../docker/utils";
|
||||||
import { execAsyncRemote } from "../process/execAsync";
|
import { execAsyncRemote } from "../process/execAsync";
|
||||||
import type { FileConfig, HttpLoadBalancerService } from "./file-types";
|
import type { FileConfig, HttpLoadBalancerService } from "./file-types";
|
||||||
@@ -40,7 +40,7 @@ export const createTraefikConfig = (appName: string) => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const yamlStr = dump(config);
|
const yamlStr = stringify(config);
|
||||||
const { DYNAMIC_TRAEFIK_PATH } = paths();
|
const { DYNAMIC_TRAEFIK_PATH } = paths();
|
||||||
fs.mkdirSync(DYNAMIC_TRAEFIK_PATH, { recursive: true });
|
fs.mkdirSync(DYNAMIC_TRAEFIK_PATH, { recursive: true });
|
||||||
writeFileSync(
|
writeFileSync(
|
||||||
@@ -87,7 +87,7 @@ export const loadOrCreateConfig = (appName: string): FileConfig => {
|
|||||||
const configPath = path.join(DYNAMIC_TRAEFIK_PATH, `${appName}.yml`);
|
const configPath = path.join(DYNAMIC_TRAEFIK_PATH, `${appName}.yml`);
|
||||||
if (fs.existsSync(configPath)) {
|
if (fs.existsSync(configPath)) {
|
||||||
const yamlStr = fs.readFileSync(configPath, "utf8");
|
const yamlStr = fs.readFileSync(configPath, "utf8");
|
||||||
const parsedConfig = (load(yamlStr) as FileConfig) || {
|
const parsedConfig = (parse(yamlStr) as FileConfig) || {
|
||||||
http: { routers: {}, services: {} },
|
http: { routers: {}, services: {} },
|
||||||
};
|
};
|
||||||
return parsedConfig;
|
return parsedConfig;
|
||||||
@@ -107,7 +107,7 @@ export const loadOrCreateConfigRemote = async (
|
|||||||
|
|
||||||
if (!stdout) return fileConfig;
|
if (!stdout) return fileConfig;
|
||||||
|
|
||||||
const parsedConfig = (load(stdout) as FileConfig) || {
|
const parsedConfig = (parse(stdout) as FileConfig) || {
|
||||||
http: { routers: {}, services: {} },
|
http: { routers: {}, services: {} },
|
||||||
};
|
};
|
||||||
return parsedConfig;
|
return parsedConfig;
|
||||||
@@ -248,7 +248,7 @@ export const writeTraefikConfig = (
|
|||||||
try {
|
try {
|
||||||
const { DYNAMIC_TRAEFIK_PATH } = paths();
|
const { DYNAMIC_TRAEFIK_PATH } = paths();
|
||||||
const configPath = path.join(DYNAMIC_TRAEFIK_PATH, `${appName}.yml`);
|
const configPath = path.join(DYNAMIC_TRAEFIK_PATH, `${appName}.yml`);
|
||||||
const yamlStr = dump(traefikConfig);
|
const yamlStr = stringify(traefikConfig);
|
||||||
fs.writeFileSync(configPath, yamlStr, "utf8");
|
fs.writeFileSync(configPath, yamlStr, "utf8");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Error saving the YAML config file:", e);
|
console.error("Error saving the YAML config file:", e);
|
||||||
@@ -263,7 +263,7 @@ export const writeTraefikConfigRemote = 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`);
|
||||||
const yamlStr = dump(traefikConfig);
|
const yamlStr = stringify(traefikConfig);
|
||||||
await execAsyncRemote(serverId, `echo '${yamlStr}' > ${configPath}`);
|
await execAsyncRemote(serverId, `echo '${yamlStr}' > ${configPath}`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Error saving the YAML config file:", e);
|
console.error("Error saving the YAML config file:", e);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import { paths } from "@dokploy/server/constants";
|
import { paths } from "@dokploy/server/constants";
|
||||||
import type { Domain } from "@dokploy/server/services/domain";
|
import type { Domain } from "@dokploy/server/services/domain";
|
||||||
import { dump, load } from "js-yaml";
|
import { parse, stringify } from "yaml";
|
||||||
import type { ApplicationNested } from "../builders";
|
import type { ApplicationNested } from "../builders";
|
||||||
import { execAsyncRemote } from "../process/execAsync";
|
import { execAsyncRemote } from "../process/execAsync";
|
||||||
import { writeTraefikConfigRemote } from "./application";
|
import { writeTraefikConfigRemote } from "./application";
|
||||||
@@ -76,7 +76,7 @@ export const loadMiddlewares = <T>() => {
|
|||||||
throw new Error(`File not found: ${configPath}`);
|
throw new Error(`File not found: ${configPath}`);
|
||||||
}
|
}
|
||||||
const yamlStr = readFileSync(configPath, "utf8");
|
const yamlStr = readFileSync(configPath, "utf8");
|
||||||
const config = load(yamlStr) as T;
|
const config = parse(yamlStr) as T;
|
||||||
return config;
|
return config;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ export const loadRemoteMiddlewares = async (serverId: string) => {
|
|||||||
console.error(`Error: ${stderr}`);
|
console.error(`Error: ${stderr}`);
|
||||||
throw new Error(`File not found: ${configPath}`);
|
throw new Error(`File not found: ${configPath}`);
|
||||||
}
|
}
|
||||||
const config = load(stdout) as FileConfig;
|
const config = parse(stdout) as FileConfig;
|
||||||
return config;
|
return config;
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
throw new Error(`File not found: ${configPath}`);
|
throw new Error(`File not found: ${configPath}`);
|
||||||
@@ -103,7 +103,7 @@ export const loadRemoteMiddlewares = async (serverId: string) => {
|
|||||||
export const writeMiddleware = <T>(config: T) => {
|
export const writeMiddleware = <T>(config: T) => {
|
||||||
const { DYNAMIC_TRAEFIK_PATH } = paths();
|
const { DYNAMIC_TRAEFIK_PATH } = paths();
|
||||||
const configPath = join(DYNAMIC_TRAEFIK_PATH, "middlewares.yml");
|
const configPath = join(DYNAMIC_TRAEFIK_PATH, "middlewares.yml");
|
||||||
const newYamlContent = dump(config);
|
const newYamlContent = stringify(config);
|
||||||
writeFileSync(configPath, newYamlContent, "utf8");
|
writeFileSync(configPath, newYamlContent, "utf8");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import { paths } from "@dokploy/server/constants";
|
import { paths } from "@dokploy/server/constants";
|
||||||
import type { User } from "@dokploy/server/services/user";
|
import type { User } from "@dokploy/server/services/user";
|
||||||
import { dump, load } from "js-yaml";
|
import { parse, stringify } from "yaml";
|
||||||
import {
|
import {
|
||||||
loadOrCreateConfig,
|
loadOrCreateConfig,
|
||||||
removeTraefikConfig,
|
removeTraefikConfig,
|
||||||
@@ -79,13 +79,13 @@ export const updateLetsEncryptEmail = (newEmail: string | null) => {
|
|||||||
const { MAIN_TRAEFIK_PATH } = paths();
|
const { MAIN_TRAEFIK_PATH } = paths();
|
||||||
const configPath = join(MAIN_TRAEFIK_PATH, "traefik.yml");
|
const configPath = join(MAIN_TRAEFIK_PATH, "traefik.yml");
|
||||||
const configContent = readFileSync(configPath, "utf8");
|
const configContent = readFileSync(configPath, "utf8");
|
||||||
const config = load(configContent) as MainTraefikConfig;
|
const config = parse(configContent) as MainTraefikConfig;
|
||||||
if (config?.certificatesResolvers?.letsencrypt?.acme) {
|
if (config?.certificatesResolvers?.letsencrypt?.acme) {
|
||||||
config.certificatesResolvers.letsencrypt.acme.email = newEmail;
|
config.certificatesResolvers.letsencrypt.acme.email = newEmail;
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Invalid Let's Encrypt configuration structure.");
|
throw new Error("Invalid Let's Encrypt configuration structure.");
|
||||||
}
|
}
|
||||||
const newYamlContent = dump(config);
|
const newYamlContent = stringify(config);
|
||||||
writeFileSync(configPath, newYamlContent, "utf8");
|
writeFileSync(configPath, newYamlContent, "utf8");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
32
pnpm-lock.yaml
generated
32
pnpm-lock.yaml
generated
@@ -325,9 +325,6 @@ importers:
|
|||||||
js-cookie:
|
js-cookie:
|
||||||
specifier: ^3.0.5
|
specifier: ^3.0.5
|
||||||
version: 3.0.5
|
version: 3.0.5
|
||||||
js-yaml:
|
|
||||||
specifier: 4.1.0
|
|
||||||
version: 4.1.0
|
|
||||||
lodash:
|
lodash:
|
||||||
specifier: 4.17.21
|
specifier: 4.17.21
|
||||||
version: 4.17.21
|
version: 4.17.21
|
||||||
@@ -448,6 +445,9 @@ importers:
|
|||||||
xterm-addon-fit:
|
xterm-addon-fit:
|
||||||
specifier: ^0.8.0
|
specifier: ^0.8.0
|
||||||
version: 0.8.0(xterm@5.3.0)
|
version: 0.8.0(xterm@5.3.0)
|
||||||
|
yaml:
|
||||||
|
specifier: 2.8.1
|
||||||
|
version: 2.8.1
|
||||||
zod:
|
zod:
|
||||||
specifier: ^3.25.32
|
specifier: ^3.25.32
|
||||||
version: 3.25.32
|
version: 3.25.32
|
||||||
@@ -464,9 +464,6 @@ importers:
|
|||||||
'@types/js-cookie':
|
'@types/js-cookie':
|
||||||
specifier: ^3.0.6
|
specifier: ^3.0.6
|
||||||
version: 3.0.6
|
version: 3.0.6
|
||||||
'@types/js-yaml':
|
|
||||||
specifier: 4.0.9
|
|
||||||
version: 4.0.9
|
|
||||||
'@types/lodash':
|
'@types/lodash':
|
||||||
specifier: 4.17.4
|
specifier: 4.17.4
|
||||||
version: 4.17.4
|
version: 4.17.4
|
||||||
@@ -681,9 +678,6 @@ importers:
|
|||||||
hi-base32:
|
hi-base32:
|
||||||
specifier: ^0.5.1
|
specifier: ^0.5.1
|
||||||
version: 0.5.1
|
version: 0.5.1
|
||||||
js-yaml:
|
|
||||||
specifier: 4.1.0
|
|
||||||
version: 4.1.0
|
|
||||||
lodash:
|
lodash:
|
||||||
specifier: 4.17.21
|
specifier: 4.17.21
|
||||||
version: 4.17.21
|
version: 4.17.21
|
||||||
@@ -747,6 +741,9 @@ importers:
|
|||||||
ws:
|
ws:
|
||||||
specifier: 8.16.0
|
specifier: 8.16.0
|
||||||
version: 8.16.0
|
version: 8.16.0
|
||||||
|
yaml:
|
||||||
|
specifier: 2.8.1
|
||||||
|
version: 2.8.1
|
||||||
zod:
|
zod:
|
||||||
specifier: ^3.25.32
|
specifier: ^3.25.32
|
||||||
version: 3.25.32
|
version: 3.25.32
|
||||||
@@ -760,9 +757,6 @@ importers:
|
|||||||
'@types/dockerode':
|
'@types/dockerode':
|
||||||
specifier: 3.3.23
|
specifier: 3.3.23
|
||||||
version: 3.3.23
|
version: 3.3.23
|
||||||
'@types/js-yaml':
|
|
||||||
specifier: 4.0.9
|
|
||||||
version: 4.0.9
|
|
||||||
'@types/lodash':
|
'@types/lodash':
|
||||||
specifier: 4.17.4
|
specifier: 4.17.4
|
||||||
version: 4.17.4
|
version: 4.17.4
|
||||||
@@ -3965,9 +3959,6 @@ packages:
|
|||||||
'@types/js-cookie@3.0.6':
|
'@types/js-cookie@3.0.6':
|
||||||
resolution: {integrity: sha512-wkw9yd1kEXOPnvEeEV1Go1MmxtBJL0RR79aOTAApecWFVu7w0NNXNqhcWgvw2YgZDYadliXkl14pa3WXw5jlCQ==}
|
resolution: {integrity: sha512-wkw9yd1kEXOPnvEeEV1Go1MmxtBJL0RR79aOTAApecWFVu7w0NNXNqhcWgvw2YgZDYadliXkl14pa3WXw5jlCQ==}
|
||||||
|
|
||||||
'@types/js-yaml@4.0.9':
|
|
||||||
resolution: {integrity: sha512-k4MGaQl5TGo/iipqb2UDG2UwjXziSWkh0uysQelTlJpX1qGlpUZYm8PnO4DxG1qBomtJUdYJ6qR6xdIah10JLg==}
|
|
||||||
|
|
||||||
'@types/jsonwebtoken@9.0.9':
|
'@types/jsonwebtoken@9.0.9':
|
||||||
resolution: {integrity: sha512-uoe+GxEuHbvy12OUQct2X9JenKM3qAscquYymuQN4fMWG9DBQtykrQEFcAbVACF7qaLw9BePSodUL0kquqBJpQ==}
|
resolution: {integrity: sha512-uoe+GxEuHbvy12OUQct2X9JenKM3qAscquYymuQN4fMWG9DBQtykrQEFcAbVACF7qaLw9BePSodUL0kquqBJpQ==}
|
||||||
|
|
||||||
@@ -7783,6 +7774,11 @@ packages:
|
|||||||
engines: {node: '>= 14.6'}
|
engines: {node: '>= 14.6'}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
|
|
||||||
|
yaml@2.8.1:
|
||||||
|
resolution: {integrity: sha512-lcYcMxX2PO9XMGvAJkJ3OsNMw+/7FKes7/hgerGUYWIoWu5j/+YQqcZr5JnPZWzOsEBgMbSbiSTn/dv/69Mkpw==}
|
||||||
|
engines: {node: '>= 14.6'}
|
||||||
|
hasBin: true
|
||||||
|
|
||||||
yargs-parser@18.1.3:
|
yargs-parser@18.1.3:
|
||||||
resolution: {integrity: sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==}
|
resolution: {integrity: sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==}
|
||||||
engines: {node: '>=6'}
|
engines: {node: '>=6'}
|
||||||
@@ -11223,8 +11219,6 @@ snapshots:
|
|||||||
|
|
||||||
'@types/js-cookie@3.0.6': {}
|
'@types/js-cookie@3.0.6': {}
|
||||||
|
|
||||||
'@types/js-yaml@4.0.9': {}
|
|
||||||
|
|
||||||
'@types/jsonwebtoken@9.0.9':
|
'@types/jsonwebtoken@9.0.9':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/ms': 2.1.0
|
'@types/ms': 2.1.0
|
||||||
@@ -14032,7 +14026,7 @@ snapshots:
|
|||||||
postcss-load-config@4.0.2(postcss@8.5.3):
|
postcss-load-config@4.0.2(postcss@8.5.3):
|
||||||
dependencies:
|
dependencies:
|
||||||
lilconfig: 3.1.3
|
lilconfig: 3.1.3
|
||||||
yaml: 2.8.0
|
yaml: 2.8.1
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
postcss: 8.5.3
|
postcss: 8.5.3
|
||||||
|
|
||||||
@@ -15353,6 +15347,8 @@ snapshots:
|
|||||||
|
|
||||||
yaml@2.8.0: {}
|
yaml@2.8.0: {}
|
||||||
|
|
||||||
|
yaml@2.8.1: {}
|
||||||
|
|
||||||
yargs-parser@18.1.3:
|
yargs-parser@18.1.3:
|
||||||
dependencies:
|
dependencies:
|
||||||
camelcase: 5.3.1
|
camelcase: 5.3.1
|
||||||
|
|||||||
Reference in New Issue
Block a user