Merge branch 'canary' into feat/libsql

This commit is contained in:
Mauricio Siu
2025-09-21 02:47:55 -06:00
61 changed files with 503 additions and 304 deletions
@@ -1,7 +1,7 @@
import type { ComposeSpecification } from "@dokploy/server"; import type { ComposeSpecification } from "@dokploy/server";
import { addSuffixToAllProperties } from "@dokploy/server"; import { addSuffixToAllProperties } from "@dokploy/server";
import { load } from "js-yaml";
import { expect, test } from "vitest"; import { expect, test } from "vitest";
import { parse } from "yaml";
const composeFile1 = ` const composeFile1 = `
version: "3.8" version: "3.8"
@@ -61,7 +61,7 @@ secrets:
file: ./db_password.txt file: ./db_password.txt
`; `;
const expectedComposeFile1 = load(` const expectedComposeFile1 = parse(`
version: "3.8" version: "3.8"
services: services:
@@ -120,7 +120,7 @@ secrets:
`) as ComposeSpecification; `) as ComposeSpecification;
test("Add suffix to all properties in compose file 1", () => { test("Add suffix to all properties in compose file 1", () => {
const composeData = load(composeFile1) as ComposeSpecification; const composeData = parse(composeFile1) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
const updatedComposeData = addSuffixToAllProperties(composeData, suffix); const updatedComposeData = addSuffixToAllProperties(composeData, suffix);
@@ -185,7 +185,7 @@ secrets:
file: ./db_password.txt file: ./db_password.txt
`; `;
const expectedComposeFile2 = load(` const expectedComposeFile2 = parse(`
version: "3.8" version: "3.8"
services: services:
@@ -243,7 +243,7 @@ secrets:
`) as ComposeSpecification; `) as ComposeSpecification;
test("Add suffix to all properties in compose file 2", () => { test("Add suffix to all properties in compose file 2", () => {
const composeData = load(composeFile2) as ComposeSpecification; const composeData = parse(composeFile2) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
const updatedComposeData = addSuffixToAllProperties(composeData, suffix); const updatedComposeData = addSuffixToAllProperties(composeData, suffix);
@@ -308,7 +308,7 @@ secrets:
file: ./service_secret.txt file: ./service_secret.txt
`; `;
const expectedComposeFile3 = load(` const expectedComposeFile3 = parse(`
version: "3.8" version: "3.8"
services: services:
@@ -366,7 +366,7 @@ secrets:
`) as ComposeSpecification; `) as ComposeSpecification;
test("Add suffix to all properties in compose file 3", () => { test("Add suffix to all properties in compose file 3", () => {
const composeData = load(composeFile3) as ComposeSpecification; const composeData = parse(composeFile3) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
const updatedComposeData = addSuffixToAllProperties(composeData, suffix); const updatedComposeData = addSuffixToAllProperties(composeData, suffix);
@@ -420,7 +420,7 @@ volumes:
driver: local driver: local
`; `;
const expectedComposeFile = load(` const expectedComposeFile = parse(`
version: "3.8" version: "3.8"
services: services:
@@ -467,7 +467,7 @@ volumes:
`) as ComposeSpecification; `) as ComposeSpecification;
test("Add suffix to all properties in Plausible compose file", () => { test("Add suffix to all properties in Plausible compose file", () => {
const composeData = load(composeFile) as ComposeSpecification; const composeData = parse(composeFile) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
const updatedComposeData = addSuffixToAllProperties(composeData, suffix); const updatedComposeData = addSuffixToAllProperties(composeData, suffix);
@@ -1,7 +1,7 @@
import type { ComposeSpecification } from "@dokploy/server"; import type { ComposeSpecification } from "@dokploy/server";
import { addSuffixToConfigsRoot, generateRandomHash } from "@dokploy/server"; import { addSuffixToConfigsRoot, generateRandomHash } from "@dokploy/server";
import { load } from "js-yaml";
import { expect, test } from "vitest"; import { expect, test } from "vitest";
import { parse } from "yaml";
test("Generate random hash with 8 characters", () => { test("Generate random hash with 8 characters", () => {
const hash = generateRandomHash(); const hash = generateRandomHash();
@@ -23,7 +23,7 @@ configs:
`; `;
test("Add suffix to configs in root property", () => { test("Add suffix to configs in root property", () => {
const composeData = load(composeFile) as ComposeSpecification; const composeData = parse(composeFile) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -59,7 +59,7 @@ configs:
`; `;
test("Add suffix to multiple configs in root property", () => { test("Add suffix to multiple configs in root property", () => {
const composeData = load(composeFileMultipleConfigs) as ComposeSpecification; const composeData = parse(composeFileMultipleConfigs) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -92,7 +92,7 @@ configs:
`; `;
test("Add suffix to configs with different properties in root property", () => { test("Add suffix to configs with different properties in root property", () => {
const composeData = load( const composeData = parse(
composeFileDifferentProperties, composeFileDifferentProperties,
) as ComposeSpecification; ) as ComposeSpecification;
@@ -137,7 +137,7 @@ configs:
`; `;
// Expected compose file con el prefijo `testhash` // Expected compose file con el prefijo `testhash`
const expectedComposeFileConfigRoot = load(` const expectedComposeFileConfigRoot = parse(`
version: "3.8" version: "3.8"
services: services:
@@ -162,7 +162,7 @@ configs:
`) as ComposeSpecification; `) as ComposeSpecification;
test("Add suffix to configs in root property", () => { test("Add suffix to configs in root property", () => {
const composeData = load(composeFileConfigRoot) as ComposeSpecification; const composeData = parse(composeFileConfigRoot) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
@@ -3,8 +3,8 @@ import {
addSuffixToConfigsInServices, addSuffixToConfigsInServices,
generateRandomHash, generateRandomHash,
} from "@dokploy/server"; } from "@dokploy/server";
import { load } from "js-yaml";
import { expect, test } from "vitest"; import { expect, test } from "vitest";
import { parse } from "yaml";
const composeFile = ` const composeFile = `
version: "3.8" version: "3.8"
@@ -22,7 +22,7 @@ configs:
`; `;
test("Add suffix to configs in services", () => { test("Add suffix to configs in services", () => {
const composeData = load(composeFile) as ComposeSpecification; const composeData = parse(composeFile) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -54,7 +54,7 @@ configs:
`; `;
test("Add suffix to configs in services with single config", () => { test("Add suffix to configs in services with single config", () => {
const composeData = load( const composeData = parse(
composeFileSingleServiceConfig, composeFileSingleServiceConfig,
) as ComposeSpecification; ) as ComposeSpecification;
@@ -108,7 +108,7 @@ configs:
`; `;
test("Add suffix to configs in services with multiple configs", () => { test("Add suffix to configs in services with multiple configs", () => {
const composeData = load( const composeData = parse(
composeFileMultipleServicesConfigs, composeFileMultipleServicesConfigs,
) as ComposeSpecification; ) as ComposeSpecification;
@@ -157,7 +157,7 @@ services:
`; `;
// Expected compose file con el prefijo `testhash` // Expected compose file con el prefijo `testhash`
const expectedComposeFileConfigServices = load(` const expectedComposeFileConfigServices = parse(`
version: "3.8" version: "3.8"
services: services:
@@ -182,7 +182,7 @@ services:
`) as ComposeSpecification; `) as ComposeSpecification;
test("Add suffix to configs in services", () => { test("Add suffix to configs in services", () => {
const composeData = load(composeFileConfigServices) as ComposeSpecification; const composeData = parse(composeFileConfigServices) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
@@ -1,7 +1,7 @@
import type { ComposeSpecification } from "@dokploy/server"; import type { ComposeSpecification } from "@dokploy/server";
import { addSuffixToAllConfigs, generateRandomHash } from "@dokploy/server"; import { addSuffixToAllConfigs, generateRandomHash } from "@dokploy/server";
import { load } from "js-yaml";
import { expect, test } from "vitest"; import { expect, test } from "vitest";
import { parse } from "yaml";
test("Generate random hash with 8 characters", () => { test("Generate random hash with 8 characters", () => {
const hash = generateRandomHash(); const hash = generateRandomHash();
@@ -43,7 +43,7 @@ configs:
file: ./db-config.yml file: ./db-config.yml
`; `;
const expectedComposeFileCombinedConfigs = load(` const expectedComposeFileCombinedConfigs = parse(`
version: "3.8" version: "3.8"
services: services:
@@ -77,7 +77,7 @@ configs:
`) as ComposeSpecification; `) as ComposeSpecification;
test("Add suffix to all configs in root and services", () => { test("Add suffix to all configs in root and services", () => {
const composeData = load(composeFileCombinedConfigs) as ComposeSpecification; const composeData = parse(composeFileCombinedConfigs) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
@@ -122,7 +122,7 @@ configs:
file: ./db-config.yml file: ./db-config.yml
`; `;
const expectedComposeFileWithEnvAndExternal = load(` const expectedComposeFileWithEnvAndExternal = parse(`
version: "3.8" version: "3.8"
services: services:
@@ -159,7 +159,7 @@ configs:
`) as ComposeSpecification; `) as ComposeSpecification;
test("Add suffix to configs with environment and external", () => { test("Add suffix to configs with environment and external", () => {
const composeData = load( const composeData = parse(
composeFileWithEnvAndExternal, composeFileWithEnvAndExternal,
) as ComposeSpecification; ) as ComposeSpecification;
@@ -200,7 +200,7 @@ configs:
file: ./db-config.yml file: ./db-config.yml
`; `;
const expectedComposeFileWithTemplateDriverAndLabels = load(` const expectedComposeFileWithTemplateDriverAndLabels = parse(`
version: "3.8" version: "3.8"
services: services:
@@ -231,7 +231,7 @@ configs:
`) as ComposeSpecification; `) as ComposeSpecification;
test("Add suffix to configs with template driver and labels", () => { test("Add suffix to configs with template driver and labels", () => {
const composeData = load( const composeData = parse(
composeFileWithTemplateDriverAndLabels, composeFileWithTemplateDriverAndLabels,
) as ComposeSpecification; ) as ComposeSpecification;
@@ -1,7 +1,7 @@
import type { ComposeSpecification } from "@dokploy/server"; import type { ComposeSpecification } from "@dokploy/server";
import { addSuffixToNetworksRoot, generateRandomHash } from "@dokploy/server"; import { addSuffixToNetworksRoot, generateRandomHash } from "@dokploy/server";
import { load } from "js-yaml";
import { expect, test } from "vitest"; import { expect, test } from "vitest";
import { parse } from "yaml";
const composeFile = ` const composeFile = `
version: "3.8" version: "3.8"
@@ -35,7 +35,7 @@ test("Generate random hash with 8 characters", () => {
}); });
test("Add suffix to networks root property", () => { test("Add suffix to networks root property", () => {
const composeData = load(composeFile) as ComposeSpecification; const composeData = parse(composeFile) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -79,7 +79,7 @@ networks:
`; `;
test("Add suffix to advanced networks root property (2 TRY)", () => { test("Add suffix to advanced networks root property (2 TRY)", () => {
const composeData = load(composeFile2) as ComposeSpecification; const composeData = parse(composeFile2) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -120,7 +120,7 @@ networks:
`; `;
test("Add suffix to networks with external properties", () => { test("Add suffix to networks with external properties", () => {
const composeData = load(composeFile3) as ComposeSpecification; const composeData = parse(composeFile3) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -160,7 +160,7 @@ networks:
`; `;
test("Add suffix to networks with IPAM configurations", () => { test("Add suffix to networks with IPAM configurations", () => {
const composeData = load(composeFile4) as ComposeSpecification; const composeData = parse(composeFile4) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -201,7 +201,7 @@ networks:
`; `;
test("Add suffix to networks with custom options", () => { test("Add suffix to networks with custom options", () => {
const composeData = load(composeFile5) as ComposeSpecification; const composeData = parse(composeFile5) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -264,7 +264,7 @@ networks:
`; `;
test("Add suffix to networks with static suffix", () => { test("Add suffix to networks with static suffix", () => {
const composeData = load(composeFile6) as ComposeSpecification; const composeData = parse(composeFile6) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
@@ -273,7 +273,7 @@ test("Add suffix to networks with static suffix", () => {
} }
const networks = addSuffixToNetworksRoot(composeData.networks, suffix); const networks = addSuffixToNetworksRoot(composeData.networks, suffix);
const expectedComposeData = load( const expectedComposeData = parse(
expectedComposeFile6, expectedComposeFile6,
) as ComposeSpecification; ) as ComposeSpecification;
expect(networks).toStrictEqual(expectedComposeData.networks); expect(networks).toStrictEqual(expectedComposeData.networks);
@@ -293,7 +293,7 @@ networks:
`; `;
test("It shoudn't add suffix to dokploy-network", () => { test("It shoudn't add suffix to dokploy-network", () => {
const composeData = load(composeFile7) as ComposeSpecification; const composeData = parse(composeFile7) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -3,8 +3,8 @@ import {
addSuffixToServiceNetworks, addSuffixToServiceNetworks,
generateRandomHash, generateRandomHash,
} from "@dokploy/server"; } from "@dokploy/server";
import { load } from "js-yaml";
import { expect, test } from "vitest"; import { expect, test } from "vitest";
import { parse } from "yaml";
const composeFile = ` const composeFile = `
version: "3.8" version: "3.8"
@@ -23,7 +23,7 @@ services:
`; `;
test("Add suffix to networks in services", () => { test("Add suffix to networks in services", () => {
const composeData = load(composeFile) as ComposeSpecification; const composeData = parse(composeFile) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -67,7 +67,7 @@ networks:
`; `;
test("Add suffix to networks in services with aliases", () => { test("Add suffix to networks in services with aliases", () => {
const composeData = load(composeFile2) as ComposeSpecification; const composeData = parse(composeFile2) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -107,7 +107,7 @@ networks:
`; `;
test("Add suffix to networks in services (Object with simple networks)", () => { test("Add suffix to networks in services (Object with simple networks)", () => {
const composeData = load(composeFile3) as ComposeSpecification; const composeData = parse(composeFile3) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -153,7 +153,7 @@ networks:
`; `;
test("Add suffix to networks in services (combined case)", () => { test("Add suffix to networks in services (combined case)", () => {
const composeData = load(composeFileCombined) as ComposeSpecification; const composeData = parse(composeFileCombined) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -196,7 +196,7 @@ services:
`; `;
test("It shoudn't add suffix to dokploy-network in services", () => { test("It shoudn't add suffix to dokploy-network in services", () => {
const composeData = load(composeFile7) as ComposeSpecification; const composeData = parse(composeFile7) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -245,7 +245,7 @@ services:
`; `;
test("It shoudn't add suffix to dokploy-network in services multiples cases", () => { test("It shoudn't add suffix to dokploy-network in services multiples cases", () => {
const composeData = load(composeFile8) as ComposeSpecification; const composeData = parse(composeFile8) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -5,8 +5,8 @@ import {
addSuffixToServiceNetworks, addSuffixToServiceNetworks,
generateRandomHash, generateRandomHash,
} from "@dokploy/server"; } from "@dokploy/server";
import { load } from "js-yaml";
import { expect, test } from "vitest"; import { expect, test } from "vitest";
import { parse } from "yaml";
const composeFileCombined = ` const composeFileCombined = `
version: "3.8" version: "3.8"
@@ -39,7 +39,7 @@ networks:
`; `;
test("Add suffix to networks in services and root (combined case)", () => { test("Add suffix to networks in services and root (combined case)", () => {
const composeData = load(composeFileCombined) as ComposeSpecification; const composeData = parse(composeFileCombined) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -89,7 +89,7 @@ test("Add suffix to networks in services and root (combined case)", () => {
expect(redisNetworks).not.toHaveProperty("backend"); expect(redisNetworks).not.toHaveProperty("backend");
}); });
const expectedComposeFile = load(` const expectedComposeFile = parse(`
version: "3.8" version: "3.8"
services: services:
@@ -120,7 +120,7 @@ networks:
`); `);
test("Add suffix to networks in compose file", () => { test("Add suffix to networks in compose file", () => {
const composeData = load(composeFileCombined) as ComposeSpecification; const composeData = parse(composeFileCombined) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
if (!composeData?.networks) { if (!composeData?.networks) {
@@ -156,7 +156,7 @@ networks:
driver: bridge driver: bridge
`; `;
const expectedComposeFile2 = load(` const expectedComposeFile2 = parse(`
version: "3.8" version: "3.8"
services: services:
@@ -182,7 +182,7 @@ networks:
`); `);
test("Add suffix to networks in compose file with external and internal networks", () => { test("Add suffix to networks in compose file with external and internal networks", () => {
const composeData = load(composeFile2) as ComposeSpecification; const composeData = parse(composeFile2) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
const updatedComposeData = addSuffixToAllNetworks(composeData, suffix); const updatedComposeData = addSuffixToAllNetworks(composeData, suffix);
@@ -218,7 +218,7 @@ networks:
com.docker.network.bridge.enable_icc: "true" com.docker.network.bridge.enable_icc: "true"
`; `;
const expectedComposeFile3 = load(` const expectedComposeFile3 = parse(`
version: "3.8" version: "3.8"
services: services:
@@ -247,7 +247,7 @@ networks:
`); `);
test("Add suffix to networks in compose file with multiple services and complex network configurations", () => { test("Add suffix to networks in compose file with multiple services and complex network configurations", () => {
const composeData = load(composeFile3) as ComposeSpecification; const composeData = parse(composeFile3) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
const updatedComposeData = addSuffixToAllNetworks(composeData, suffix); const updatedComposeData = addSuffixToAllNetworks(composeData, suffix);
@@ -289,7 +289,7 @@ networks:
`; `;
const expectedComposeFile4 = load(` const expectedComposeFile4 = parse(`
version: "3.8" version: "3.8"
services: services:
@@ -326,7 +326,7 @@ networks:
`); `);
test("Expect don't add suffix to dokploy-network in compose file with multiple services and complex network configurations", () => { test("Expect don't add suffix to dokploy-network in compose file with multiple services and complex network configurations", () => {
const composeData = load(composeFile4) as ComposeSpecification; const composeData = parse(composeFile4) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
const updatedComposeData = addSuffixToAllNetworks(composeData, suffix); const updatedComposeData = addSuffixToAllNetworks(composeData, suffix);
@@ -1,7 +1,7 @@
import type { ComposeSpecification } from "@dokploy/server"; import type { ComposeSpecification } from "@dokploy/server";
import { addSuffixToSecretsRoot, generateRandomHash } from "@dokploy/server"; import { addSuffixToSecretsRoot, generateRandomHash } from "@dokploy/server";
import { load } from "js-yaml";
import { expect, test } from "vitest"; import { expect, test } from "vitest";
import { parse } from "yaml";
test("Generate random hash with 8 characters", () => { test("Generate random hash with 8 characters", () => {
const hash = generateRandomHash(); const hash = generateRandomHash();
@@ -23,7 +23,7 @@ secrets:
`; `;
test("Add suffix to secrets in root property", () => { test("Add suffix to secrets in root property", () => {
const composeData = load(composeFileSecretsRoot) as ComposeSpecification; const composeData = parse(composeFileSecretsRoot) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
if (!composeData?.secrets) { if (!composeData?.secrets) {
@@ -52,7 +52,7 @@ secrets:
`; `;
test("Add suffix to secrets in root property (Test 1)", () => { test("Add suffix to secrets in root property (Test 1)", () => {
const composeData = load(composeFileSecretsRoot1) as ComposeSpecification; const composeData = parse(composeFileSecretsRoot1) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
if (!composeData?.secrets) { if (!composeData?.secrets) {
@@ -84,7 +84,7 @@ secrets:
`; `;
test("Add suffix to secrets in root property (Test 2)", () => { test("Add suffix to secrets in root property (Test 2)", () => {
const composeData = load(composeFileSecretsRoot2) as ComposeSpecification; const composeData = parse(composeFileSecretsRoot2) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
if (!composeData?.secrets) { if (!composeData?.secrets) {
@@ -3,8 +3,8 @@ import {
addSuffixToSecretsInServices, addSuffixToSecretsInServices,
generateRandomHash, generateRandomHash,
} from "@dokploy/server"; } from "@dokploy/server";
import { load } from "js-yaml";
import { expect, test } from "vitest"; import { expect, test } from "vitest";
import { parse } from "yaml";
const composeFileSecretsServices = ` const composeFileSecretsServices = `
version: "3.8" version: "3.8"
@@ -21,7 +21,7 @@ secrets:
`; `;
test("Add suffix to secrets in services", () => { test("Add suffix to secrets in services", () => {
const composeData = load(composeFileSecretsServices) as ComposeSpecification; const composeData = parse(composeFileSecretsServices) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
if (!composeData.services) { if (!composeData.services) {
@@ -54,7 +54,9 @@ secrets:
`; `;
test("Add suffix to secrets in services (Test 1)", () => { test("Add suffix to secrets in services (Test 1)", () => {
const composeData = load(composeFileSecretsServices1) as ComposeSpecification; const composeData = parse(
composeFileSecretsServices1,
) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
if (!composeData.services) { if (!composeData.services) {
@@ -93,7 +95,9 @@ secrets:
`; `;
test("Add suffix to secrets in services (Test 2)", () => { test("Add suffix to secrets in services (Test 2)", () => {
const composeData = load(composeFileSecretsServices2) as ComposeSpecification; const composeData = parse(
composeFileSecretsServices2,
) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
if (!composeData.services) { if (!composeData.services) {
@@ -1,7 +1,7 @@
import type { ComposeSpecification } from "@dokploy/server"; import type { ComposeSpecification } from "@dokploy/server";
import { addSuffixToAllSecrets } from "@dokploy/server"; import { addSuffixToAllSecrets } from "@dokploy/server";
import { load } from "js-yaml";
import { expect, test } from "vitest"; import { expect, test } from "vitest";
import { parse } from "yaml";
const composeFileCombinedSecrets = ` const composeFileCombinedSecrets = `
version: "3.8" version: "3.8"
@@ -25,7 +25,7 @@ secrets:
file: ./app_secret.txt file: ./app_secret.txt
`; `;
const expectedComposeFileCombinedSecrets = load(` const expectedComposeFileCombinedSecrets = parse(`
version: "3.8" version: "3.8"
services: services:
@@ -48,7 +48,7 @@ secrets:
`) as ComposeSpecification; `) as ComposeSpecification;
test("Add suffix to all secrets", () => { test("Add suffix to all secrets", () => {
const composeData = load(composeFileCombinedSecrets) as ComposeSpecification; const composeData = parse(composeFileCombinedSecrets) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
const updatedComposeData = addSuffixToAllSecrets(composeData, suffix); const updatedComposeData = addSuffixToAllSecrets(composeData, suffix);
@@ -77,7 +77,7 @@ secrets:
file: ./cache_secret.txt file: ./cache_secret.txt
`; `;
const expectedComposeFileCombinedSecrets3 = load(` const expectedComposeFileCombinedSecrets3 = parse(`
version: "3.8" version: "3.8"
services: services:
@@ -99,7 +99,9 @@ secrets:
`) as ComposeSpecification; `) as ComposeSpecification;
test("Add suffix to all secrets (3rd Case)", () => { test("Add suffix to all secrets (3rd Case)", () => {
const composeData = load(composeFileCombinedSecrets3) as ComposeSpecification; const composeData = parse(
composeFileCombinedSecrets3,
) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
const updatedComposeData = addSuffixToAllSecrets(composeData, suffix); const updatedComposeData = addSuffixToAllSecrets(composeData, suffix);
@@ -128,7 +130,7 @@ secrets:
file: ./db_password.txt file: ./db_password.txt
`; `;
const expectedComposeFileCombinedSecrets4 = load(` const expectedComposeFileCombinedSecrets4 = parse(`
version: "3.8" version: "3.8"
services: services:
@@ -150,7 +152,9 @@ secrets:
`) as ComposeSpecification; `) as ComposeSpecification;
test("Add suffix to all secrets (4th Case)", () => { test("Add suffix to all secrets (4th Case)", () => {
const composeData = load(composeFileCombinedSecrets4) as ComposeSpecification; const composeData = parse(
composeFileCombinedSecrets4,
) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
const updatedComposeData = addSuffixToAllSecrets(composeData, suffix); const updatedComposeData = addSuffixToAllSecrets(composeData, suffix);
@@ -1,7 +1,7 @@
import type { ComposeSpecification } from "@dokploy/server"; import type { ComposeSpecification } from "@dokploy/server";
import { addSuffixToServiceNames, generateRandomHash } from "@dokploy/server"; import { addSuffixToServiceNames, generateRandomHash } from "@dokploy/server";
import { load } from "js-yaml";
import { expect, test } from "vitest"; import { expect, test } from "vitest";
import { parse } from "yaml";
const composeFile = ` const composeFile = `
version: "3.8" version: "3.8"
@@ -27,7 +27,7 @@ test("Generate random hash with 8 characters", () => {
}); });
test("Add suffix to service names with container_name in compose file", () => { test("Add suffix to service names with container_name in compose file", () => {
const composeData = load(composeFile) as ComposeSpecification; const composeData = parse(composeFile) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -1,7 +1,7 @@
import type { ComposeSpecification } from "@dokploy/server"; import type { ComposeSpecification } from "@dokploy/server";
import { addSuffixToServiceNames, generateRandomHash } from "@dokploy/server"; import { addSuffixToServiceNames, generateRandomHash } from "@dokploy/server";
import { load } from "js-yaml";
import { expect, test } from "vitest"; import { expect, test } from "vitest";
import { parse } from "yaml";
test("Generate random hash with 8 characters", () => { test("Generate random hash with 8 characters", () => {
const hash = generateRandomHash(); const hash = generateRandomHash();
@@ -32,7 +32,7 @@ networks:
`; `;
test("Add suffix to service names with depends_on (array) in compose file", () => { test("Add suffix to service names with depends_on (array) in compose file", () => {
const composeData = load(composeFile4) as ComposeSpecification; const composeData = parse(composeFile4) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -102,7 +102,7 @@ networks:
`; `;
test("Add suffix to service names with depends_on (object) in compose file", () => { test("Add suffix to service names with depends_on (object) in compose file", () => {
const composeData = load(composeFile5) as ComposeSpecification; const composeData = parse(composeFile5) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -1,7 +1,7 @@
import type { ComposeSpecification } from "@dokploy/server"; import type { ComposeSpecification } from "@dokploy/server";
import { addSuffixToServiceNames, generateRandomHash } from "@dokploy/server"; import { addSuffixToServiceNames, generateRandomHash } from "@dokploy/server";
import { load } from "js-yaml";
import { expect, test } from "vitest"; import { expect, test } from "vitest";
import { parse } from "yaml";
test("Generate random hash with 8 characters", () => { test("Generate random hash with 8 characters", () => {
const hash = generateRandomHash(); const hash = generateRandomHash();
@@ -30,7 +30,7 @@ networks:
`; `;
test("Add suffix to service names with extends (string) in compose file", () => { test("Add suffix to service names with extends (string) in compose file", () => {
const composeData = load(composeFile6) as ComposeSpecification; const composeData = parse(composeFile6) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -90,7 +90,7 @@ networks:
`; `;
test("Add suffix to service names with extends (object) in compose file", () => { test("Add suffix to service names with extends (object) in compose file", () => {
const composeData = load(composeFile7) as ComposeSpecification; const composeData = parse(composeFile7) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -1,7 +1,7 @@
import type { ComposeSpecification } from "@dokploy/server"; import type { ComposeSpecification } from "@dokploy/server";
import { addSuffixToServiceNames, generateRandomHash } from "@dokploy/server"; import { addSuffixToServiceNames, generateRandomHash } from "@dokploy/server";
import { load } from "js-yaml";
import { expect, test } from "vitest"; import { expect, test } from "vitest";
import { parse } from "yaml";
test("Generate random hash with 8 characters", () => { test("Generate random hash with 8 characters", () => {
const hash = generateRandomHash(); const hash = generateRandomHash();
@@ -31,7 +31,7 @@ networks:
`; `;
test("Add suffix to service names with links in compose file", () => { test("Add suffix to service names with links in compose file", () => {
const composeData = load(composeFile2) as ComposeSpecification; const composeData = parse(composeFile2) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -1,7 +1,7 @@
import type { ComposeSpecification } from "@dokploy/server"; import type { ComposeSpecification } from "@dokploy/server";
import { addSuffixToServiceNames, generateRandomHash } from "@dokploy/server"; import { addSuffixToServiceNames, generateRandomHash } from "@dokploy/server";
import { load } from "js-yaml";
import { expect, test } from "vitest"; import { expect, test } from "vitest";
import { parse } from "yaml";
test("Generate random hash with 8 characters", () => { test("Generate random hash with 8 characters", () => {
const hash = generateRandomHash(); const hash = generateRandomHash();
@@ -26,7 +26,7 @@ networks:
`; `;
test("Add suffix to service names in compose file", () => { test("Add suffix to service names in compose file", () => {
const composeData = load(composeFile) as ComposeSpecification; const composeData = parse(composeFile) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -3,8 +3,8 @@ import {
addSuffixToAllServiceNames, addSuffixToAllServiceNames,
addSuffixToServiceNames, addSuffixToServiceNames,
} from "@dokploy/server"; } from "@dokploy/server";
import { load } from "js-yaml";
import { expect, test } from "vitest"; import { expect, test } from "vitest";
import { parse } from "yaml";
const composeFileCombinedAllCases = ` const composeFileCombinedAllCases = `
version: "3.8" version: "3.8"
@@ -38,7 +38,7 @@ networks:
driver: bridge driver: bridge
`; `;
const expectedComposeFile = load(` const expectedComposeFile = parse(`
version: "3.8" version: "3.8"
services: services:
@@ -71,7 +71,9 @@ networks:
`); `);
test("Add suffix to all service names in compose file", () => { test("Add suffix to all service names in compose file", () => {
const composeData = load(composeFileCombinedAllCases) as ComposeSpecification; const composeData = parse(
composeFileCombinedAllCases,
) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
@@ -131,7 +133,7 @@ networks:
driver: bridge driver: bridge
`; `;
const expectedComposeFile1 = load(` const expectedComposeFile1 = parse(`
version: "3.8" version: "3.8"
services: services:
@@ -176,7 +178,7 @@ networks:
`) as ComposeSpecification; `) as ComposeSpecification;
test("Add suffix to all service names in compose file 1", () => { test("Add suffix to all service names in compose file 1", () => {
const composeData = load(composeFile1) as ComposeSpecification; const composeData = parse(composeFile1) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
const updatedComposeData = addSuffixToAllServiceNames(composeData, suffix); const updatedComposeData = addSuffixToAllServiceNames(composeData, suffix);
@@ -227,7 +229,7 @@ networks:
driver: bridge driver: bridge
`; `;
const expectedComposeFile2 = load(` const expectedComposeFile2 = parse(`
version: "3.8" version: "3.8"
services: services:
@@ -271,7 +273,7 @@ networks:
`) as ComposeSpecification; `) as ComposeSpecification;
test("Add suffix to all service names in compose file 2", () => { test("Add suffix to all service names in compose file 2", () => {
const composeData = load(composeFile2) as ComposeSpecification; const composeData = parse(composeFile2) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
const updatedComposeData = addSuffixToAllServiceNames(composeData, suffix); const updatedComposeData = addSuffixToAllServiceNames(composeData, suffix);
@@ -322,7 +324,7 @@ networks:
driver: bridge driver: bridge
`; `;
const expectedComposeFile3 = load(` const expectedComposeFile3 = parse(`
version: "3.8" version: "3.8"
services: services:
@@ -366,7 +368,7 @@ networks:
`) as ComposeSpecification; `) as ComposeSpecification;
test("Add suffix to all service names in compose file 3", () => { test("Add suffix to all service names in compose file 3", () => {
const composeData = load(composeFile3) as ComposeSpecification; const composeData = parse(composeFile3) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
const updatedComposeData = addSuffixToAllServiceNames(composeData, suffix); const updatedComposeData = addSuffixToAllServiceNames(composeData, suffix);
@@ -1,7 +1,7 @@
import type { ComposeSpecification } from "@dokploy/server"; import type { ComposeSpecification } from "@dokploy/server";
import { addSuffixToServiceNames, generateRandomHash } from "@dokploy/server"; import { addSuffixToServiceNames, generateRandomHash } from "@dokploy/server";
import { load } from "js-yaml";
import { expect, test } from "vitest"; import { expect, test } from "vitest";
import { parse } from "yaml";
test("Generate random hash with 8 characters", () => { test("Generate random hash with 8 characters", () => {
const hash = generateRandomHash(); const hash = generateRandomHash();
@@ -35,7 +35,7 @@ networks:
`; `;
test("Add suffix to service names with volumes_from in compose file", () => { test("Add suffix to service names with volumes_from in compose file", () => {
const composeData = load(composeFile3) as ComposeSpecification; const composeData = parse(composeFile3) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -4,8 +4,8 @@ import {
addSuffixToVolumesRoot, addSuffixToVolumesRoot,
generateRandomHash, generateRandomHash,
} from "@dokploy/server"; } from "@dokploy/server";
import { load } from "js-yaml";
import { expect, test } from "vitest"; import { expect, test } from "vitest";
import { parse } from "yaml";
const composeFile = ` const composeFile = `
services: services:
@@ -70,7 +70,7 @@ volumes:
driver: local driver: local
`; `;
const expectedDockerCompose = load(` const expectedDockerCompose = parse(`
services: services:
mail: mail:
image: bytemark/smtp image: bytemark/smtp
@@ -143,7 +143,7 @@ test("Generate random hash with 8 characters", () => {
// Docker compose needs unique names for services, volumes, networks and containers // Docker compose needs unique names for services, volumes, networks and containers
// So base on a input which is a dockercompose file, it should replace the name with a hash and return a new dockercompose file // So base on a input which is a dockercompose file, it should replace the name with a hash and return a new dockercompose file
test("Add suffix to volumes root property", () => { test("Add suffix to volumes root property", () => {
const composeData = load(composeFile) as ComposeSpecification; const composeData = parse(composeFile) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -165,7 +165,7 @@ test("Add suffix to volumes root property", () => {
}); });
test("Expect to change the suffix in all the possible places", () => { test("Expect to change the suffix in all the possible places", () => {
const composeData = load(composeFile) as ComposeSpecification; const composeData = parse(composeFile) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
const updatedComposeData = addSuffixToAllVolumes(composeData, suffix); const updatedComposeData = addSuffixToAllVolumes(composeData, suffix);
@@ -195,7 +195,7 @@ volumes:
mongo-data: mongo-data:
`; `;
const expectedDockerCompose2 = load(` const expectedDockerCompose2 = parse(`
version: '3.8' version: '3.8'
services: services:
app: app:
@@ -218,7 +218,7 @@ volumes:
`) as ComposeSpecification; `) as ComposeSpecification;
test("Expect to change the suffix in all the possible places (2 Try)", () => { test("Expect to change the suffix in all the possible places (2 Try)", () => {
const composeData = load(composeFile2) as ComposeSpecification; const composeData = parse(composeFile2) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
const updatedComposeData = addSuffixToAllVolumes(composeData, suffix); const updatedComposeData = addSuffixToAllVolumes(composeData, suffix);
@@ -248,7 +248,7 @@ volumes:
mongo-data: mongo-data:
`; `;
const expectedDockerCompose3 = load(` const expectedDockerCompose3 = parse(`
version: '3.8' version: '3.8'
services: services:
app: app:
@@ -271,7 +271,7 @@ volumes:
`) as ComposeSpecification; `) as ComposeSpecification;
test("Expect to change the suffix in all the possible places (3 Try)", () => { test("Expect to change the suffix in all the possible places (3 Try)", () => {
const composeData = load(composeFile3) as ComposeSpecification; const composeData = parse(composeFile3) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
const updatedComposeData = addSuffixToAllVolumes(composeData, suffix); const updatedComposeData = addSuffixToAllVolumes(composeData, suffix);
@@ -645,7 +645,7 @@ volumes:
db-config: db-config:
`; `;
const expectedDockerComposeComplex = load(` const expectedDockerComposeComplex = parse(`
version: "3.8" version: "3.8"
services: services:
studio: studio:
@@ -1012,7 +1012,7 @@ volumes:
`); `);
test("Expect to change the suffix in all the possible places (4 Try)", () => { test("Expect to change the suffix in all the possible places (4 Try)", () => {
const composeData = load(composeFileComplex) as ComposeSpecification; const composeData = parse(composeFileComplex) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
const updatedComposeData = addSuffixToAllVolumes(composeData, suffix); const updatedComposeData = addSuffixToAllVolumes(composeData, suffix);
@@ -1065,7 +1065,7 @@ volumes:
db-data: db-data:
`; `;
const expectedDockerComposeExample1 = load(` const expectedDockerComposeExample1 = parse(`
version: "3.8" version: "3.8"
services: services:
web: web:
@@ -1111,7 +1111,7 @@ volumes:
`) as ComposeSpecification; `) as ComposeSpecification;
test("Expect to change the suffix in all the possible places (5 Try)", () => { test("Expect to change the suffix in all the possible places (5 Try)", () => {
const composeData = load(composeFileExample1) as ComposeSpecification; const composeData = parse(composeFileExample1) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
const updatedComposeData = addSuffixToAllVolumes(composeData, suffix); const updatedComposeData = addSuffixToAllVolumes(composeData, suffix);
@@ -1143,7 +1143,7 @@ volumes:
backrest-cache: backrest-cache:
`; `;
const expectedDockerComposeBackrest = load(` const expectedDockerComposeBackrest = parse(`
services: services:
backrest: backrest:
image: garethgeorge/backrest:v1.7.3 image: garethgeorge/backrest:v1.7.3
@@ -1168,7 +1168,7 @@ volumes:
`) as ComposeSpecification; `) as ComposeSpecification;
test("Should handle volume paths with subdirectories correctly", () => { test("Should handle volume paths with subdirectories correctly", () => {
const composeData = load(composeFileBackrest) as ComposeSpecification; const composeData = parse(composeFileBackrest) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
const updatedComposeData = addSuffixToAllVolumes(composeData, suffix); const updatedComposeData = addSuffixToAllVolumes(composeData, suffix);
@@ -1,7 +1,7 @@
import type { ComposeSpecification } from "@dokploy/server"; import type { ComposeSpecification } from "@dokploy/server";
import { addSuffixToVolumesRoot, generateRandomHash } from "@dokploy/server"; import { addSuffixToVolumesRoot, generateRandomHash } from "@dokploy/server";
import { load } from "js-yaml";
import { expect, test } from "vitest"; import { expect, test } from "vitest";
import { parse } from "yaml";
const composeFile = ` const composeFile = `
version: "3.8" version: "3.8"
@@ -29,7 +29,7 @@ test("Generate random hash with 8 characters", () => {
}); });
test("Add suffix to volumes in root property", () => { test("Add suffix to volumes in root property", () => {
const composeData = load(composeFile) as ComposeSpecification; const composeData = parse(composeFile) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -67,7 +67,7 @@ networks:
`; `;
test("Add suffix to volumes in root property (Case 2)", () => { test("Add suffix to volumes in root property (Case 2)", () => {
const composeData = load(composeFile2) as ComposeSpecification; const composeData = parse(composeFile2) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -101,7 +101,7 @@ networks:
`; `;
test("Add suffix to volumes in root property (Case 3)", () => { test("Add suffix to volumes in root property (Case 3)", () => {
const composeData = load(composeFile3) as ComposeSpecification; const composeData = parse(composeFile3) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -148,7 +148,7 @@ volumes:
`; `;
// Expected compose file con el prefijo `testhash` // Expected compose file con el prefijo `testhash`
const expectedComposeFile4 = load(` const expectedComposeFile4 = parse(`
version: "3.8" version: "3.8"
services: services:
@@ -179,7 +179,7 @@ volumes:
`) as ComposeSpecification; `) as ComposeSpecification;
test("Add suffix to volumes in root property", () => { test("Add suffix to volumes in root property", () => {
const composeData = load(composeFile4) as ComposeSpecification; const composeData = parse(composeFile4) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
@@ -3,8 +3,8 @@ import {
addSuffixToVolumesInServices, addSuffixToVolumesInServices,
generateRandomHash, generateRandomHash,
} from "@dokploy/server"; } from "@dokploy/server";
import { load } from "js-yaml";
import { expect, test } from "vitest"; import { expect, test } from "vitest";
import { parse } from "yaml";
test("Generate random hash with 8 characters", () => { test("Generate random hash with 8 characters", () => {
const hash = generateRandomHash(); const hash = generateRandomHash();
@@ -24,7 +24,7 @@ services:
`; `;
test("Add suffix to volumes declared directly in services", () => { test("Add suffix to volumes declared directly in services", () => {
const composeData = load(composeFile1) as ComposeSpecification; const composeData = parse(composeFile1) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -59,7 +59,7 @@ volumes:
`; `;
test("Add suffix to volumes declared directly in services (Case 2)", () => { test("Add suffix to volumes declared directly in services (Case 2)", () => {
const composeData = load(composeFileTypeVolume) as ComposeSpecification; const composeData = parse(composeFileTypeVolume) as ComposeSpecification;
const suffix = generateRandomHash(); const suffix = generateRandomHash();
@@ -1,7 +1,7 @@
import type { ComposeSpecification } from "@dokploy/server"; import type { ComposeSpecification } from "@dokploy/server";
import { addSuffixToAllVolumes } from "@dokploy/server"; import { addSuffixToAllVolumes } from "@dokploy/server";
import { load } from "js-yaml";
import { expect, test } from "vitest"; import { expect, test } from "vitest";
import { parse } from "yaml";
const composeFileTypeVolume = ` const composeFileTypeVolume = `
version: "3.8" version: "3.8"
@@ -23,7 +23,7 @@ volumes:
driver: local driver: local
`; `;
const expectedComposeFileTypeVolume = load(` const expectedComposeFileTypeVolume = parse(`
version: "3.8" version: "3.8"
services: services:
@@ -44,7 +44,7 @@ volumes:
`) as ComposeSpecification; `) as ComposeSpecification;
test("Add suffix to volumes with type: volume in services", () => { test("Add suffix to volumes with type: volume in services", () => {
const composeData = load(composeFileTypeVolume) as ComposeSpecification; const composeData = parse(composeFileTypeVolume) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
@@ -73,7 +73,7 @@ volumes:
driver: local driver: local
`; `;
const expectedComposeFileTypeVolume1 = load(` const expectedComposeFileTypeVolume1 = parse(`
version: "3.8" version: "3.8"
services: services:
@@ -93,7 +93,7 @@ volumes:
`) as ComposeSpecification; `) as ComposeSpecification;
test("Add suffix to mixed volumes in services", () => { test("Add suffix to mixed volumes in services", () => {
const composeData = load(composeFileTypeVolume1) as ComposeSpecification; const composeData = parse(composeFileTypeVolume1) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
@@ -128,7 +128,7 @@ volumes:
device: /path/to/app/logs device: /path/to/app/logs
`; `;
const expectedComposeFileTypeVolume2 = load(` const expectedComposeFileTypeVolume2 = parse(`
version: "3.8" version: "3.8"
services: services:
@@ -154,7 +154,7 @@ volumes:
`) as ComposeSpecification; `) as ComposeSpecification;
test("Add suffix to complex volume configurations in services", () => { test("Add suffix to complex volume configurations in services", () => {
const composeData = load(composeFileTypeVolume2) as ComposeSpecification; const composeData = parse(composeFileTypeVolume2) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
@@ -218,7 +218,7 @@ volumes:
device: /path/to/shared/logs device: /path/to/shared/logs
`; `;
const expectedComposeFileTypeVolume3 = load(` const expectedComposeFileTypeVolume3 = parse(`
version: "3.8" version: "3.8"
services: services:
@@ -273,7 +273,7 @@ volumes:
`) as ComposeSpecification; `) as ComposeSpecification;
test("Add suffix to complex nested volumes configuration in services", () => { test("Add suffix to complex nested volumes configuration in services", () => {
const composeData = load(composeFileTypeVolume3) as ComposeSpecification; const composeData = parse(composeFileTypeVolume3) as ComposeSpecification;
const suffix = "testhash"; const suffix = "testhash";
@@ -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;
} }
@@ -171,7 +171,7 @@ export const AddTemplate = ({ environmentId, baseUrl }: Props) => {
<Input <Input
placeholder="Search Template" placeholder="Search Template"
onChange={(e) => setQuery(e.target.value)} onChange={(e) => setQuery(e.target.value)}
className="w-full sm:w-[200px]" className="w-full"
value={query} value={query}
/> />
<Input <Input
@@ -248,7 +248,7 @@ export const AddTemplate = ({ environmentId, baseUrl }: Props) => {
onClick={() => onClick={() =>
setViewMode(viewMode === "detailed" ? "icon" : "detailed") setViewMode(viewMode === "detailed" ? "icon" : "detailed")
} }
className="h-9 w-9" className="h-9 w-9 flex-shrink-0"
> >
{viewMode === "detailed" ? ( {viewMode === "detailed" ? (
<LayoutGrid className="size-4" /> <LayoutGrid className="size-4" />
@@ -88,7 +88,7 @@ export const StepThree = ({ templateInfo }: StepProps) => {
<div> <div>
<h3 className="text-sm font-semibold">Configuration Files</h3> <h3 className="text-sm font-semibold">Configuration Files</h3>
<ul className="list-disc pl-5"> <ul className="list-disc pl-5">
{templateInfo?.details?.configFiles.map((file, index) => ( {templateInfo?.details?.configFiles?.map((file, index) => (
<li key={index}> <li key={index}>
<strong className="text-sm font-semibold"> <strong className="text-sm font-semibold">
{file.filePath} {file.filePath}
@@ -1,5 +1,5 @@
import { Bot, Eye, EyeOff, PlusCircle, Trash2 } from "lucide-react"; import { Bot, PlusCircle, Trash2 } from "lucide-react";
import { useEffect, useState } from "react"; import { useEffect } from "react";
import ReactMarkdown from "react-markdown"; import ReactMarkdown from "react-markdown";
import { toast } from "sonner"; import { toast } from "sonner";
import { AlertBlock } from "@/components/shared/alert-block"; import { AlertBlock } from "@/components/shared/alert-block";
@@ -27,7 +27,6 @@ export interface StepProps {
export const StepTwo = ({ templateInfo, setTemplateInfo }: StepProps) => { export const StepTwo = ({ templateInfo, setTemplateInfo }: StepProps) => {
const suggestions = templateInfo.suggestions || []; const suggestions = templateInfo.suggestions || [];
const selectedVariant = templateInfo.details; const selectedVariant = templateInfo.details;
const [showValues, setShowValues] = useState<Record<string, boolean>>({});
const { mutateAsync, isLoading, error, isError } = const { mutateAsync, isLoading, error, isError } =
api.ai.suggest.useMutation(); api.ai.suggest.useMutation();
@@ -44,7 +43,7 @@ export const StepTwo = ({ templateInfo, setTemplateInfo }: StepProps) => {
.then((data) => { .then((data) => {
setTemplateInfo({ setTemplateInfo({
...templateInfo, ...templateInfo,
suggestions: data, suggestions: data || [],
}); });
}) })
.catch((error) => { .catch((error) => {
@@ -54,10 +53,6 @@ export const StepTwo = ({ templateInfo, setTemplateInfo }: StepProps) => {
}); });
}, [templateInfo.userInput]); }, [templateInfo.userInput]);
const toggleShowValue = (name: string) => {
setShowValues((prev) => ({ ...prev, [name]: !prev[name] }));
};
const handleEnvVariableChange = ( const handleEnvVariableChange = (
index: number, index: number,
field: "name" | "value", field: "name" | "value",
@@ -308,11 +303,9 @@ export const StepTwo = ({ templateInfo, setTemplateInfo }: StepProps) => {
placeholder="Variable Name" placeholder="Variable Name"
className="flex-1" className="flex-1"
/> />
<div className="flex-1 relative"> <div className="relative">
<Input <Input
type={ type={"password"}
showValues[env.name] ? "text" : "password"
}
value={env.value} value={env.value}
onChange={(e) => onChange={(e) =>
handleEnvVariableChange( handleEnvVariableChange(
@@ -323,19 +316,6 @@ export const StepTwo = ({ templateInfo, setTemplateInfo }: StepProps) => {
} }
placeholder="Variable Value" placeholder="Variable Value"
/> />
<Button
type="button"
variant="ghost"
size="icon"
className="absolute right-2 top-1/2 transform -translate-y-1/2"
onClick={() => toggleShowValue(env.name)}
>
{showValues[env.name] ? (
<EyeOff className="h-4 w-4" />
) : (
<Eye className="h-4 w-4" />
)}
</Button>
</div> </div>
<Button <Button
type="button" type="button"
@@ -437,13 +417,14 @@ export const StepTwo = ({ templateInfo, setTemplateInfo }: StepProps) => {
<AccordionContent> <AccordionContent>
<ScrollArea className="w-full rounded-md border"> <ScrollArea className="w-full rounded-md border">
<div className="p-4 space-y-4"> <div className="p-4 space-y-4">
{selectedVariant?.configFiles?.length > 0 ? ( {selectedVariant?.configFiles?.length &&
selectedVariant?.configFiles?.length > 0 ? (
<> <>
<div className="text-sm text-muted-foreground mb-4"> <div className="text-sm text-muted-foreground mb-4">
This template requires the following This template requires the following
configuration files to be mounted: configuration files to be mounted:
</div> </div>
{selectedVariant.configFiles.map( {selectedVariant?.configFiles?.map(
(config, index) => ( (config, index) => (
<div <div
key={index} key={index}
@@ -47,7 +47,7 @@ interface Details {
envVariables: EnvVariable[]; envVariables: EnvVariable[];
shortDescription: string; shortDescription: string;
domains: Domain[]; domains: Domain[];
configFiles: Mount[]; configFiles?: Mount[];
} }
interface Mount { interface Mount {
@@ -81,6 +81,29 @@ export const DuplicateProject = ({
api.project.duplicate.useMutation({ api.project.duplicate.useMutation({
onSuccess: async (newProject) => { onSuccess: async (newProject) => {
await utils.project.all.invalidate(); await utils.project.all.invalidate();
// If duplicating to same project+environment, invalidate the environment query
// to refresh the services list
if (duplicateType === "existing-environment") {
await utils.environment.one.invalidate({
environmentId: selectedTargetEnvironment,
});
await utils.environment.byProjectId.invalidate({
projectId: selectedTargetProject,
});
// If duplicating to the same environment we're currently viewing,
// also invalidate the current environment to refresh the services list
if (selectedTargetEnvironment === environmentId) {
await utils.environment.one.invalidate({ environmentId });
// Also invalidate the project query to refresh the project data
const projectId = router.query.projectId as string;
if (projectId) {
await utils.project.one.invalidate({ projectId });
}
}
}
toast.success( toast.success(
duplicateType === "new-project" duplicateType === "new-project"
? "Project duplicated successfully" ? "Project duplicated successfully"
@@ -292,45 +292,48 @@ export const ShowProjects = () => {
)} )}
</DropdownMenuGroup> </DropdownMenuGroup>
)} )}
{/* {project.environments.some(
{project.compose.length > 0 && ( (env) => env.compose.length > 0,
) && (
<DropdownMenuGroup> <DropdownMenuGroup>
<DropdownMenuLabel> <DropdownMenuLabel>
Compose Compose
</DropdownMenuLabel> </DropdownMenuLabel>
{project.compose.map((comp) => ( {project.environments.map((env) =>
<div key={comp.composeId}> env.compose.map((comp) => (
<DropdownMenuSeparator /> <div key={comp.composeId}>
<DropdownMenuGroup>
<DropdownMenuLabel className="font-normal capitalize text-xs flex items-center justify-between">
{comp.name}
<StatusTooltip
status={comp.composeStatus}
/>
</DropdownMenuLabel>
<DropdownMenuSeparator /> <DropdownMenuSeparator />
{comp.domains.map((domain) => ( <DropdownMenuGroup>
<DropdownMenuItem <DropdownMenuLabel className="font-normal capitalize text-xs flex items-center justify-between">
key={domain.domainId} {comp.name}
asChild <StatusTooltip
> status={comp.composeStatus}
<Link />
className="space-x-4 text-xs cursor-pointer justify-between" </DropdownMenuLabel>
target="_blank" <DropdownMenuSeparator />
href={`${domain.https ? "https" : "http"}://${domain.host}${domain.path}`} {comp.domains.map((domain) => (
<DropdownMenuItem
key={domain.domainId}
asChild
> >
<span className="truncate"> <Link
{domain.host} className="space-x-4 text-xs cursor-pointer justify-between"
</span> target="_blank"
<ExternalLinkIcon className="size-4 shrink-0" /> href={`${domain.https ? "https" : "http"}://${domain.host}${domain.path}`}
</Link> >
</DropdownMenuItem> <span className="truncate">
))} {domain.host}
</DropdownMenuGroup> </span>
</div> <ExternalLinkIcon className="size-4 shrink-0" />
))} </Link>
</DropdownMenuItem>
))}
</DropdownMenuGroup>
</div>
)),
)}
</DropdownMenuGroup> </DropdownMenuGroup>
)} */} )}
</DropdownMenuContent> </DropdownMenuContent>
</DropdownMenu> </DropdownMenu>
) : null} ) : null}
@@ -30,6 +30,9 @@ const Schema = z.object({
name: z.string().min(1, { name: z.string().min(1, {
message: "Name is required", message: "Name is required",
}), }),
appName: z.string().min(1, {
message: "App Name is required",
}),
}); });
type Schema = z.infer<typeof Schema>; type Schema = z.infer<typeof Schema>;
@@ -55,6 +58,7 @@ export const EditGithubProvider = ({ githubId }: Props) => {
const form = useForm<Schema>({ const form = useForm<Schema>({
defaultValues: { defaultValues: {
name: "", name: "",
appName: "",
}, },
resolver: zodResolver(Schema), resolver: zodResolver(Schema),
}); });
@@ -62,6 +66,7 @@ export const EditGithubProvider = ({ githubId }: Props) => {
useEffect(() => { useEffect(() => {
form.reset({ form.reset({
name: github?.gitProvider.name || "", name: github?.gitProvider.name || "",
appName: github?.githubAppName || "",
}); });
}, [form, isOpen]); }, [form, isOpen]);
@@ -70,6 +75,7 @@ export const EditGithubProvider = ({ githubId }: Props) => {
githubId, githubId,
name: data.name || "", name: data.name || "",
gitProviderId: github?.gitProviderId || "", gitProviderId: github?.gitProviderId || "",
githubAppName: data.appName || "",
}) })
.then(async () => { .then(async () => {
await utils.gitProvider.getAll.invalidate(); await utils.gitProvider.getAll.invalidate();
@@ -124,6 +130,22 @@ export const EditGithubProvider = ({ githubId }: Props) => {
</FormItem> </FormItem>
)} )}
/> />
<FormField
control={form.control}
name="appName"
render={({ field }) => (
<FormItem>
<FormLabel>App Name</FormLabel>
<FormControl>
<Input
placeholder="pp Name eg(my-personal)"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<div className="flex w-full justify-between gap-4 mt-4"> <div className="flex w-full justify-between gap-4 mt-4">
<Button <Button
@@ -33,7 +33,10 @@ import { Disable2FA } from "./disable-2fa";
import { Enable2FA } from "./enable-2fa"; import { Enable2FA } from "./enable-2fa";
const profileSchema = z.object({ const profileSchema = z.object({
email: z.string(), email: z
.string()
.email("Please enter a valid email address")
.min(1, "Email is required"),
password: z.string().nullable(), password: z.string().nullable(),
currentPassword: z.string().nullable(), currentPassword: z.string().nullable(),
image: z.string().optional(), image: z.string().optional(),
+2 -3
View File
@@ -1,6 +1,6 @@
{ {
"name": "dokploy", "name": "dokploy",
"version": "v0.25.1", "version": "v0.25.2",
"private": true, "private": true,
"license": "Apache-2.0", "license": "Apache-2.0",
"type": "module", "type": "module",
@@ -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",
+3 -3
View File
@@ -7,7 +7,7 @@ import {
} from "@dokploy/server"; } from "@dokploy/server";
import { TRPCError } from "@trpc/server"; import { TRPCError } from "@trpc/server";
import { z } from "zod"; import { z } from "zod";
import { getPublicIpWithFallback } from "@/server/wss/terminal"; import { getLocalServerIp } from "@/server/wss/terminal";
import { createTRPCRouter, protectedProcedure } from "../trpc"; import { createTRPCRouter, protectedProcedure } from "../trpc";
export const clusterRouter = createTRPCRouter({ export const clusterRouter = createTRPCRouter({
getNodes: protectedProcedure getNodes: protectedProcedure
@@ -61,7 +61,7 @@ export const clusterRouter = createTRPCRouter({
const result = await docker.swarmInspect(); const result = await docker.swarmInspect();
const docker_version = await docker.version(); const docker_version = await docker.version();
let ip = await getPublicIpWithFallback(); let ip = await getLocalServerIp();
if (input.serverId) { if (input.serverId) {
const server = await findServerById(input.serverId); const server = await findServerById(input.serverId);
ip = server?.ipAddress; ip = server?.ipAddress;
@@ -85,7 +85,7 @@ export const clusterRouter = createTRPCRouter({
const result = await docker.swarmInspect(); const result = await docker.swarmInspect();
const docker_version = await docker.version(); const docker_version = await docker.version();
let ip = await getPublicIpWithFallback(); let ip = await getLocalServerIp();
if (input.serverId) { if (input.serverId) {
const server = await findServerById(input.serverId); const server = await findServerById(input.serverId);
ip = server?.ipAddress; ip = server?.ipAddress;
+2 -2
View File
@@ -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,
}); });
}), }),
@@ -3,6 +3,7 @@ import {
getGithubBranches, getGithubBranches,
getGithubRepositories, getGithubRepositories,
haveGithubRequirements, haveGithubRequirements,
updateGithub,
updateGitProvider, updateGitProvider,
} from "@dokploy/server"; } from "@dokploy/server";
import { TRPCError } from "@trpc/server"; import { TRPCError } from "@trpc/server";
@@ -134,5 +135,9 @@ export const githubRouter = createTRPCRouter({
name: input.name, name: input.name,
organizationId: ctx.session.activeOrganizationId, organizationId: ctx.session.activeOrganizationId,
}); });
await updateGithub(input.githubId, {
...input,
});
}), }),
}); });
+4 -4
View File
@@ -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 {
@@ -658,7 +658,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;
}; };
@@ -679,7 +679,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;
}; };
@@ -702,7 +702,7 @@ export const settingsRouter = createTRPCRouter({
currentConfig.accessLog = undefined; currentConfig.accessLog = undefined;
} }
writeMainConfig(dump(currentConfig)); writeMainConfig(stringify(currentConfig));
return true; return true;
}), }),
+10 -1
View File
@@ -192,7 +192,16 @@ export const userRouter = createTRPCRouter({
}) })
.where(eq(account.userId, ctx.user.id)); .where(eq(account.userId, ctx.user.id));
} }
return await updateUser(ctx.user.id, input);
try {
return await updateUser(ctx.user.id, input);
} catch (error) {
throw new TRPCError({
code: "BAD_REQUEST",
message:
error instanceof Error ? error.message : "Failed to update user",
});
}
}), }),
getUserByToken: publicProcedure getUserByToken: publicProcedure
.input(apiFindOneToken) .input(apiFindOneToken)
+21 -1
View File
@@ -1,5 +1,10 @@
import type http from "node:http"; import type http from "node:http";
import { findServerById, IS_CLOUD, validateRequest } from "@dokploy/server"; import {
execAsync,
findServerById,
IS_CLOUD,
validateRequest,
} from "@dokploy/server";
import { publicIpv4, publicIpv6 } from "public-ip"; import { publicIpv4, publicIpv6 } from "public-ip";
import { Client, type ConnectConfig } from "ssh2"; import { Client, type ConnectConfig } from "ssh2";
import { WebSocketServer } from "ws"; import { WebSocketServer } from "ws";
@@ -44,6 +49,21 @@ export const getPublicIpWithFallback = async () => {
return ip; return ip;
}; };
export const getLocalServerIp = async () => {
try {
const command = `ip addr show | grep -E "inet (192\.168\.|10\.|172\.1[6-9]\.|172\.2[0-9]\.|172\.3[0-1]\.)" | head -n1 | awk '{print $2}' | cut -d/ -f1`;
const { stdout } = await execAsync(command);
const ip = stdout.trim();
return (
ip ||
"We were unable to obtain the local server IP, please use your private IP address"
);
} catch (error) {
console.error("Error to obtain local server IP", error);
return "We were unable to obtain the local server IP, please use your private IP address";
}
};
export const setupTerminalWebSocketServer = ( export const setupTerminalWebSocketServer = (
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>, server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>,
) => { ) => {
+3
View File
@@ -1,3 +1,4 @@
import { exit } from "node:process";
import { execAsync } from "@dokploy/server"; import { execAsync } from "@dokploy/server";
import { setupDirectories } from "@dokploy/server/setup/config-paths"; import { setupDirectories } from "@dokploy/server/setup/config-paths";
import { initializePostgres } from "@dokploy/server/setup/postgres-setup"; import { initializePostgres } from "@dokploy/server/setup/postgres-setup";
@@ -25,6 +26,8 @@ import {
await initializeStandaloneTraefik(); await initializeStandaloneTraefik();
await initializeRedis(); await initializeRedis();
await initializePostgres(); await initializePostgres();
console.log("Dokploy setup completed");
exit(0);
} catch (e) { } catch (e) {
console.error("Error in dokploy setup", e); console.error("Error in dokploy setup", e);
} }
+2 -1
View File
@@ -11,7 +11,7 @@ import {
} from "./queue.js"; } from "./queue.js";
import { jobQueueSchema } from "./schema.js"; import { jobQueueSchema } from "./schema.js";
import { initializeJobs } from "./utils.js"; import { initializeJobs } from "./utils.js";
import { firstWorker, secondWorker } from "./workers.js"; import { firstWorker, secondWorker, thirdWorker } from "./workers.js";
const app = new Hono(); const app = new Hono();
@@ -91,6 +91,7 @@ export const gracefulShutdown = async (signal: string) => {
logger.warn(`Received ${signal}, closing server...`); logger.warn(`Received ${signal}, closing server...`);
await firstWorker.close(); await firstWorker.close();
await secondWorker.close(); await secondWorker.close();
await thirdWorker.close();
process.exit(0); process.exit(0);
}; };
+16 -4
View File
@@ -7,22 +7,34 @@ import { runJobs } from "./utils.js";
export const firstWorker = new Worker( export const firstWorker = new Worker(
"backupQueue", "backupQueue",
async (job: Job<QueueJob>) => { async (job: Job<QueueJob>) => {
logger.info({ data: job.data }, "Running job"); logger.info({ data: job.data }, "Running job first worker");
await runJobs(job.data); await runJobs(job.data);
}, },
{ {
concurrency: 50, concurrency: 100,
connection, connection,
}, },
); );
export const secondWorker = new Worker( export const secondWorker = new Worker(
"backupQueue", "backupQueue",
async (job: Job<QueueJob>) => { async (job: Job<QueueJob>) => {
logger.info({ data: job.data }, "Running job"); logger.info({ data: job.data }, "Running job second worker");
await runJobs(job.data); await runJobs(job.data);
}, },
{ {
concurrency: 50, concurrency: 100,
connection,
},
);
export const thirdWorker = new Worker(
"backupQueue",
async (job: Job<QueueJob>) => {
logger.info({ data: job.data }, "Running job third worker");
await runJobs(job.data);
},
{
concurrency: 100,
connection, connection,
}, },
); );
+1 -2
View File
@@ -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",
+1
View File
@@ -58,4 +58,5 @@ export const apiUpdateGithub = createSchema.extend({
githubId: z.string().min(1), githubId: z.string().min(1),
name: z.string().min(1), name: z.string().min(1),
gitProviderId: z.string().min(1), gitProviderId: z.string().min(1),
githubAppName: z.string().min(1),
}); });
+5
View File
@@ -322,6 +322,11 @@ export const apiUpdateWebServerMonitoring = z.object({
}); });
export const apiUpdateUser = createSchema.partial().extend({ export const apiUpdateUser = createSchema.partial().extend({
email: z
.string()
.email("Please enter a valid email address")
.min(1, "Email is required")
.optional(),
password: z.string().optional(), password: z.string().optional(),
currentPassword: z.string().optional(), currentPassword: z.string().optional(),
name: z.string().optional(), name: z.string().optional(),
+51 -20
View File
@@ -92,31 +92,48 @@ export const suggestVariants = async ({
const { object } = await generateObject({ const { object } = await generateObject({
model, model,
output: "array", output: "object",
schema: z.object({ schema: z.object({
id: z.string(), suggestions: z.array(
name: z.string(), z.object({
shortDescription: z.string(), id: z.string(),
description: z.string(), name: z.string(),
shortDescription: z.string(),
description: z.string(),
}),
),
}), }),
prompt: ` prompt: `
Act as advanced DevOps engineer and generate a list of open source projects what can cover users needs(up to 3 items), the suggestion Act as advanced DevOps engineer and generate a list of open source projects what can cover users needs(up to 3 items).
should include id, name, shortDescription, and description. Use slug of title for id.
Return your response as a JSON object with the following structure:
{
"suggestions": [
{
"id": "project-slug",
"name": "Project Name",
"shortDescription": "Brief one-line description",
"description": "Detailed description"
}
]
}
Important rules for the response: Important rules for the response:
1. The description field should ONLY contain a plain text description of the project, its features, and use cases 1. Use slug format for the id field (lowercase, hyphenated)
2. Do NOT include any code snippets, configuration examples, or installation instructions in the description 2. The description field should ONLY contain a plain text description of the project, its features, and use cases
3. The shortDescription should be a single-line summary focusing on the main technologies 3. Do NOT include any code snippets, configuration examples, or installation instructions in the description
4. The shortDescription should be a single-line summary focusing on the main technologies
5. All projects should be installable in docker and have docker compose support
User wants to create a new project with the following details, it should be installable in docker and can be docker compose generated for it: User wants to create a new project with the following details:
${input} ${input}
`, `,
}); });
if (object?.length) { if (object?.suggestions?.length) {
const result = []; const result = [];
for (const suggestion of object) { for (const suggestion of object.suggestions) {
try { try {
const { object: docker } = await generateObject({ const { object: docker } = await generateObject({
model, model,
@@ -136,16 +153,29 @@ export const suggestVariants = async ({
serviceName: z.string(), serviceName: z.string(),
}), }),
), ),
configFiles: z.array( configFiles: z
z.object({ .array(
content: z.string(), z.object({
filePath: z.string(), content: z.string(),
}), filePath: z.string(),
), }),
)
.optional(),
}), }),
prompt: ` prompt: `
Act as advanced DevOps engineer and generate docker compose with environment variables and domain configurations needed to install the following project. Act as advanced DevOps engineer and generate docker compose with environment variables and domain configurations needed to install the following project.
Return the docker compose as a YAML string and environment variables configuration. Follow these rules:
Return your response as a JSON object with this structure:
{
"dockerCompose": "yaml string here",
"envVariables": [{"name": "VAR_NAME", "value": "example_value"}],
"domains": [{"host": "domain.com", "port": 3000, "serviceName": "service"}],
"configFiles": [{"content": "file content", "filePath": "path/to/file"}]
}
Note: configFiles is optional - only include it if configuration files are absolutely required.
Follow these rules:
Docker Compose Rules: Docker Compose Rules:
1. Use placeholder like \${VARIABLE_NAME-default} for generated variables in the docker-compose.yml 1. Use placeholder like \${VARIABLE_NAME-default} for generated variables in the docker-compose.yml
@@ -198,6 +228,7 @@ export const suggestVariants = async ({
console.error("Error in docker compose generation:", error); console.error("Error in docker compose generation:", error);
} }
} }
return result; return result;
} }
+2 -2
View File
@@ -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) {
+26 -2
View File
@@ -10,6 +10,22 @@ import { IS_CLOUD } from "../constants";
export type Registry = typeof registry.$inferSelect; export type Registry = typeof registry.$inferSelect;
function shEscape(s: string | undefined): string {
if (!s) return "''";
return `'${s.replace(/'/g, `'\\''`)}'`;
}
function safeDockerLoginCommand(
registry: string | undefined,
user: string | undefined,
pass: string | undefined,
) {
const escapedRegistry = shEscape(registry);
const escapedUser = shEscape(user);
const escapedPassword = shEscape(pass);
return `printf %s ${escapedPassword} | docker login ${escapedRegistry} -u ${escapedUser} --password-stdin`;
}
export const createRegistry = async ( export const createRegistry = async (
input: typeof apiCreateRegistry._type, input: typeof apiCreateRegistry._type,
organizationId: string, organizationId: string,
@@ -37,7 +53,11 @@ export const createRegistry = async (
message: "Select a server to add the registry", message: "Select a server to add the registry",
}); });
} }
const loginCommand = `echo ${input.password} | docker login ${input.registryUrl} --username ${input.username} --password-stdin`; const loginCommand = safeDockerLoginCommand(
input.registryUrl,
input.username,
input.password,
);
if (input.serverId && input.serverId !== "none") { if (input.serverId && input.serverId !== "none") {
await execAsyncRemote(input.serverId, loginCommand); await execAsyncRemote(input.serverId, loginCommand);
} else if (newRegistry.registryType === "cloud") { } else if (newRegistry.registryType === "cloud") {
@@ -91,7 +111,11 @@ export const updateRegistry = async (
.returning() .returning()
.then((res) => res[0]); .then((res) => res[0]);
const loginCommand = `echo ${response?.password} | docker login ${response?.registryUrl} --username ${response?.username} --password-stdin`; const loginCommand = safeDockerLoginCommand(
response?.registryUrl,
response?.username,
response?.password,
);
if ( if (
IS_CLOUD && IS_CLOUD &&
+13
View File
@@ -296,6 +296,19 @@ export const findMemberById = async (
}; };
export const updateUser = async (userId: string, userData: Partial<User>) => { export const updateUser = async (userId: string, userData: Partial<User>) => {
// Validate email if it's being updated
if (userData.email !== undefined) {
if (!userData.email || userData.email.trim() === "") {
throw new Error("Email is required and cannot be empty");
}
// Basic email format validation
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(userData.email)) {
throw new Error("Please enter a valid email address");
}
}
const user = await db const user = await db
.update(users_temp) .update(users_temp)
.set({ .set({
+31 -11
View File
@@ -1,7 +1,14 @@
import { chmodSync, existsSync, mkdirSync, writeFileSync } from "node:fs"; import {
chmodSync,
existsSync,
mkdirSync,
rmSync,
statSync,
writeFileSync,
} 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";
@@ -234,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`),
@@ -308,7 +315,7 @@ export const getDefaultTraefikConfig = () => {
}), }),
}; };
const yamlStr = dump(configObject); const yamlStr = stringify(configObject);
return yamlStr; return yamlStr;
}; };
@@ -362,7 +369,7 @@ export const getDefaultServerTraefikConfig = () => {
}, },
}; };
const yamlStr = dump(configObject); const yamlStr = stringify(configObject);
return yamlStr; return yamlStr;
}; };
@@ -375,13 +382,26 @@ export const createDefaultTraefikConfig = () => {
if (existsSync(acmeJsonPath)) { if (existsSync(acmeJsonPath)) {
chmodSync(acmeJsonPath, "600"); chmodSync(acmeJsonPath, "600");
} }
if (existsSync(mainConfig)) {
console.log("Main config already exists"); // Create the traefik directory first
return;
}
const yamlStr = getDefaultTraefikConfig();
mkdirSync(MAIN_TRAEFIK_PATH, { recursive: true }); mkdirSync(MAIN_TRAEFIK_PATH, { recursive: true });
// Check if traefik.yml exists and handle the case where it might be a directory
if (existsSync(mainConfig)) {
const stats = statSync(mainConfig);
if (stats.isDirectory()) {
// If traefik.yml is a directory, remove it
console.log("Found traefik.yml as directory, removing it...");
rmSync(mainConfig, { recursive: true, force: true });
} else if (stats.isFile()) {
console.log("Main config already exists");
return;
}
}
const yamlStr = getDefaultTraefikConfig();
writeFileSync(mainConfig, yamlStr, "utf8"); writeFileSync(mainConfig, yamlStr, "utf8");
console.log("Traefik config created successfully");
}; };
export const getDefaultMiddlewares = () => { export const getDefaultMiddlewares = () => {
@@ -397,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 -1
View File
@@ -89,7 +89,7 @@ export const getMariadbBackupCommand = (
databaseUser: string, databaseUser: string,
databasePassword: string, databasePassword: string,
) => { ) => {
return `docker exec -i $CONTAINER_ID bash -c "set -o pipefail; mariadb-dump --user='${databaseUser}' --password='${databasePassword}' --databases ${database} | gzip"`; return `docker exec -i $CONTAINER_ID bash -c "set -o pipefail; mariadb-dump --user='${databaseUser}' --password='${databasePassword}' --single-transaction --quick --databases ${database} | gzip"`;
}; };
export const getMysqlBackupCommand = ( export const getMysqlBackupCommand = (
+2 -2
View File
@@ -220,8 +220,8 @@ const getImageName = (application: ApplicationNested) => {
if (registry) { if (registry) {
const { registryUrl, imagePrefix, username } = registry; const { registryUrl, imagePrefix, username } = registry;
const registryTag = imagePrefix const registryTag = imagePrefix
? `${registryUrl}/${imagePrefix}/${imageName}` ? `${registryUrl ? `${registryUrl}/` : ""}${imagePrefix}/${imageName}`
: `${registryUrl}/${username}/${imageName}`; : `${registryUrl ? `${registryUrl}/` : ""}${username}/${imageName}`;
return registryTag; return registryTag;
} }
+2 -2
View File
@@ -22,8 +22,8 @@ export const uploadImage = async (
// For ghcr.io: ghcr.io/username/image:tag // For ghcr.io: ghcr.io/username/image:tag
// For docker.io: docker.io/username/image:tag // For docker.io: docker.io/username/image:tag
const registryTag = imagePrefix const registryTag = imagePrefix
? `${registryUrl}/${imagePrefix}/${imageName}` ? `${registryUrl ? `${registryUrl}/` : ""}${imagePrefix}/${imageName}`
: `${registryUrl}/${username}/${imageName}`; : `${registryUrl ? `${registryUrl}/` : ""}${username}/${imageName}`;
try { try {
writeStream.write( writeStream.write(
@@ -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 = (
+3 -3
View File
@@ -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 = (
+15 -11
View File
@@ -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}";`;
} }
@@ -251,11 +251,15 @@ export const addDomainToCompose = async (
} }
labels.unshift(...httpLabels); labels.unshift(...httpLabels);
if (!compose.isolatedDeployment) { if (!compose.isolatedDeployment) {
if (!labels.includes("traefik.docker.network=dokploy-network")) { if (compose.composeType === "docker-compose") {
labels.unshift("traefik.docker.network=dokploy-network"); if (!labels.includes("traefik.docker.network=dokploy-network")) {
} labels.unshift("traefik.docker.network=dokploy-network");
if (!labels.includes("traefik.swarm.network=dokploy-network")) { }
labels.unshift("traefik.swarm.network=dokploy-network"); } else {
// Stack Case
if (!labels.includes("traefik.swarm.network=dokploy-network")) {
labels.unshift("traefik.swarm.network=dokploy-network");
}
} }
} }
} }
@@ -283,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");
@@ -171,7 +171,7 @@ export const cloneGithubRepository = async ({
const cloneUrl = `https://oauth2:${token}@${repoclone}`; const cloneUrl = `https://oauth2:${token}@${repoclone}`;
try { try {
writeStream.write(`\nClonning Repo ${repoclone} to ${outputPath}: ✅\n`); writeStream.write(`\nCloning Repo ${repoclone} to ${outputPath}: ✅\n`);
const cloneArgs = [ const cloneArgs = [
"clone", "clone",
"--branch", "--branch",
@@ -401,7 +401,7 @@ export const cloneRawGitlabRepositoryRemote = async (compose: Compose) => {
const { const {
appName, appName,
gitlabPathNamespace, gitlabPathNamespace,
branch, gitlabBranch,
gitlabId, gitlabId,
serverId, serverId,
enableSubmodules, enableSubmodules,
@@ -429,7 +429,7 @@ export const cloneRawGitlabRepositoryRemote = async (compose: Compose) => {
try { try {
const command = ` const command = `
rm -rf ${outputPath}; rm -rf ${outputPath};
git clone --branch ${branch} --depth 1 ${enableSubmodules ? "--recurse-submodules" : ""} ${cloneUrl} ${outputPath} git clone --branch ${gitlabBranch} --depth 1 ${enableSubmodules ? "--recurse-submodules" : ""} ${cloneUrl} ${outputPath}
`; `;
await execAsyncRemote(serverId, command); await execAsyncRemote(serverId, command);
} catch (error) { } catch (error) {
@@ -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;
@@ -1,3 +1,5 @@
import path from "node:path";
import { paths } from "@dokploy/server/constants";
import { import {
createDeploymentVolumeBackup, createDeploymentVolumeBackup,
updateDeploymentStatus, updateDeploymentStatus,
@@ -76,7 +78,20 @@ export const runVolumeBackup = async (volumeBackupId: string) => {
await updateDeploymentStatus(deployment.deploymentId, "done"); await updateDeploymentStatus(deployment.deploymentId, "done");
} catch (error) { } catch (error) {
const { VOLUME_BACKUPS_PATH } = paths(!!serverId);
const volumeBackupPath = path.join(
VOLUME_BACKUPS_PATH,
volumeBackup.appName,
);
// delete all the .tar files
const command = `rm -rf ${volumeBackupPath}/*.tar`;
if (serverId) {
await execAsyncRemote(serverId, command);
} else {
await execAsync(command);
}
await updateDeploymentStatus(deployment.deploymentId, "error"); await updateDeploymentStatus(deployment.deploymentId, "error");
console.error(error); console.error(error);
} }
}; };
+14 -18
View File
@@ -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([email protected]) version: 0.8.0([email protected])
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/[email protected]': '@types/[email protected]':
resolution: {integrity: sha512-wkw9yd1kEXOPnvEeEV1Go1MmxtBJL0RR79aOTAApecWFVu7w0NNXNqhcWgvw2YgZDYadliXkl14pa3WXw5jlCQ==} resolution: {integrity: sha512-wkw9yd1kEXOPnvEeEV1Go1MmxtBJL0RR79aOTAApecWFVu7w0NNXNqhcWgvw2YgZDYadliXkl14pa3WXw5jlCQ==}
'@types/[email protected]':
resolution: {integrity: sha512-k4MGaQl5TGo/iipqb2UDG2UwjXziSWkh0uysQelTlJpX1qGlpUZYm8PnO4DxG1qBomtJUdYJ6qR6xdIah10JLg==}
'@types/[email protected]': '@types/[email protected]':
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
[email protected]:
resolution: {integrity: sha512-lcYcMxX2PO9XMGvAJkJ3OsNMw+/7FKes7/hgerGUYWIoWu5j/+YQqcZr5JnPZWzOsEBgMbSbiSTn/dv/69Mkpw==}
engines: {node: '>= 14.6'}
hasBin: true
[email protected]: [email protected]:
resolution: {integrity: sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==} resolution: {integrity: sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==}
engines: {node: '>=6'} engines: {node: '>=6'}
@@ -11223,8 +11219,6 @@ snapshots:
'@types/[email protected]': {} '@types/[email protected]': {}
'@types/[email protected]': {}
'@types/[email protected]': '@types/[email protected]':
dependencies: dependencies:
'@types/ms': 2.1.0 '@types/ms': 2.1.0
@@ -14032,7 +14026,7 @@ snapshots:
[email protected]([email protected]): [email protected]([email protected]):
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:
[email protected]: {} [email protected]: {}
[email protected]: {}
[email protected]: [email protected]:
dependencies: dependencies:
camelcase: 5.3.1 camelcase: 5.3.1