diff --git a/README.md b/README.md index 8faf22a35..d60962cff 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,10 @@ For detailed documentation, visit [docs.dokploy.com](https://docs.dokploy.com).
Hostinger LX Aer + + + +
diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts index aa7358335..8ddb56dec 100644 --- a/apps/api/src/index.ts +++ b/apps/api/src/index.ts @@ -5,7 +5,11 @@ import { zValidator } from "@hono/zod-validator"; import { Inngest } from "inngest"; import { serve as serveInngest } from "inngest/hono"; import { logger } from "./logger.js"; -import { type DeployJob, deployJobSchema } from "./schema.js"; +import { + cancelDeploymentSchema, + type DeployJob, + deployJobSchema, +} from "./schema.js"; import { deploy } from "./utils.js"; const app = new Hono(); @@ -27,6 +31,13 @@ export const deploymentFunction = inngest.createFunction( }, ], retries: 0, + cancelOn: [ + { + event: "deployment/cancelled", + if: "async.data.applicationId == event.data.applicationId || async.data.composeId == event.data.composeId", + timeout: "1h", // Allow cancellation for up to 1 hour + }, + ], }, { event: "deployment/requested" }, @@ -119,6 +130,48 @@ app.post("/deploy", zValidator("json", deployJobSchema), async (c) => { } }); +app.post( + "/cancel-deployment", + zValidator("json", cancelDeploymentSchema), + async (c) => { + const data = c.req.valid("json"); + logger.info("Received cancel deployment request", data); + + try { + // Send cancellation event to Inngest + + await inngest.send({ + name: "deployment/cancelled", + data, + }); + + const identifier = + data.applicationType === "application" + ? `applicationId: ${data.applicationId}` + : `composeId: ${data.composeId}`; + + logger.info("Deployment cancellation event sent", { + ...data, + identifier, + }); + + return c.json({ + message: "Deployment cancellation requested", + applicationType: data.applicationType, + }); + } catch (error) { + logger.error("Failed to send deployment cancellation event", error); + return c.json( + { + message: "Failed to cancel deployment", + error: error instanceof Error ? error.message : String(error), + }, + 500, + ); + } + }, +); + app.get("/health", async (c) => { return c.json({ status: "ok" }); }); diff --git a/apps/api/src/schema.ts b/apps/api/src/schema.ts index 609289bf7..5a4355956 100644 --- a/apps/api/src/schema.ts +++ b/apps/api/src/schema.ts @@ -3,8 +3,8 @@ import { z } from "zod"; export const deployJobSchema = z.discriminatedUnion("applicationType", [ z.object({ applicationId: z.string(), - titleLog: z.string(), - descriptionLog: z.string(), + titleLog: z.string().optional(), + descriptionLog: z.string().optional(), server: z.boolean().optional(), type: z.enum(["deploy", "redeploy"]), applicationType: z.literal("application"), @@ -12,8 +12,8 @@ export const deployJobSchema = z.discriminatedUnion("applicationType", [ }), z.object({ composeId: z.string(), - titleLog: z.string(), - descriptionLog: z.string(), + titleLog: z.string().optional(), + descriptionLog: z.string().optional(), server: z.boolean().optional(), type: z.enum(["deploy", "redeploy"]), applicationType: z.literal("compose"), @@ -22,8 +22,8 @@ export const deployJobSchema = z.discriminatedUnion("applicationType", [ z.object({ applicationId: z.string(), previewDeploymentId: z.string(), - titleLog: z.string(), - descriptionLog: z.string(), + titleLog: z.string().optional(), + descriptionLog: z.string().optional(), server: z.boolean().optional(), type: z.enum(["deploy"]), applicationType: z.literal("application-preview"), @@ -32,3 +32,16 @@ export const deployJobSchema = z.discriminatedUnion("applicationType", [ ]); export type DeployJob = z.infer; + +export const cancelDeploymentSchema = z.discriminatedUnion("applicationType", [ + z.object({ + applicationId: z.string(), + applicationType: z.literal("application"), + }), + z.object({ + composeId: z.string(), + applicationType: z.literal("compose"), + }), +]); + +export type CancelDeploymentJob = z.infer; diff --git a/apps/api/src/utils.ts b/apps/api/src/utils.ts index ee3943d34..0d0b574fc 100644 --- a/apps/api/src/utils.ts +++ b/apps/api/src/utils.ts @@ -1,9 +1,9 @@ import { - deployRemoteApplication, - deployRemoteCompose, - deployRemotePreviewApplication, - rebuildRemoteApplication, - rebuildRemoteCompose, + deployApplication, + deployCompose, + deployPreviewApplication, + rebuildApplication, + rebuildCompose, updateApplicationStatus, updateCompose, updatePreviewDeployment, @@ -16,16 +16,16 @@ export const deploy = async (job: DeployJob) => { await updateApplicationStatus(job.applicationId, "running"); if (job.server) { if (job.type === "redeploy") { - await rebuildRemoteApplication({ + await rebuildApplication({ applicationId: job.applicationId, - titleLog: job.titleLog, - descriptionLog: job.descriptionLog, + titleLog: job.titleLog || "Rebuild deployment", + descriptionLog: job.descriptionLog || "", }); } else if (job.type === "deploy") { - await deployRemoteApplication({ + await deployApplication({ applicationId: job.applicationId, - titleLog: job.titleLog, - descriptionLog: job.descriptionLog, + titleLog: job.titleLog || "Manual deployment", + descriptionLog: job.descriptionLog || "", }); } } @@ -36,16 +36,16 @@ export const deploy = async (job: DeployJob) => { if (job.server) { if (job.type === "redeploy") { - await rebuildRemoteCompose({ + await rebuildCompose({ composeId: job.composeId, - titleLog: job.titleLog, - descriptionLog: job.descriptionLog, + titleLog: job.titleLog || "Rebuild deployment", + descriptionLog: job.descriptionLog || "", }); } else if (job.type === "deploy") { - await deployRemoteCompose({ + await deployCompose({ composeId: job.composeId, - titleLog: job.titleLog, - descriptionLog: job.descriptionLog, + titleLog: job.titleLog || "Manual deployment", + descriptionLog: job.descriptionLog || "", }); } } @@ -55,10 +55,10 @@ export const deploy = async (job: DeployJob) => { }); if (job.server) { if (job.type === "deploy") { - await deployRemotePreviewApplication({ + await deployPreviewApplication({ applicationId: job.applicationId, - titleLog: job.titleLog, - descriptionLog: job.descriptionLog, + titleLog: job.titleLog || "Preview Deployment", + descriptionLog: job.descriptionLog || "", previewDeploymentId: job.previewDeploymentId, }); } diff --git a/apps/dokploy/__test__/compose/compose.test.ts b/apps/dokploy/__test__/compose/compose.test.ts index 69d3a5212..b691537a1 100644 --- a/apps/dokploy/__test__/compose/compose.test.ts +++ b/apps/dokploy/__test__/compose/compose.test.ts @@ -1,7 +1,7 @@ import type { ComposeSpecification } from "@dokploy/server"; import { addSuffixToAllProperties } from "@dokploy/server"; -import { load } from "js-yaml"; import { expect, test } from "vitest"; +import { parse } from "yaml"; const composeFile1 = ` version: "3.8" @@ -61,7 +61,7 @@ secrets: file: ./db_password.txt `; -const expectedComposeFile1 = load(` +const expectedComposeFile1 = parse(` version: "3.8" services: @@ -120,7 +120,7 @@ secrets: `) as ComposeSpecification; 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 updatedComposeData = addSuffixToAllProperties(composeData, suffix); @@ -185,7 +185,7 @@ secrets: file: ./db_password.txt `; -const expectedComposeFile2 = load(` +const expectedComposeFile2 = parse(` version: "3.8" services: @@ -243,7 +243,7 @@ secrets: `) as ComposeSpecification; 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 updatedComposeData = addSuffixToAllProperties(composeData, suffix); @@ -308,7 +308,7 @@ secrets: file: ./service_secret.txt `; -const expectedComposeFile3 = load(` +const expectedComposeFile3 = parse(` version: "3.8" services: @@ -366,7 +366,7 @@ secrets: `) as ComposeSpecification; 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 updatedComposeData = addSuffixToAllProperties(composeData, suffix); @@ -420,7 +420,7 @@ volumes: driver: local `; -const expectedComposeFile = load(` +const expectedComposeFile = parse(` version: "3.8" services: @@ -467,7 +467,7 @@ volumes: `) as ComposeSpecification; 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 updatedComposeData = addSuffixToAllProperties(composeData, suffix); diff --git a/apps/dokploy/__test__/compose/config/config-root.test.ts b/apps/dokploy/__test__/compose/config/config-root.test.ts index 668e17902..a633bab53 100644 --- a/apps/dokploy/__test__/compose/config/config-root.test.ts +++ b/apps/dokploy/__test__/compose/config/config-root.test.ts @@ -1,7 +1,7 @@ import type { ComposeSpecification } from "@dokploy/server"; import { addSuffixToConfigsRoot, generateRandomHash } from "@dokploy/server"; -import { load } from "js-yaml"; import { expect, test } from "vitest"; +import { parse } from "yaml"; test("Generate random hash with 8 characters", () => { const hash = generateRandomHash(); @@ -23,7 +23,7 @@ configs: `; test("Add suffix to configs in root property", () => { - const composeData = load(composeFile) as ComposeSpecification; + const composeData = parse(composeFile) as ComposeSpecification; const suffix = generateRandomHash(); @@ -59,7 +59,7 @@ configs: `; test("Add suffix to multiple configs in root property", () => { - const composeData = load(composeFileMultipleConfigs) as ComposeSpecification; + const composeData = parse(composeFileMultipleConfigs) as ComposeSpecification; const suffix = generateRandomHash(); @@ -92,7 +92,7 @@ configs: `; test("Add suffix to configs with different properties in root property", () => { - const composeData = load( + const composeData = parse( composeFileDifferentProperties, ) as ComposeSpecification; @@ -137,7 +137,7 @@ configs: `; // Expected compose file con el prefijo `testhash` -const expectedComposeFileConfigRoot = load(` +const expectedComposeFileConfigRoot = parse(` version: "3.8" services: @@ -162,7 +162,7 @@ configs: `) as ComposeSpecification; test("Add suffix to configs in root property", () => { - const composeData = load(composeFileConfigRoot) as ComposeSpecification; + const composeData = parse(composeFileConfigRoot) as ComposeSpecification; const suffix = "testhash"; diff --git a/apps/dokploy/__test__/compose/config/config-service.test.ts b/apps/dokploy/__test__/compose/config/config-service.test.ts index 246872f09..08dd696e6 100644 --- a/apps/dokploy/__test__/compose/config/config-service.test.ts +++ b/apps/dokploy/__test__/compose/config/config-service.test.ts @@ -3,8 +3,8 @@ import { addSuffixToConfigsInServices, generateRandomHash, } from "@dokploy/server"; -import { load } from "js-yaml"; import { expect, test } from "vitest"; +import { parse } from "yaml"; const composeFile = ` version: "3.8" @@ -22,7 +22,7 @@ configs: `; test("Add suffix to configs in services", () => { - const composeData = load(composeFile) as ComposeSpecification; + const composeData = parse(composeFile) as ComposeSpecification; const suffix = generateRandomHash(); @@ -54,7 +54,7 @@ configs: `; test("Add suffix to configs in services with single config", () => { - const composeData = load( + const composeData = parse( composeFileSingleServiceConfig, ) as ComposeSpecification; @@ -108,7 +108,7 @@ configs: `; test("Add suffix to configs in services with multiple configs", () => { - const composeData = load( + const composeData = parse( composeFileMultipleServicesConfigs, ) as ComposeSpecification; @@ -157,7 +157,7 @@ services: `; // Expected compose file con el prefijo `testhash` -const expectedComposeFileConfigServices = load(` +const expectedComposeFileConfigServices = parse(` version: "3.8" services: @@ -182,7 +182,7 @@ services: `) as ComposeSpecification; test("Add suffix to configs in services", () => { - const composeData = load(composeFileConfigServices) as ComposeSpecification; + const composeData = parse(composeFileConfigServices) as ComposeSpecification; const suffix = "testhash"; diff --git a/apps/dokploy/__test__/compose/config/config.test.ts b/apps/dokploy/__test__/compose/config/config.test.ts index 2d5feeb9a..3a160431e 100644 --- a/apps/dokploy/__test__/compose/config/config.test.ts +++ b/apps/dokploy/__test__/compose/config/config.test.ts @@ -1,7 +1,7 @@ import type { ComposeSpecification } from "@dokploy/server"; import { addSuffixToAllConfigs, generateRandomHash } from "@dokploy/server"; -import { load } from "js-yaml"; import { expect, test } from "vitest"; +import { parse } from "yaml"; test("Generate random hash with 8 characters", () => { const hash = generateRandomHash(); @@ -43,7 +43,7 @@ configs: file: ./db-config.yml `; -const expectedComposeFileCombinedConfigs = load(` +const expectedComposeFileCombinedConfigs = parse(` version: "3.8" services: @@ -77,7 +77,7 @@ configs: `) as ComposeSpecification; 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"; @@ -122,7 +122,7 @@ configs: file: ./db-config.yml `; -const expectedComposeFileWithEnvAndExternal = load(` +const expectedComposeFileWithEnvAndExternal = parse(` version: "3.8" services: @@ -159,7 +159,7 @@ configs: `) as ComposeSpecification; test("Add suffix to configs with environment and external", () => { - const composeData = load( + const composeData = parse( composeFileWithEnvAndExternal, ) as ComposeSpecification; @@ -200,7 +200,7 @@ configs: file: ./db-config.yml `; -const expectedComposeFileWithTemplateDriverAndLabels = load(` +const expectedComposeFileWithTemplateDriverAndLabels = parse(` version: "3.8" services: @@ -231,7 +231,7 @@ configs: `) as ComposeSpecification; test("Add suffix to configs with template driver and labels", () => { - const composeData = load( + const composeData = parse( composeFileWithTemplateDriverAndLabels, ) as ComposeSpecification; diff --git a/apps/dokploy/__test__/compose/network/network-root.test.ts b/apps/dokploy/__test__/compose/network/network-root.test.ts index c55f6fa86..0d3c841d4 100644 --- a/apps/dokploy/__test__/compose/network/network-root.test.ts +++ b/apps/dokploy/__test__/compose/network/network-root.test.ts @@ -1,7 +1,7 @@ import type { ComposeSpecification } from "@dokploy/server"; import { addSuffixToNetworksRoot, generateRandomHash } from "@dokploy/server"; -import { load } from "js-yaml"; import { expect, test } from "vitest"; +import { parse } from "yaml"; const composeFile = ` version: "3.8" @@ -35,7 +35,7 @@ test("Generate random hash with 8 characters", () => { }); test("Add suffix to networks root property", () => { - const composeData = load(composeFile) as ComposeSpecification; + const composeData = parse(composeFile) as ComposeSpecification; const suffix = generateRandomHash(); @@ -79,7 +79,7 @@ networks: `; 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(); @@ -120,7 +120,7 @@ networks: `; test("Add suffix to networks with external properties", () => { - const composeData = load(composeFile3) as ComposeSpecification; + const composeData = parse(composeFile3) as ComposeSpecification; const suffix = generateRandomHash(); @@ -160,7 +160,7 @@ networks: `; test("Add suffix to networks with IPAM configurations", () => { - const composeData = load(composeFile4) as ComposeSpecification; + const composeData = parse(composeFile4) as ComposeSpecification; const suffix = generateRandomHash(); @@ -201,7 +201,7 @@ networks: `; test("Add suffix to networks with custom options", () => { - const composeData = load(composeFile5) as ComposeSpecification; + const composeData = parse(composeFile5) as ComposeSpecification; const suffix = generateRandomHash(); @@ -264,7 +264,7 @@ networks: `; test("Add suffix to networks with static suffix", () => { - const composeData = load(composeFile6) as ComposeSpecification; + const composeData = parse(composeFile6) as ComposeSpecification; const suffix = "testhash"; @@ -273,7 +273,7 @@ test("Add suffix to networks with static suffix", () => { } const networks = addSuffixToNetworksRoot(composeData.networks, suffix); - const expectedComposeData = load( + const expectedComposeData = parse( expectedComposeFile6, ) as ComposeSpecification; expect(networks).toStrictEqual(expectedComposeData.networks); @@ -293,7 +293,7 @@ networks: `; test("It shoudn't add suffix to dokploy-network", () => { - const composeData = load(composeFile7) as ComposeSpecification; + const composeData = parse(composeFile7) as ComposeSpecification; const suffix = generateRandomHash(); diff --git a/apps/dokploy/__test__/compose/network/network-service.test.ts b/apps/dokploy/__test__/compose/network/network-service.test.ts index 3cf46d4ab..e07fa1546 100644 --- a/apps/dokploy/__test__/compose/network/network-service.test.ts +++ b/apps/dokploy/__test__/compose/network/network-service.test.ts @@ -3,8 +3,8 @@ import { addSuffixToServiceNetworks, generateRandomHash, } from "@dokploy/server"; -import { load } from "js-yaml"; import { expect, test } from "vitest"; +import { parse } from "yaml"; const composeFile = ` version: "3.8" @@ -23,7 +23,7 @@ services: `; test("Add suffix to networks in services", () => { - const composeData = load(composeFile) as ComposeSpecification; + const composeData = parse(composeFile) as ComposeSpecification; const suffix = generateRandomHash(); @@ -67,7 +67,7 @@ networks: `; test("Add suffix to networks in services with aliases", () => { - const composeData = load(composeFile2) as ComposeSpecification; + const composeData = parse(composeFile2) as ComposeSpecification; const suffix = generateRandomHash(); @@ -107,7 +107,7 @@ 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(); @@ -153,7 +153,7 @@ networks: `; test("Add suffix to networks in services (combined case)", () => { - const composeData = load(composeFileCombined) as ComposeSpecification; + const composeData = parse(composeFileCombined) as ComposeSpecification; const suffix = generateRandomHash(); @@ -196,7 +196,7 @@ 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(); @@ -245,7 +245,7 @@ services: `; 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(); diff --git a/apps/dokploy/__test__/compose/network/network.test.ts b/apps/dokploy/__test__/compose/network/network.test.ts index 7ba1c6a83..c1900ed74 100644 --- a/apps/dokploy/__test__/compose/network/network.test.ts +++ b/apps/dokploy/__test__/compose/network/network.test.ts @@ -5,8 +5,8 @@ import { addSuffixToServiceNetworks, generateRandomHash, } from "@dokploy/server"; -import { load } from "js-yaml"; import { expect, test } from "vitest"; +import { parse } from "yaml"; const composeFileCombined = ` version: "3.8" @@ -39,7 +39,7 @@ networks: `; 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(); @@ -89,7 +89,7 @@ test("Add suffix to networks in services and root (combined case)", () => { expect(redisNetworks).not.toHaveProperty("backend"); }); -const expectedComposeFile = load(` +const expectedComposeFile = parse(` version: "3.8" services: @@ -120,7 +120,7 @@ networks: `); test("Add suffix to networks in compose file", () => { - const composeData = load(composeFileCombined) as ComposeSpecification; + const composeData = parse(composeFileCombined) as ComposeSpecification; const suffix = "testhash"; if (!composeData?.networks) { @@ -156,7 +156,7 @@ networks: driver: bridge `; -const expectedComposeFile2 = load(` +const expectedComposeFile2 = parse(` version: "3.8" services: @@ -182,7 +182,7 @@ 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 updatedComposeData = addSuffixToAllNetworks(composeData, suffix); @@ -218,7 +218,7 @@ networks: com.docker.network.bridge.enable_icc: "true" `; -const expectedComposeFile3 = load(` +const expectedComposeFile3 = parse(` version: "3.8" services: @@ -247,7 +247,7 @@ networks: `); 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 updatedComposeData = addSuffixToAllNetworks(composeData, suffix); @@ -289,7 +289,7 @@ networks: `; -const expectedComposeFile4 = load(` +const expectedComposeFile4 = parse(` version: "3.8" 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", () => { - const composeData = load(composeFile4) as ComposeSpecification; + const composeData = parse(composeFile4) as ComposeSpecification; const suffix = "testhash"; const updatedComposeData = addSuffixToAllNetworks(composeData, suffix); diff --git a/apps/dokploy/__test__/compose/secrets/secret-root.test.ts b/apps/dokploy/__test__/compose/secrets/secret-root.test.ts index b8cef56e4..ef74d64cf 100644 --- a/apps/dokploy/__test__/compose/secrets/secret-root.test.ts +++ b/apps/dokploy/__test__/compose/secrets/secret-root.test.ts @@ -1,7 +1,7 @@ import type { ComposeSpecification } from "@dokploy/server"; import { addSuffixToSecretsRoot, generateRandomHash } from "@dokploy/server"; -import { load } from "js-yaml"; import { expect, test } from "vitest"; +import { parse } from "yaml"; test("Generate random hash with 8 characters", () => { const hash = generateRandomHash(); @@ -23,7 +23,7 @@ secrets: `; test("Add suffix to secrets in root property", () => { - const composeData = load(composeFileSecretsRoot) as ComposeSpecification; + const composeData = parse(composeFileSecretsRoot) as ComposeSpecification; const suffix = generateRandomHash(); if (!composeData?.secrets) { @@ -52,7 +52,7 @@ secrets: `; 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(); if (!composeData?.secrets) { @@ -84,7 +84,7 @@ secrets: `; 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(); if (!composeData?.secrets) { diff --git a/apps/dokploy/__test__/compose/secrets/secret-services.test.ts b/apps/dokploy/__test__/compose/secrets/secret-services.test.ts index e12f611d0..a378bd606 100644 --- a/apps/dokploy/__test__/compose/secrets/secret-services.test.ts +++ b/apps/dokploy/__test__/compose/secrets/secret-services.test.ts @@ -3,8 +3,8 @@ import { addSuffixToSecretsInServices, generateRandomHash, } from "@dokploy/server"; -import { load } from "js-yaml"; import { expect, test } from "vitest"; +import { parse } from "yaml"; const composeFileSecretsServices = ` version: "3.8" @@ -21,7 +21,7 @@ secrets: `; test("Add suffix to secrets in services", () => { - const composeData = load(composeFileSecretsServices) as ComposeSpecification; + const composeData = parse(composeFileSecretsServices) as ComposeSpecification; const suffix = generateRandomHash(); if (!composeData.services) { @@ -54,7 +54,9 @@ secrets: `; test("Add suffix to secrets in services (Test 1)", () => { - const composeData = load(composeFileSecretsServices1) as ComposeSpecification; + const composeData = parse( + composeFileSecretsServices1, + ) as ComposeSpecification; const suffix = generateRandomHash(); if (!composeData.services) { @@ -93,7 +95,9 @@ secrets: `; test("Add suffix to secrets in services (Test 2)", () => { - const composeData = load(composeFileSecretsServices2) as ComposeSpecification; + const composeData = parse( + composeFileSecretsServices2, + ) as ComposeSpecification; const suffix = generateRandomHash(); if (!composeData.services) { diff --git a/apps/dokploy/__test__/compose/secrets/secret.test.ts b/apps/dokploy/__test__/compose/secrets/secret.test.ts index 3ff524ad7..3f6544bf1 100644 --- a/apps/dokploy/__test__/compose/secrets/secret.test.ts +++ b/apps/dokploy/__test__/compose/secrets/secret.test.ts @@ -1,7 +1,7 @@ import type { ComposeSpecification } from "@dokploy/server"; import { addSuffixToAllSecrets } from "@dokploy/server"; -import { load } from "js-yaml"; import { expect, test } from "vitest"; +import { parse } from "yaml"; const composeFileCombinedSecrets = ` version: "3.8" @@ -25,7 +25,7 @@ secrets: file: ./app_secret.txt `; -const expectedComposeFileCombinedSecrets = load(` +const expectedComposeFileCombinedSecrets = parse(` version: "3.8" services: @@ -48,7 +48,7 @@ secrets: `) as ComposeSpecification; test("Add suffix to all secrets", () => { - const composeData = load(composeFileCombinedSecrets) as ComposeSpecification; + const composeData = parse(composeFileCombinedSecrets) as ComposeSpecification; const suffix = "testhash"; const updatedComposeData = addSuffixToAllSecrets(composeData, suffix); @@ -77,7 +77,7 @@ secrets: file: ./cache_secret.txt `; -const expectedComposeFileCombinedSecrets3 = load(` +const expectedComposeFileCombinedSecrets3 = parse(` version: "3.8" services: @@ -99,7 +99,9 @@ secrets: `) as ComposeSpecification; test("Add suffix to all secrets (3rd Case)", () => { - const composeData = load(composeFileCombinedSecrets3) as ComposeSpecification; + const composeData = parse( + composeFileCombinedSecrets3, + ) as ComposeSpecification; const suffix = "testhash"; const updatedComposeData = addSuffixToAllSecrets(composeData, suffix); @@ -128,7 +130,7 @@ secrets: file: ./db_password.txt `; -const expectedComposeFileCombinedSecrets4 = load(` +const expectedComposeFileCombinedSecrets4 = parse(` version: "3.8" services: @@ -150,7 +152,9 @@ secrets: `) as ComposeSpecification; test("Add suffix to all secrets (4th Case)", () => { - const composeData = load(composeFileCombinedSecrets4) as ComposeSpecification; + const composeData = parse( + composeFileCombinedSecrets4, + ) as ComposeSpecification; const suffix = "testhash"; const updatedComposeData = addSuffixToAllSecrets(composeData, suffix); diff --git a/apps/dokploy/__test__/compose/service/service-container-name.test.ts b/apps/dokploy/__test__/compose/service/service-container-name.test.ts index 6ad45c588..d6521464d 100644 --- a/apps/dokploy/__test__/compose/service/service-container-name.test.ts +++ b/apps/dokploy/__test__/compose/service/service-container-name.test.ts @@ -1,7 +1,7 @@ import type { ComposeSpecification } from "@dokploy/server"; import { addSuffixToServiceNames, generateRandomHash } from "@dokploy/server"; -import { load } from "js-yaml"; import { expect, test } from "vitest"; +import { parse } from "yaml"; const composeFile = ` 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", () => { - const composeData = load(composeFile) as ComposeSpecification; + const composeData = parse(composeFile) as ComposeSpecification; const suffix = generateRandomHash(); diff --git a/apps/dokploy/__test__/compose/service/service-depends-on.test.ts b/apps/dokploy/__test__/compose/service/service-depends-on.test.ts index 14a5789c4..547c309d5 100644 --- a/apps/dokploy/__test__/compose/service/service-depends-on.test.ts +++ b/apps/dokploy/__test__/compose/service/service-depends-on.test.ts @@ -1,7 +1,7 @@ import type { ComposeSpecification } from "@dokploy/server"; import { addSuffixToServiceNames, generateRandomHash } from "@dokploy/server"; -import { load } from "js-yaml"; import { expect, test } from "vitest"; +import { parse } from "yaml"; test("Generate random hash with 8 characters", () => { const hash = generateRandomHash(); @@ -32,7 +32,7 @@ networks: `; 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(); @@ -102,7 +102,7 @@ networks: `; 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(); diff --git a/apps/dokploy/__test__/compose/service/service-extends.test.ts b/apps/dokploy/__test__/compose/service/service-extends.test.ts index 0b7e92c53..f539eeebd 100644 --- a/apps/dokploy/__test__/compose/service/service-extends.test.ts +++ b/apps/dokploy/__test__/compose/service/service-extends.test.ts @@ -1,7 +1,7 @@ import type { ComposeSpecification } from "@dokploy/server"; import { addSuffixToServiceNames, generateRandomHash } from "@dokploy/server"; -import { load } from "js-yaml"; import { expect, test } from "vitest"; +import { parse } from "yaml"; test("Generate random hash with 8 characters", () => { const hash = generateRandomHash(); @@ -30,7 +30,7 @@ networks: `; 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(); @@ -90,7 +90,7 @@ networks: `; 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(); diff --git a/apps/dokploy/__test__/compose/service/service-links.test.ts b/apps/dokploy/__test__/compose/service/service-links.test.ts index 6c8cde39e..4187edce8 100644 --- a/apps/dokploy/__test__/compose/service/service-links.test.ts +++ b/apps/dokploy/__test__/compose/service/service-links.test.ts @@ -1,7 +1,7 @@ import type { ComposeSpecification } from "@dokploy/server"; import { addSuffixToServiceNames, generateRandomHash } from "@dokploy/server"; -import { load } from "js-yaml"; import { expect, test } from "vitest"; +import { parse } from "yaml"; test("Generate random hash with 8 characters", () => { const hash = generateRandomHash(); @@ -31,7 +31,7 @@ networks: `; 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(); diff --git a/apps/dokploy/__test__/compose/service/service-names.test.ts b/apps/dokploy/__test__/compose/service/service-names.test.ts index c65299b03..c9c9d78c1 100644 --- a/apps/dokploy/__test__/compose/service/service-names.test.ts +++ b/apps/dokploy/__test__/compose/service/service-names.test.ts @@ -1,7 +1,7 @@ import type { ComposeSpecification } from "@dokploy/server"; import { addSuffixToServiceNames, generateRandomHash } from "@dokploy/server"; -import { load } from "js-yaml"; import { expect, test } from "vitest"; +import { parse } from "yaml"; test("Generate random hash with 8 characters", () => { const hash = generateRandomHash(); @@ -26,7 +26,7 @@ networks: `; test("Add suffix to service names in compose file", () => { - const composeData = load(composeFile) as ComposeSpecification; + const composeData = parse(composeFile) as ComposeSpecification; const suffix = generateRandomHash(); diff --git a/apps/dokploy/__test__/compose/service/service.test.ts b/apps/dokploy/__test__/compose/service/service.test.ts index 38895e073..a58e16722 100644 --- a/apps/dokploy/__test__/compose/service/service.test.ts +++ b/apps/dokploy/__test__/compose/service/service.test.ts @@ -3,8 +3,8 @@ import { addSuffixToAllServiceNames, addSuffixToServiceNames, } from "@dokploy/server"; -import { load } from "js-yaml"; import { expect, test } from "vitest"; +import { parse } from "yaml"; const composeFileCombinedAllCases = ` version: "3.8" @@ -38,7 +38,7 @@ networks: driver: bridge `; -const expectedComposeFile = load(` +const expectedComposeFile = parse(` version: "3.8" services: @@ -71,7 +71,9 @@ networks: `); 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"; @@ -131,7 +133,7 @@ networks: driver: bridge `; -const expectedComposeFile1 = load(` +const expectedComposeFile1 = parse(` version: "3.8" services: @@ -176,7 +178,7 @@ networks: `) as ComposeSpecification; 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 updatedComposeData = addSuffixToAllServiceNames(composeData, suffix); @@ -227,7 +229,7 @@ networks: driver: bridge `; -const expectedComposeFile2 = load(` +const expectedComposeFile2 = parse(` version: "3.8" services: @@ -271,7 +273,7 @@ networks: `) as ComposeSpecification; 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 updatedComposeData = addSuffixToAllServiceNames(composeData, suffix); @@ -322,7 +324,7 @@ networks: driver: bridge `; -const expectedComposeFile3 = load(` +const expectedComposeFile3 = parse(` version: "3.8" services: @@ -366,7 +368,7 @@ networks: `) as ComposeSpecification; 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 updatedComposeData = addSuffixToAllServiceNames(composeData, suffix); diff --git a/apps/dokploy/__test__/compose/service/sevice-volumes-from.test.ts b/apps/dokploy/__test__/compose/service/sevice-volumes-from.test.ts index 8aa8296e8..1de94b894 100644 --- a/apps/dokploy/__test__/compose/service/sevice-volumes-from.test.ts +++ b/apps/dokploy/__test__/compose/service/sevice-volumes-from.test.ts @@ -1,7 +1,7 @@ import type { ComposeSpecification } from "@dokploy/server"; import { addSuffixToServiceNames, generateRandomHash } from "@dokploy/server"; -import { load } from "js-yaml"; import { expect, test } from "vitest"; +import { parse } from "yaml"; test("Generate random hash with 8 characters", () => { const hash = generateRandomHash(); @@ -35,7 +35,7 @@ networks: `; 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(); diff --git a/apps/dokploy/__test__/compose/volume/volume-2.test.ts b/apps/dokploy/__test__/compose/volume/volume-2.test.ts index 6aa9d01d3..7ffbc4c1a 100644 --- a/apps/dokploy/__test__/compose/volume/volume-2.test.ts +++ b/apps/dokploy/__test__/compose/volume/volume-2.test.ts @@ -4,8 +4,8 @@ import { addSuffixToVolumesRoot, generateRandomHash, } from "@dokploy/server"; -import { load } from "js-yaml"; import { expect, test } from "vitest"; +import { parse } from "yaml"; const composeFile = ` services: @@ -70,7 +70,7 @@ volumes: driver: local `; -const expectedDockerCompose = load(` +const expectedDockerCompose = parse(` services: mail: 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 // 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", () => { - const composeData = load(composeFile) as ComposeSpecification; + const composeData = parse(composeFile) as ComposeSpecification; 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", () => { - const composeData = load(composeFile) as ComposeSpecification; + const composeData = parse(composeFile) as ComposeSpecification; const suffix = "testhash"; const updatedComposeData = addSuffixToAllVolumes(composeData, suffix); @@ -195,7 +195,7 @@ volumes: mongo-data: `; -const expectedDockerCompose2 = load(` +const expectedDockerCompose2 = parse(` version: '3.8' services: app: @@ -218,7 +218,7 @@ volumes: `) as ComposeSpecification; 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 updatedComposeData = addSuffixToAllVolumes(composeData, suffix); @@ -248,7 +248,7 @@ volumes: mongo-data: `; -const expectedDockerCompose3 = load(` +const expectedDockerCompose3 = parse(` version: '3.8' services: app: @@ -271,7 +271,7 @@ volumes: `) as ComposeSpecification; 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 updatedComposeData = addSuffixToAllVolumes(composeData, suffix); @@ -645,7 +645,7 @@ volumes: db-config: `; -const expectedDockerComposeComplex = load(` +const expectedDockerComposeComplex = parse(` version: "3.8" services: studio: @@ -1012,7 +1012,7 @@ volumes: `); 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 updatedComposeData = addSuffixToAllVolumes(composeData, suffix); @@ -1065,7 +1065,7 @@ volumes: db-data: `; -const expectedDockerComposeExample1 = load(` +const expectedDockerComposeExample1 = parse(` version: "3.8" services: web: @@ -1111,7 +1111,7 @@ volumes: `) as ComposeSpecification; 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 updatedComposeData = addSuffixToAllVolumes(composeData, suffix); @@ -1143,7 +1143,7 @@ volumes: backrest-cache: `; -const expectedDockerComposeBackrest = load(` +const expectedDockerComposeBackrest = parse(` services: backrest: image: garethgeorge/backrest:v1.7.3 @@ -1168,7 +1168,7 @@ volumes: `) as ComposeSpecification; test("Should handle volume paths with subdirectories correctly", () => { - const composeData = load(composeFileBackrest) as ComposeSpecification; + const composeData = parse(composeFileBackrest) as ComposeSpecification; const suffix = "testhash"; const updatedComposeData = addSuffixToAllVolumes(composeData, suffix); diff --git a/apps/dokploy/__test__/compose/volume/volume-root.test.ts b/apps/dokploy/__test__/compose/volume/volume-root.test.ts index 80db1f0cc..69afb7f99 100644 --- a/apps/dokploy/__test__/compose/volume/volume-root.test.ts +++ b/apps/dokploy/__test__/compose/volume/volume-root.test.ts @@ -1,7 +1,7 @@ import type { ComposeSpecification } from "@dokploy/server"; import { addSuffixToVolumesRoot, generateRandomHash } from "@dokploy/server"; -import { load } from "js-yaml"; import { expect, test } from "vitest"; +import { parse } from "yaml"; const composeFile = ` version: "3.8" @@ -29,7 +29,7 @@ test("Generate random hash with 8 characters", () => { }); test("Add suffix to volumes in root property", () => { - const composeData = load(composeFile) as ComposeSpecification; + const composeData = parse(composeFile) as ComposeSpecification; const suffix = generateRandomHash(); @@ -67,7 +67,7 @@ networks: `; 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(); @@ -101,7 +101,7 @@ networks: `; 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(); @@ -148,7 +148,7 @@ volumes: `; // Expected compose file con el prefijo `testhash` -const expectedComposeFile4 = load(` +const expectedComposeFile4 = parse(` version: "3.8" services: @@ -179,7 +179,7 @@ volumes: `) as ComposeSpecification; test("Add suffix to volumes in root property", () => { - const composeData = load(composeFile4) as ComposeSpecification; + const composeData = parse(composeFile4) as ComposeSpecification; const suffix = "testhash"; diff --git a/apps/dokploy/__test__/compose/volume/volume-services.test.ts b/apps/dokploy/__test__/compose/volume/volume-services.test.ts index 0e9cb018f..a42ab5fa9 100644 --- a/apps/dokploy/__test__/compose/volume/volume-services.test.ts +++ b/apps/dokploy/__test__/compose/volume/volume-services.test.ts @@ -3,8 +3,8 @@ import { addSuffixToVolumesInServices, generateRandomHash, } from "@dokploy/server"; -import { load } from "js-yaml"; import { expect, test } from "vitest"; +import { parse } from "yaml"; test("Generate random hash with 8 characters", () => { const hash = generateRandomHash(); @@ -24,7 +24,7 @@ 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(); @@ -59,7 +59,7 @@ volumes: `; 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(); diff --git a/apps/dokploy/__test__/compose/volume/volume.test.ts b/apps/dokploy/__test__/compose/volume/volume.test.ts index 6f8e76708..2ccd12da6 100644 --- a/apps/dokploy/__test__/compose/volume/volume.test.ts +++ b/apps/dokploy/__test__/compose/volume/volume.test.ts @@ -1,7 +1,7 @@ import type { ComposeSpecification } from "@dokploy/server"; import { addSuffixToAllVolumes } from "@dokploy/server"; -import { load } from "js-yaml"; import { expect, test } from "vitest"; +import { parse } from "yaml"; const composeFileTypeVolume = ` version: "3.8" @@ -23,7 +23,7 @@ volumes: driver: local `; -const expectedComposeFileTypeVolume = load(` +const expectedComposeFileTypeVolume = parse(` version: "3.8" services: @@ -44,7 +44,7 @@ volumes: `) as ComposeSpecification; 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"; @@ -73,7 +73,7 @@ volumes: driver: local `; -const expectedComposeFileTypeVolume1 = load(` +const expectedComposeFileTypeVolume1 = parse(` version: "3.8" services: @@ -93,7 +93,7 @@ volumes: `) as ComposeSpecification; test("Add suffix to mixed volumes in services", () => { - const composeData = load(composeFileTypeVolume1) as ComposeSpecification; + const composeData = parse(composeFileTypeVolume1) as ComposeSpecification; const suffix = "testhash"; @@ -128,7 +128,7 @@ volumes: device: /path/to/app/logs `; -const expectedComposeFileTypeVolume2 = load(` +const expectedComposeFileTypeVolume2 = parse(` version: "3.8" services: @@ -154,7 +154,7 @@ volumes: `) as ComposeSpecification; test("Add suffix to complex volume configurations in services", () => { - const composeData = load(composeFileTypeVolume2) as ComposeSpecification; + const composeData = parse(composeFileTypeVolume2) as ComposeSpecification; const suffix = "testhash"; @@ -218,7 +218,7 @@ volumes: device: /path/to/shared/logs `; -const expectedComposeFileTypeVolume3 = load(` +const expectedComposeFileTypeVolume3 = parse(` version: "3.8" services: @@ -273,7 +273,7 @@ volumes: `) as ComposeSpecification; 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"; diff --git a/apps/dokploy/__test__/drop/drop.test.ts b/apps/dokploy/__test__/drop/drop.test.ts index a9bc178a2..112a4b25e 100644 --- a/apps/dokploy/__test__/drop/drop.test.ts +++ b/apps/dokploy/__test__/drop/drop.test.ts @@ -42,12 +42,14 @@ const baseApp: ApplicationNested = { triggerType: "push", appName: "", autoDeploy: true, + endpointSpecSwarm: null, serverId: "", registryUrl: "", branch: null, dockerBuildStage: "", isPreviewDeploymentsActive: false, previewBuildArgs: null, + previewBuildSecrets: null, previewCertificateType: "none", previewCustomCertResolver: null, previewEnv: null, @@ -56,15 +58,24 @@ const baseApp: ApplicationNested = { previewPort: 3000, previewLimit: 0, previewWildcard: "", - project: { + environment: { env: "", - organizationId: "", + environmentId: "", name: "", - description: "", createdAt: "", + description: "", projectId: "", + project: { + env: "", + organizationId: "", + name: "", + description: "", + createdAt: "", + projectId: "", + }, }, buildArgs: null, + buildSecrets: null, buildPath: "/", gitlabPathNamespace: "", buildType: "nixpacks", @@ -92,6 +103,7 @@ const baseApp: ApplicationNested = { dockerfile: null, dockerImage: null, dropBuildPath: null, + environmentId: "", enabled: null, env: null, healthCheckSwarm: null, @@ -106,7 +118,6 @@ const baseApp: ApplicationNested = { password: null, placementSwarm: null, ports: [], - projectId: "", publishDirectory: null, isStaticSpa: null, redirects: [], @@ -125,6 +136,7 @@ const baseApp: ApplicationNested = { username: null, dockerContextPath: null, rollbackActive: false, + stopGracePeriodSwarm: null, }; describe("unzipDrop using real zip files", () => { diff --git a/apps/dokploy/__test__/env/environment.test.ts b/apps/dokploy/__test__/env/environment.test.ts new file mode 100644 index 000000000..95d46dcc0 --- /dev/null +++ b/apps/dokploy/__test__/env/environment.test.ts @@ -0,0 +1,335 @@ +import { prepareEnvironmentVariables } from "@dokploy/server/index"; +import { describe, expect, it } from "vitest"; + +const projectEnv = ` +ENVIRONMENT=staging +DATABASE_URL=postgres://postgres:postgres@localhost:5432/project_db +PORT=3000 +`; + +const environmentEnv = ` +NODE_ENV=development +API_URL=https://api.dev.example.com +REDIS_URL=redis://localhost:6379 +DATABASE_NAME=dev_database +SECRET_KEY=env-secret-123 +`; + +describe("prepareEnvironmentVariables (environment variables)", () => { + it("resolves environment variables correctly", () => { + const serviceWithEnvVars = ` +NODE_ENV=\${{environment.NODE_ENV}} +API_URL=\${{environment.API_URL}} +SERVICE_PORT=4000 +`; + + const resolved = prepareEnvironmentVariables( + serviceWithEnvVars, + "", + environmentEnv, + ); + + expect(resolved).toEqual([ + "NODE_ENV=development", + "API_URL=https://api.dev.example.com", + "SERVICE_PORT=4000", + ]); + }); + + it("resolves both project and environment variables", () => { + const serviceWithBoth = ` +ENVIRONMENT=\${{project.ENVIRONMENT}} +NODE_ENV=\${{environment.NODE_ENV}} +API_URL=\${{environment.API_URL}} +DATABASE_URL=\${{project.DATABASE_URL}} +SERVICE_PORT=4000 +`; + + const resolved = prepareEnvironmentVariables( + serviceWithBoth, + projectEnv, + environmentEnv, + ); + + expect(resolved).toEqual([ + "ENVIRONMENT=staging", + "NODE_ENV=development", + "API_URL=https://api.dev.example.com", + "DATABASE_URL=postgres://postgres:postgres@localhost:5432/project_db", + "SERVICE_PORT=4000", + ]); + }); + + it("handles undefined environment variables", () => { + const serviceWithUndefined = ` +UNDEFINED_VAR=\${{environment.UNDEFINED_VAR}} +`; + + expect(() => + prepareEnvironmentVariables(serviceWithUndefined, "", environmentEnv), + ).toThrow("Invalid environment variable: environment.UNDEFINED_VAR"); + }); + + it("allows service variables to override environment variables", () => { + const serviceOverrideEnv = ` +NODE_ENV=production +API_URL=\${{environment.API_URL}} +`; + + const resolved = prepareEnvironmentVariables( + serviceOverrideEnv, + "", + environmentEnv, + ); + + expect(resolved).toEqual([ + "NODE_ENV=production", // Overrides environment variable + "API_URL=https://api.dev.example.com", + ]); + }); + + it("resolves complex references with project, environment, and service variables", () => { + const complexServiceEnv = ` +FULL_DATABASE_URL=\${{project.DATABASE_URL}}/\${{environment.DATABASE_NAME}} +API_ENDPOINT=\${{environment.API_URL}}/\${{project.ENVIRONMENT}}/api +SERVICE_NAME=my-service +COMPLEX_VAR=\${{SERVICE_NAME}}-\${{environment.NODE_ENV}}-\${{project.ENVIRONMENT}} +`; + + const resolved = prepareEnvironmentVariables( + complexServiceEnv, + projectEnv, + environmentEnv, + ); + + expect(resolved).toEqual([ + "FULL_DATABASE_URL=postgres://postgres:postgres@localhost:5432/project_db/dev_database", + "API_ENDPOINT=https://api.dev.example.com/staging/api", + "SERVICE_NAME=my-service", + "COMPLEX_VAR=my-service-development-staging", + ]); + }); + + it("handles environment variables with special characters", () => { + const specialEnvVars = ` +SPECIAL_URL=https://special.com +COMPLEX_KEY="key-with-@#$%^&*()" +JWT_SECRET="secret-with-spaces and symbols!@#" +`; + + const serviceWithSpecial = ` +FULL_URL=\${{environment.SPECIAL_URL}}/path?key=\${{environment.COMPLEX_KEY}} +AUTH_SECRET=\${{environment.JWT_SECRET}} +`; + + const resolved = prepareEnvironmentVariables( + serviceWithSpecial, + "", + specialEnvVars, + ); + + expect(resolved).toEqual([ + "FULL_URL=https://special.com/path?key=key-with-@#$%^&*()", + "AUTH_SECRET=secret-with-spaces and symbols!@#", + ]); + }); + + it("maintains precedence: service > environment > project", () => { + const conflictingProjectEnv = ` +NODE_ENV=production-project +API_URL=https://project.api.com +DATABASE_NAME=project_db +`; + + const conflictingEnvironmentEnv = ` +NODE_ENV=development-environment +API_URL=https://environment.api.com +DATABASE_NAME=env_db +`; + + const serviceWithConflicts = ` +NODE_ENV=service-override +PROJECT_ENV=\${{project.NODE_ENV}} +ENV_VAR=\${{environment.API_URL}} +DB_NAME=\${{environment.DATABASE_NAME}} +`; + + const resolved = prepareEnvironmentVariables( + serviceWithConflicts, + conflictingProjectEnv, + conflictingEnvironmentEnv, + ); + + expect(resolved).toEqual([ + "NODE_ENV=service-override", // Service wins + "PROJECT_ENV=production-project", // Project reference + "ENV_VAR=https://environment.api.com", // Environment reference + "DB_NAME=env_db", // Environment reference + ]); + }); + + it("handles empty environment variables", () => { + const serviceWithEmpty = ` +SERVICE_VAR=test +PROJECT_VAR=\${{project.ENVIRONMENT}} +`; + + const resolved = prepareEnvironmentVariables( + serviceWithEmpty, + projectEnv, + "", + ); + + expect(resolved).toEqual(["SERVICE_VAR=test", "PROJECT_VAR=staging"]); + }); + + it("handles mixed quotes and environment variables", () => { + const envWithQuotes = ` +QUOTED_VAR="development" +SINGLE_QUOTED='https://api.dev.example.com' +MIXED_VAR="value with 'single' quotes" +`; + + const serviceWithQuotes = ` +NODE_ENV=\${{environment.QUOTED_VAR}} +API_URL=\${{environment.SINGLE_QUOTED}} +COMPLEX="Prefix-\${{environment.MIXED_VAR}}-Suffix" +`; + + const resolved = prepareEnvironmentVariables( + serviceWithQuotes, + "", + envWithQuotes, + ); + + expect(resolved).toEqual([ + "NODE_ENV=development", + "API_URL=https://api.dev.example.com", + "COMPLEX=Prefix-value with 'single' quotes-Suffix", + ]); + }); + + it("resolves multiple environment references in single value", () => { + const multiRefEnv = ` +HOST=localhost +PORT=5432 +USERNAME=postgres +PASSWORD=secret123 +`; + + const serviceWithMultiRefs = ` +DATABASE_URL=postgresql://\${{environment.USERNAME}}:\${{environment.PASSWORD}}@\${{environment.HOST}}:\${{environment.PORT}}/mydb +CONNECTION_STRING=\${{environment.HOST}}:\${{environment.PORT}} +`; + + const resolved = prepareEnvironmentVariables( + serviceWithMultiRefs, + "", + multiRefEnv, + ); + + expect(resolved).toEqual([ + "DATABASE_URL=postgresql://postgres:secret123@localhost:5432/mydb", + "CONNECTION_STRING=localhost:5432", + ]); + }); + + it("handles nested references with environment and project variables", () => { + const nestedProjectEnv = ` +BASE_DOMAIN=example.com +PROTOCOL=https +`; + + const nestedEnvironmentEnv = ` +SUBDOMAIN=api.dev +PATH_PREFIX=/v1 +`; + + const serviceWithNested = ` +FULL_URL=\${{project.PROTOCOL}}://\${{environment.SUBDOMAIN}}.\${{project.BASE_DOMAIN}}\${{environment.PATH_PREFIX}}/endpoint +API_BASE=\${{project.PROTOCOL}}://\${{environment.SUBDOMAIN}}.\${{project.BASE_DOMAIN}} +`; + + const resolved = prepareEnvironmentVariables( + serviceWithNested, + nestedProjectEnv, + nestedEnvironmentEnv, + ); + + expect(resolved).toEqual([ + "FULL_URL=https://api.dev.example.com/v1/endpoint", + "API_BASE=https://api.dev.example.com", + ]); + }); + + it("throws error for malformed environment variable references", () => { + const serviceWithMalformed = ` +MALFORMED1=\${{environment.}} +MALFORMED2=\${{environment}} +VALID=\${{environment.NODE_ENV}} +`; + + // Should throw error for empty variable name after environment. + expect(() => + prepareEnvironmentVariables(serviceWithMalformed, "", environmentEnv), + ).toThrow("Invalid environment variable: environment."); + }); + + it("handles environment variables with numeric values", () => { + const numericEnv = ` +PORT=8080 +TIMEOUT=30 +RETRY_COUNT=3 +PERCENTAGE=99.5 +`; + + const serviceWithNumeric = ` +SERVER_PORT=\${{environment.PORT}} +REQUEST_TIMEOUT=\${{environment.TIMEOUT}} +MAX_RETRIES=\${{environment.RETRY_COUNT}} +SUCCESS_RATE=\${{environment.PERCENTAGE}} +`; + + const resolved = prepareEnvironmentVariables( + serviceWithNumeric, + "", + numericEnv, + ); + + expect(resolved).toEqual([ + "SERVER_PORT=8080", + "REQUEST_TIMEOUT=30", + "MAX_RETRIES=3", + "SUCCESS_RATE=99.5", + ]); + }); + + it("handles boolean-like environment variables", () => { + const booleanEnv = ` +DEBUG=true +ENABLED=false +PRODUCTION=1 +DEVELOPMENT=0 +`; + + const serviceWithBoolean = ` +DEBUG_MODE=\${{environment.DEBUG}} +FEATURE_ENABLED=\${{environment.ENABLED}} +IS_PROD=\${{environment.PRODUCTION}} +IS_DEV=\${{environment.DEVELOPMENT}} +`; + + const resolved = prepareEnvironmentVariables( + serviceWithBoolean, + "", + booleanEnv, + ); + + expect(resolved).toEqual([ + "DEBUG_MODE=true", + "FEATURE_ENABLED=false", + "IS_PROD=1", + "IS_DEV=0", + ]); + }); +}); diff --git a/apps/dokploy/__test__/server/mechanizeDockerContainer.test.ts b/apps/dokploy/__test__/server/mechanizeDockerContainer.test.ts new file mode 100644 index 000000000..6eb5d1831 --- /dev/null +++ b/apps/dokploy/__test__/server/mechanizeDockerContainer.test.ts @@ -0,0 +1,102 @@ +import { beforeEach, describe, expect, it, vi } from "vitest"; + +import type { ApplicationNested } from "@dokploy/server/utils/builders"; +import { mechanizeDockerContainer } from "@dokploy/server/utils/builders"; + +type MockCreateServiceOptions = { + StopGracePeriod?: number; + [key: string]: unknown; +}; + +const { inspectMock, getServiceMock, createServiceMock, getRemoteDockerMock } = + vi.hoisted(() => { + const inspect = vi.fn<[], Promise>(); + const getService = vi.fn(() => ({ inspect })); + const createService = vi.fn<[MockCreateServiceOptions], Promise>( + async () => undefined, + ); + const getRemoteDocker = vi.fn(async () => ({ + getService, + createService, + })); + return { + inspectMock: inspect, + getServiceMock: getService, + createServiceMock: createService, + getRemoteDockerMock: getRemoteDocker, + }; + }); + +vi.mock("@dokploy/server/utils/servers/remote-docker", () => ({ + getRemoteDocker: getRemoteDockerMock, +})); + +const createApplication = ( + overrides: Partial = {}, +): ApplicationNested => + ({ + appName: "test-app", + buildType: "dockerfile", + env: null, + mounts: [], + cpuLimit: null, + memoryLimit: null, + memoryReservation: null, + cpuReservation: null, + command: null, + ports: [], + sourceType: "docker", + dockerImage: "example:latest", + registry: null, + environment: { + project: { env: null }, + env: null, + }, + replicas: 1, + stopGracePeriodSwarm: 0n, + serverId: "server-id", + ...overrides, + }) as unknown as ApplicationNested; + +describe("mechanizeDockerContainer", () => { + beforeEach(() => { + inspectMock.mockReset(); + inspectMock.mockRejectedValue(new Error("service not found")); + getServiceMock.mockClear(); + createServiceMock.mockClear(); + getRemoteDockerMock.mockClear(); + getRemoteDockerMock.mockResolvedValue({ + getService: getServiceMock, + createService: createServiceMock, + }); + }); + + it("converts bigint stopGracePeriodSwarm to a number and keeps zero values", async () => { + const application = createApplication({ stopGracePeriodSwarm: 0n }); + + await mechanizeDockerContainer(application); + + expect(createServiceMock).toHaveBeenCalledTimes(1); + const call = createServiceMock.mock.calls[0]; + if (!call) { + throw new Error("createServiceMock should have been called once"); + } + const [settings] = call; + expect(settings.StopGracePeriod).toBe(0); + expect(typeof settings.StopGracePeriod).toBe("number"); + }); + + it("omits StopGracePeriod when stopGracePeriodSwarm is null", async () => { + const application = createApplication({ stopGracePeriodSwarm: null }); + + await mechanizeDockerContainer(application); + + expect(createServiceMock).toHaveBeenCalledTimes(1); + const call = createServiceMock.mock.calls[0]; + if (!call) { + throw new Error("createServiceMock should have been called once"); + } + const [settings] = call; + expect(settings).not.toHaveProperty("StopGracePeriod"); + }); +}); diff --git a/apps/dokploy/__test__/templates/helpers.template.test.ts b/apps/dokploy/__test__/templates/helpers.template.test.ts index 1144b65fe..3ae92ae20 100644 --- a/apps/dokploy/__test__/templates/helpers.template.test.ts +++ b/apps/dokploy/__test__/templates/helpers.template.test.ts @@ -228,5 +228,58 @@ describe("helpers functions", () => { "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MzU2ODk2MDAsImV4cCI6MTczNTY5MzIwMCwiaXNzIjoidGVzdC1pc3N1ZXIiLCJjdXN0b21wcm9wIjoiY3VzdG9tdmFsdWUifQ.m42U7PZSUSCf7gBOJrxJir0rQmyPq4rA59Dydr_QahI", ); }); + + it("should handle JWT payload with newlines and whitespace by trimming them", () => { + const iat = Math.floor(new Date("2025-01-01T00:00:00Z").getTime() / 1000); + const expiry = iat + 3600; + const payloadWithNewlines = `{ + "role": "anon", + "iss": "supabase", + "exp": ${expiry} +} +`; + const jwt = processValue( + "${jwt:secret:payload}", + { + secret: "mysecret", + payload: payloadWithNewlines, + }, + mockSchema, + ); + expect(jwt).toMatch(jwtMatchExp); + const parts = jwt.split(".") as JWTParts; + jwtCheckHeader(parts[0]); + const decodedPayload = jwtBase64Decode(parts[1]); + expect(decodedPayload).toHaveProperty("role"); + expect(decodedPayload.role).toEqual("anon"); + expect(decodedPayload).toHaveProperty("iss"); + expect(decodedPayload.iss).toEqual("supabase"); + expect(decodedPayload).toHaveProperty("exp"); + expect(decodedPayload.exp).toEqual(expiry); + }); + + it("should handle JWT payload with leading and trailing whitespace", () => { + const iat = Math.floor(new Date("2025-01-01T00:00:00Z").getTime() / 1000); + const expiry = iat + 3600; + const payloadWithWhitespace = ` {"role": "service_role", "iss": "supabase", "exp": ${expiry}} `; + const jwt = processValue( + "${jwt:secret:payload}", + { + secret: "mysecret", + payload: payloadWithWhitespace, + }, + mockSchema, + ); + expect(jwt).toMatch(jwtMatchExp); + const parts = jwt.split(".") as JWTParts; + jwtCheckHeader(parts[0]); + const decodedPayload = jwtBase64Decode(parts[1]); + expect(decodedPayload).toHaveProperty("role"); + expect(decodedPayload.role).toEqual("service_role"); + expect(decodedPayload).toHaveProperty("iss"); + expect(decodedPayload.iss).toEqual("supabase"); + expect(decodedPayload).toHaveProperty("exp"); + expect(decodedPayload.exp).toEqual(expiry); + }); }); }); diff --git a/apps/dokploy/__test__/traefik/traefik.test.ts b/apps/dokploy/__test__/traefik/traefik.test.ts index ff8a99620..5b48b1248 100644 --- a/apps/dokploy/__test__/traefik/traefik.test.ts +++ b/apps/dokploy/__test__/traefik/traefik.test.ts @@ -15,6 +15,7 @@ const baseApp: ApplicationNested = { giteaId: "", cleanCache: false, applicationStatus: "done", + endpointSpecSwarm: null, appName: "", autoDeploy: true, enableSubmodules: false, @@ -25,8 +26,10 @@ const baseApp: ApplicationNested = { registryUrl: "", watchPaths: [], buildArgs: null, + buildSecrets: null, isPreviewDeploymentsActive: false, previewBuildArgs: null, + previewBuildSecrets: null, triggerType: "push", previewCertificateType: "none", previewEnv: null, @@ -36,13 +39,22 @@ const baseApp: ApplicationNested = { previewLimit: 0, previewCustomCertResolver: null, previewWildcard: "", - project: { + environmentId: "", + environment: { env: "", - organizationId: "", + environmentId: "", name: "", - description: "", createdAt: "", + description: "", projectId: "", + project: { + env: "", + organizationId: "", + name: "", + description: "", + createdAt: "", + projectId: "", + }, }, buildPath: "/", gitlabPathNamespace: "", @@ -85,7 +97,6 @@ const baseApp: ApplicationNested = { password: null, placementSwarm: null, ports: [], - projectId: "", publishDirectory: null, isStaticSpa: null, redirects: [], @@ -103,6 +114,7 @@ const baseApp: ApplicationNested = { updateConfigSwarm: null, username: null, dockerContextPath: null, + stopGracePeriodSwarm: null, }; const baseDomain: Domain = { diff --git a/apps/dokploy/components/dashboard/application/advanced/cluster/modify-swarm-settings.tsx b/apps/dokploy/components/dashboard/application/advanced/cluster/modify-swarm-settings.tsx index 9e10f43ec..739bd87a5 100644 --- a/apps/dokploy/components/dashboard/application/advanced/cluster/modify-swarm-settings.tsx +++ b/apps/dokploy/components/dashboard/application/advanced/cluster/modify-swarm-settings.tsx @@ -25,6 +25,7 @@ import { FormLabel, FormMessage, } from "@/components/ui/form"; +import { Input } from "@/components/ui/input"; import { Tooltip, TooltipContent, @@ -121,6 +122,22 @@ const NetworkSwarmSchema = z.array( const LabelsSwarmSchema = z.record(z.string()); +const EndpointPortConfigSwarmSchema = z + .object({ + Protocol: z.string().optional(), + TargetPort: z.number().optional(), + PublishedPort: z.number().optional(), + PublishMode: z.string().optional(), + }) + .strict(); + +const EndpointSpecSwarmSchema = z + .object({ + Mode: z.string().optional(), + Ports: z.array(EndpointPortConfigSwarmSchema).optional(), + }) + .strict(); + const createStringToJSONSchema = (schema: z.ZodTypeAny) => { return z .string() @@ -176,10 +193,21 @@ const addSwarmSettings = z.object({ modeSwarm: createStringToJSONSchema(ServiceModeSwarmSchema).nullable(), labelsSwarm: createStringToJSONSchema(LabelsSwarmSchema).nullable(), networkSwarm: createStringToJSONSchema(NetworkSwarmSchema).nullable(), + stopGracePeriodSwarm: z.bigint().nullable(), + endpointSpecSwarm: createStringToJSONSchema( + EndpointSpecSwarmSchema, + ).nullable(), }); type AddSwarmSettings = z.infer; +const hasStopGracePeriodSwarm = ( + value: unknown, +): value is { stopGracePeriodSwarm: bigint | number | string | null } => + typeof value === "object" && + value !== null && + "stopGracePeriodSwarm" in value; + interface Props { id: string; type: "postgres" | "mariadb" | "mongo" | "mysql" | "redis" | "application"; @@ -224,12 +252,23 @@ export const AddSwarmSettings = ({ id, type }: Props) => { modeSwarm: null, labelsSwarm: null, networkSwarm: null, + stopGracePeriodSwarm: null, + endpointSpecSwarm: null, }, resolver: zodResolver(addSwarmSettings), }); useEffect(() => { if (data) { + const stopGracePeriodValue = hasStopGracePeriodSwarm(data) + ? data.stopGracePeriodSwarm + : null; + const normalizedStopGracePeriod = + stopGracePeriodValue === null || stopGracePeriodValue === undefined + ? null + : typeof stopGracePeriodValue === "bigint" + ? stopGracePeriodValue + : BigInt(stopGracePeriodValue); form.reset({ healthCheckSwarm: data.healthCheckSwarm ? JSON.stringify(data.healthCheckSwarm, null, 2) @@ -255,6 +294,10 @@ export const AddSwarmSettings = ({ id, type }: Props) => { networkSwarm: data.networkSwarm ? JSON.stringify(data.networkSwarm, null, 2) : null, + stopGracePeriodSwarm: normalizedStopGracePeriod, + endpointSpecSwarm: data.endpointSpecSwarm + ? JSON.stringify(data.endpointSpecSwarm, null, 2) + : null, }); } }, [form, form.reset, data]); @@ -275,6 +318,8 @@ export const AddSwarmSettings = ({ id, type }: Props) => { modeSwarm: data.modeSwarm, labelsSwarm: data.labelsSwarm, networkSwarm: data.networkSwarm, + stopGracePeriodSwarm: data.stopGracePeriodSwarm ?? null, + endpointSpecSwarm: data.endpointSpecSwarm, }) .then(async () => { toast.success("Swarm settings updated"); @@ -352,9 +397,9 @@ export const AddSwarmSettings = ({ id, type }: Props) => { language="json" placeholder={`{ "Test" : ["CMD-SHELL", "curl -f http://localhost:3000/health"], - "Interval" : 10000, - "Timeout" : 10000, - "StartPeriod" : 10000, + "Interval" : 10000000000, + "Timeout" : 10000000000, + "StartPeriod" : 10000000000, "Retries" : 10 }`} className="h-[12rem] font-mono" @@ -407,9 +452,9 @@ export const AddSwarmSettings = ({ id, type }: Props) => { language="json" placeholder={`{ "Condition" : "on-failure", - "Delay" : 10000, + "Delay" : 10000000000, "MaxAttempts" : 10, - "Window" : 10000 + "Window" : 10000000000 } `} className="h-[12rem] font-mono" {...field} @@ -529,9 +574,9 @@ export const AddSwarmSettings = ({ id, type }: Props) => { language="json" placeholder={`{ "Parallelism" : 1, - "Delay" : 10000, + "Delay" : 10000000000, "FailureAction" : "continue", - "Monitor" : 10000, + "Monitor" : 10000000000, "MaxFailureRatio" : 10, "Order" : "start-first" }`} @@ -587,9 +632,9 @@ export const AddSwarmSettings = ({ id, type }: Props) => { language="json" placeholder={`{ "Parallelism" : 1, - "Delay" : 10000, + "Delay" : 10000000000, "FailureAction" : "continue", - "Monitor" : 10000, + "Monitor" : 10000000000, "MaxFailureRatio" : 10, "Order" : "start-first" }`} @@ -774,7 +819,118 @@ export const AddSwarmSettings = ({ id, type }: Props) => { )} /> + ( + + Stop Grace Period (nanoseconds) + + + + + Duration in nanoseconds + + + + + +
+														{`Enter duration in nanoseconds:
+														• 30000000000 - 30 seconds
+														• 120000000000 - 2 minutes  
+														• 3600000000000 - 1 hour
+														• 0 - no grace period`}
+													
+
+
+
+
+ + + field.onChange( + e.target.value ? BigInt(e.target.value) : null, + ) + } + /> + +
+										
+									
+
+ )} + /> + ( + + Endpoint Spec + + + + + Check the interface + + + + + +
+														{`{
+	Mode?: string | undefined;
+	Ports?: Array<{
+		Protocol?: string | undefined;
+		TargetPort?: number | undefined;
+		PublishedPort?: number | undefined;
+		PublishMode?: string | undefined;
+	}> | undefined;
+}`}
+													
+
+
+
+
+ + + +
+										
+									
+
+ )} + /> + {serverId && (
{ + if (!isCloud || !deployments || deployments.length === 0) return null; + + const now = Date.now(); + const NINE_MINUTES = 10 * 60 * 1000; // 9 minutes in milliseconds + + // Get the most recent deployment (first in the list since they're sorted by date) + const mostRecentDeployment = deployments[0]; + + if ( + !mostRecentDeployment || + mostRecentDeployment.status !== "running" || + !mostRecentDeployment.startedAt + ) { + return null; + } + + const startTime = new Date(mostRecentDeployment.startedAt).getTime(); + const elapsed = now - startTime; + + return elapsed > NINE_MINUTES ? mostRecentDeployment : null; + }, [isCloud, deployments]); useEffect(() => { setUrl(document.location.origin); }, []); @@ -94,6 +131,54 @@ export const ShowDeployments = ({
+ {stuckDeployment && (type === "application" || type === "compose") && ( + +
+
+
+ Build appears to be stuck +
+

+ Hey! Looks like the build has been running for more than 10 + minutes. Would you like to cancel this deployment? +

+
+ +
+
+ )} {refreshToken && (
diff --git a/apps/dokploy/components/dashboard/application/environment/show-enviroment.tsx b/apps/dokploy/components/dashboard/application/environment/show-enviroment.tsx index 4a5d0270b..797a317a8 100644 --- a/apps/dokploy/components/dashboard/application/environment/show-enviroment.tsx +++ b/apps/dokploy/components/dashboard/application/environment/show-enviroment.tsx @@ -108,6 +108,21 @@ export const ShowEnvironment = ({ id, type }: Props) => { }); }; + // Add keyboard shortcut for Ctrl+S/Cmd+S + useEffect(() => { + const handleKeyDown = (e: KeyboardEvent) => { + if ((e.ctrlKey || e.metaKey) && e.key === "s" && !isLoading) { + e.preventDefault(); + form.handleSubmit(onSubmit)(); + } + }; + + document.addEventListener("keydown", handleKeyDown); + return () => { + document.removeEventListener("keydown", handleKeyDown); + }; + }, [form, onSubmit, isLoading]); + return (
diff --git a/apps/dokploy/components/dashboard/application/environment/show.tsx b/apps/dokploy/components/dashboard/application/environment/show.tsx index 78edb1aaa..48e978880 100644 --- a/apps/dokploy/components/dashboard/application/environment/show.tsx +++ b/apps/dokploy/components/dashboard/application/environment/show.tsx @@ -12,6 +12,7 @@ import { api } from "@/utils/api"; const addEnvironmentSchema = z.object({ env: z.string(), buildArgs: z.string(), + buildSecrets: z.string(), }); type EnvironmentSchema = z.infer; @@ -37,6 +38,7 @@ export const ShowEnvironment = ({ applicationId }: Props) => { defaultValues: { env: "", buildArgs: "", + buildSecrets: "", }, resolver: zodResolver(addEnvironmentSchema), }); @@ -44,15 +46,18 @@ export const ShowEnvironment = ({ applicationId }: Props) => { // Watch form values const currentEnv = form.watch("env"); const currentBuildArgs = form.watch("buildArgs"); + const currentBuildSecrets = form.watch("buildSecrets"); const hasChanges = currentEnv !== (data?.env || "") || - currentBuildArgs !== (data?.buildArgs || ""); + currentBuildArgs !== (data?.buildArgs || "") || + currentBuildSecrets !== (data?.buildSecrets || ""); useEffect(() => { if (data) { form.reset({ env: data.env || "", buildArgs: data.buildArgs || "", + buildSecrets: data.buildSecrets || "", }); } }, [data, form]); @@ -61,6 +66,7 @@ export const ShowEnvironment = ({ applicationId }: Props) => { mutateAsync({ env: formData.env, buildArgs: formData.buildArgs, + buildSecrets: formData.buildSecrets, applicationId, }) .then(async () => { @@ -76,9 +82,25 @@ export const ShowEnvironment = ({ applicationId }: Props) => { form.reset({ env: data?.env || "", buildArgs: data?.buildArgs || "", + buildSecrets: data?.buildSecrets || "", }); }; + // Add keyboard shortcut for Ctrl+S/Cmd+S + useEffect(() => { + const handleKeyDown = (e: KeyboardEvent) => { + if ((e.ctrlKey || e.metaKey) && e.key === "s" && !isLoading) { + e.preventDefault(); + form.handleSubmit(onSubmit)(); + } + }; + + document.addEventListener("keydown", handleKeyDown); + return () => { + document.removeEventListener("keydown", handleKeyDown); + }; + }, [form, onSubmit, isLoading]); + return (
@@ -104,13 +126,36 @@ export const ShowEnvironment = ({ applicationId }: Props) => { {data?.buildType === "dockerfile" && ( - Available only at build-time. See documentation  + Arguments are available only at build-time. See + documentation  + here + + . + + } + placeholder="NPM_TOKEN=xyz" + /> + )} + {data?.buildType === "dockerfile" && ( + + Secrets are specially designed for sensitive information and + are only available at build-time. See documentation  + diff --git a/apps/dokploy/components/dashboard/application/general/generic/save-bitbucket-provider.tsx b/apps/dokploy/components/dashboard/application/general/generic/save-bitbucket-provider.tsx index 6f6db5dd1..1f54ddd58 100644 --- a/apps/dokploy/components/dashboard/application/general/generic/save-bitbucket-provider.tsx +++ b/apps/dokploy/components/dashboard/application/general/generic/save-bitbucket-provider.tsx @@ -150,7 +150,7 @@ export const SaveBitbucketProvider = ({ applicationId }: Props) => { enableSubmodules: data.enableSubmodules || false, }) .then(async () => { - toast.success("Service Provided Saved"); + toast.success("Service Provider Saved"); await refetch(); }) .catch(() => { diff --git a/apps/dokploy/components/dashboard/application/general/generic/save-git-provider.tsx b/apps/dokploy/components/dashboard/application/general/generic/save-git-provider.tsx index 61690e740..e9be3a2f5 100644 --- a/apps/dokploy/components/dashboard/application/general/generic/save-git-provider.tsx +++ b/apps/dokploy/components/dashboard/application/general/generic/save-git-provider.tsx @@ -59,7 +59,7 @@ export const SaveGitProvider = ({ applicationId }: Props) => { const router = useRouter(); const { mutateAsync, isLoading } = - api.application.saveGitProdiver.useMutation(); + api.application.saveGitProvider.useMutation(); const form = useForm({ defaultValues: { diff --git a/apps/dokploy/components/dashboard/application/general/generic/save-github-provider.tsx b/apps/dokploy/components/dashboard/application/general/generic/save-github-provider.tsx index 9a4b92ce1..80d6850ca 100644 --- a/apps/dokploy/components/dashboard/application/general/generic/save-github-provider.tsx +++ b/apps/dokploy/components/dashboard/application/general/generic/save-github-provider.tsx @@ -149,7 +149,7 @@ export const SaveGithubProvider = ({ applicationId }: Props) => { enableSubmodules: data.enableSubmodules, }) .then(async () => { - toast.success("Service Provided Saved"); + toast.success("Service Provider Saved"); await refetch(); }) .catch(() => { diff --git a/apps/dokploy/components/dashboard/application/general/generic/save-gitlab-provider.tsx b/apps/dokploy/components/dashboard/application/general/generic/save-gitlab-provider.tsx index cb7209f8a..d6f65caf3 100644 --- a/apps/dokploy/components/dashboard/application/general/generic/save-gitlab-provider.tsx +++ b/apps/dokploy/components/dashboard/application/general/generic/save-gitlab-provider.tsx @@ -167,7 +167,7 @@ export const SaveGitlabProvider = ({ applicationId }: Props) => { enableSubmodules: data.enableSubmodules, }) .then(async () => { - toast.success("Service Provided Saved"); + toast.success("Service Provider Saved"); await refetch(); }) .catch(() => { diff --git a/apps/dokploy/components/dashboard/application/general/show.tsx b/apps/dokploy/components/dashboard/application/general/show.tsx index a8fef349b..5387659ad 100644 --- a/apps/dokploy/components/dashboard/application/general/show.tsx +++ b/apps/dokploy/components/dashboard/application/general/show.tsx @@ -69,7 +69,7 @@ export const ShowGeneralApplication = ({ applicationId }: Props) => { toast.success("Application deployed successfully"); refetch(); router.push( - `/dashboard/project/${data?.projectId}/services/application/${applicationId}?tab=deployments`, + `/dashboard/project/${data?.environment.projectId}/environment/${data?.environmentId}/services/application/${applicationId}?tab=deployments`, ); }) .catch(() => { diff --git a/apps/dokploy/components/dashboard/application/preview-deployments/show-preview-settings.tsx b/apps/dokploy/components/dashboard/application/preview-deployments/show-preview-settings.tsx index 16c916d93..862d5f87a 100644 --- a/apps/dokploy/components/dashboard/application/preview-deployments/show-preview-settings.tsx +++ b/apps/dokploy/components/dashboard/application/preview-deployments/show-preview-settings.tsx @@ -46,6 +46,7 @@ const schema = z .object({ env: z.string(), buildArgs: z.string(), + buildSecrets: z.string(), wildcardDomain: z.string(), port: z.number(), previewLimit: z.number(), @@ -109,6 +110,7 @@ export const ShowPreviewSettings = ({ applicationId }: Props) => { form.reset({ env: data.previewEnv || "", buildArgs: data.previewBuildArgs || "", + buildSecrets: data.previewBuildSecrets || "", wildcardDomain: data.previewWildcard || "*.traefik.me", port: data.previewPort || 3000, previewLabels: data.previewLabels || [], @@ -127,6 +129,7 @@ export const ShowPreviewSettings = ({ applicationId }: Props) => { updateApplication({ previewEnv: formData.env, previewBuildArgs: formData.buildArgs, + previewBuildSecrets: formData.buildSecrets, previewWildcard: formData.wildcardDomain, previewPort: formData.port, previewLabels: formData.previewLabels, @@ -467,13 +470,37 @@ export const ShowPreviewSettings = ({ applicationId }: Props) => { {data?.buildType === "dockerfile" && ( - Available only at build-time. See documentation  + Arguments are available only at build-time. See + documentation  + here + + . + + } + placeholder="NPM_TOKEN=xyz" + /> + )} + {data?.buildType === "dockerfile" && ( + + Secrets are specially designed for sensitive information + and are only available at build-time. See + documentation  + diff --git a/apps/dokploy/components/dashboard/application/schedules/handle-schedules.tsx b/apps/dokploy/components/dashboard/application/schedules/handle-schedules.tsx index e403c8be5..8273d0e2b 100644 --- a/apps/dokploy/components/dashboard/application/schedules/handle-schedules.tsx +++ b/apps/dokploy/components/dashboard/application/schedules/handle-schedules.tsx @@ -7,7 +7,7 @@ import { RefreshCw, } from "lucide-react"; import { useEffect, useState } from "react"; -import { useForm } from "react-hook-form"; +import { type Control, useForm } from "react-hook-form"; import { toast } from "sonner"; import { z } from "zod"; import { AlertBlock } from "@/components/shared/alert-block"; @@ -57,6 +57,7 @@ export const commonCronExpressions = [ { label: "Every month on the 1st at midnight", value: "0 0 1 * *" }, { label: "Every 15 minutes", value: "*/15 * * * *" }, { label: "Every weekday at midnight", value: "0 0 * * 1-5" }, + { label: "Custom", value: "custom" }, ]; const formSchema = z @@ -115,10 +116,91 @@ interface Props { scheduleType?: "application" | "compose" | "server" | "dokploy-server"; } +export const ScheduleFormField = ({ + name, + formControl, +}: { + name: string; + formControl: Control; +}) => { + const [selectedOption, setSelectedOption] = useState(""); + + return ( + ( + + + Schedule + + + + + + +

Cron expression format: minute hour day month weekday

+

Example: 0 0 * * * (daily at midnight)

+
+
+
+
+
+ +
+ + { + const value = e.target.value; + const commonExpression = commonCronExpressions.find( + (expression) => expression.value === value, + ); + if (commonExpression) { + setSelectedOption(commonExpression.value); + } else { + setSelectedOption("custom"); + } + field.onChange(e); + }} + /> + +
+
+ + Choose a predefined schedule or enter a custom cron expression + + +
+ )} + /> + ); +}; + export const HandleSchedules = ({ id, scheduleId, scheduleType }: Props) => { const [isOpen, setIsOpen] = useState(false); const [cacheType, setCacheType] = useState("cache"); - const utils = api.useUtils(); const form = useForm>({ resolver: zodResolver(formSchema), @@ -377,63 +459,9 @@ export const HandleSchedules = ({ id, scheduleId, scheduleType }: Props) => { )} /> - ( - - - Schedule - - - - - - -

- Cron expression format: minute hour day month - weekday -

-

Example: 0 0 * * * (daily at midnight)

-
-
-
-
-
- -
- - - -
-
- - Choose a predefined schedule or enter a custom cron - expression - - -
- )} + formControl={form.control} /> {(scheduleTypeForm === "application" || diff --git a/apps/dokploy/components/dashboard/application/schedules/show-schedules.tsx b/apps/dokploy/components/dashboard/application/schedules/show-schedules.tsx index 3209b6e03..26bfa9421 100644 --- a/apps/dokploy/components/dashboard/application/schedules/show-schedules.tsx +++ b/apps/dokploy/components/dashboard/application/schedules/show-schedules.tsx @@ -6,6 +6,7 @@ import { Terminal, Trash2, } from "lucide-react"; +import { useState } from "react"; import { toast } from "sonner"; import { DialogAction } from "@/components/shared/dialog-action"; import { Badge } from "@/components/ui/badge"; @@ -33,6 +34,9 @@ interface Props { } export const ShowSchedules = ({ id, scheduleType = "application" }: Props) => { + const [runningSchedules, setRunningSchedules] = useState>( + new Set(), + ); const { data: schedules, isLoading: isLoadingSchedules, @@ -46,14 +50,27 @@ export const ShowSchedules = ({ id, scheduleType = "application" }: Props) => { enabled: !!id, }, ); - const utils = api.useUtils(); - const { mutateAsync: deleteSchedule, isLoading: isDeleting } = api.schedule.delete.useMutation(); + const { mutateAsync: runManually } = api.schedule.runManually.useMutation(); - const { mutateAsync: runManually, isLoading } = - api.schedule.runManually.useMutation(); + const handleRunManually = async (scheduleId: string) => { + setRunningSchedules((prev) => new Set(prev).add(scheduleId)); + try { + await runManually({ scheduleId }); + toast.success("Schedule run successfully"); + await refetchSchedules(); + } catch { + toast.error("Error running schedule"); + } finally { + setRunningSchedules((prev) => { + const newSet = new Set(prev); + newSet.delete(scheduleId); + return newSet; + }); + } + }; return ( @@ -67,7 +84,6 @@ export const ShowSchedules = ({ id, scheduleType = "application" }: Props) => { Schedule tasks to run automatically at specified intervals.
- {schedules && schedules.length > 0 && ( )} @@ -75,7 +91,7 @@ export const ShowSchedules = ({ id, scheduleType = "application" }: Props) => { {isLoadingSchedules ? ( -
+
Loading scheduled tasks... @@ -91,13 +107,13 @@ export const ShowSchedules = ({ id, scheduleType = "application" }: Props) => { return (
-
+
-
+

{schedule.name} @@ -132,16 +148,15 @@ export const ShowSchedules = ({ id, scheduleType = "application" }: Props) => { )}

{schedule.command && ( -
- - +
+ + {schedule.command}
)}
-
{ serverId={serverId || undefined} > - @@ -160,37 +174,26 @@ export const ShowSchedules = ({ id, scheduleType = "application" }: Props) => { type="button" variant="ghost" size="icon" - isLoading={isLoading} - onClick={async () => { - toast.success("Schedule run successfully"); - - await runManually({ - scheduleId: schedule.scheduleId, - }) - .then(async () => { - await new Promise((resolve) => - setTimeout(resolve, 1500), - ); - refetchSchedules(); - }) - .catch(() => { - toast.error("Error running schedule"); - }); - }} + disabled={runningSchedules.has(schedule.scheduleId)} + onClick={() => + handleRunManually(schedule.scheduleId) + } > - + {runningSchedules.has(schedule.scheduleId) ? ( + + ) : ( + + )} Run Manual Schedule - - { diff --git a/apps/dokploy/components/dashboard/application/volume-backups/handle-volume-backups.tsx b/apps/dokploy/components/dashboard/application/volume-backups/handle-volume-backups.tsx index f00b91a9d..e179713de 100644 --- a/apps/dokploy/components/dashboard/application/volume-backups/handle-volume-backups.tsx +++ b/apps/dokploy/components/dashboard/application/volume-backups/handle-volume-backups.tsx @@ -1,11 +1,5 @@ import { zodResolver } from "@hookform/resolvers/zod"; -import { - DatabaseZap, - Info, - PenBoxIcon, - PlusCircle, - RefreshCw, -} from "lucide-react"; +import { DatabaseZap, PenBoxIcon, PlusCircle, RefreshCw } from "lucide-react"; import { useEffect, useState } from "react"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; @@ -47,13 +41,19 @@ import { import { cn } from "@/lib/utils"; import { api } from "@/utils/api"; import type { CacheType } from "../domains/handle-domain"; -import { commonCronExpressions } from "../schedules/handle-schedules"; +import { ScheduleFormField } from "../schedules/handle-schedules"; const formSchema = z .object({ name: z.string().min(1, "Name is required"), cronExpression: z.string().min(1, "Cron expression is required"), - volumeName: z.string().min(1, "Volume name is required"), + volumeName: z + .string() + .min(1, "Volume name is required") + .regex( + /^[a-zA-Z0-9][a-zA-Z0-9_.-]*$/, + "Invalid volume name. Use letters, numbers, '._-' and start with a letter/number.", + ), prefix: z.string(), keepLatestCount: z.coerce .number() @@ -306,64 +306,9 @@ export const HandleVolumeBackups = ({ )} /> - - ( - - - Schedule - - - - - - -

- Cron expression format: minute hour day month - weekday -

-

Example: 0 0 * * * (daily at midnight)

-
-
-
-
-
- -
- - - -
-
- - Choose a predefined schedule or enter a custom cron - expression - - -
- )} + formControl={form.control} /> { + const [runningBackups, setRunningBackups] = useState>(new Set()); const { data: volumeBackups, isLoading: isLoadingVolumeBackups, @@ -51,19 +53,33 @@ export const ShowVolumeBackups = ({ enabled: !!id, }, ); - const utils = api.useUtils(); - const { mutateAsync: deleteVolumeBackup, isLoading: isDeleting } = api.volumeBackups.delete.useMutation(); - - const { mutateAsync: runManually, isLoading } = + const { mutateAsync: runManually } = api.volumeBackups.runManually.useMutation(); + const handleRunManually = async (volumeBackupId: string) => { + setRunningBackups((prev) => new Set(prev).add(volumeBackupId)); + try { + await runManually({ volumeBackupId }); + toast.success("Volume backup run successfully"); + await refetchVolumeBackups(); + } catch { + toast.error("Error running volume backup"); + } finally { + setRunningBackups((prev) => { + const newSet = new Set(prev); + newSet.delete(volumeBackupId); + return newSet; + }); + } + }; + return ( -
+
Volume Backups @@ -73,12 +89,10 @@ export const ShowVolumeBackups = ({ intervals.
- -
+
{volumeBackups && volumeBackups.length > 0 && ( <> -
{isLoadingVolumeBackups ? ( -
+
Loading volume backups... @@ -113,13 +127,13 @@ export const ShowVolumeBackups = ({ return (
-
+
-
+

{volumeBackup.name} @@ -143,18 +157,16 @@ export const ShowVolumeBackups = ({

- -
+
- @@ -162,25 +174,18 @@ export const ShowVolumeBackups = ({ type="button" variant="ghost" size="icon" - isLoading={isLoading} - onClick={async () => { - toast.success("Volume backup run successfully"); - - await runManually({ - volumeBackupId: volumeBackup.volumeBackupId, - }) - .then(async () => { - await new Promise((resolve) => - setTimeout(resolve, 1500), - ); - refetchVolumeBackups(); - }) - .catch(() => { - toast.error("Error running volume backup"); - }); - }} + disabled={runningBackups.has( + volumeBackup.volumeBackupId, + )} + onClick={() => + handleRunManually(volumeBackup.volumeBackupId) + } > - + {runningBackups.has(volumeBackup.volumeBackupId) ? ( + + ) : ( + + )} @@ -188,13 +193,11 @@ export const ShowVolumeBackups = ({ - - @@ -230,7 +233,7 @@ export const ShowVolumeBackups = ({ })}
) : ( -
+

No volume backups diff --git a/apps/dokploy/components/dashboard/compose/delete-service.tsx b/apps/dokploy/components/dashboard/compose/delete-service.tsx index 438af954a..5c8577dff 100644 --- a/apps/dokploy/components/dashboard/compose/delete-service.tsx +++ b/apps/dokploy/components/dashboard/compose/delete-service.tsx @@ -101,8 +101,10 @@ export const DeleteService = ({ id, type }: Props) => { deleteVolumes, }) .then((result) => { - push(`/dashboard/project/${result?.projectId}`); - toast.success("deleted successfully"); + push( + `/dashboard/project/${result?.environment?.projectId}/environment/${result?.environment?.environmentId}`, + ); + toast.success("Service deleted successfully"); setIsOpen(false); }) .catch(() => { diff --git a/apps/dokploy/components/dashboard/compose/general/actions.tsx b/apps/dokploy/components/dashboard/compose/general/actions.tsx index 29a9f9be3..1bbeb880e 100644 --- a/apps/dokploy/components/dashboard/compose/general/actions.tsx +++ b/apps/dokploy/components/dashboard/compose/general/actions.tsx @@ -47,7 +47,7 @@ export const ComposeActions = ({ composeId }: Props) => { toast.success("Compose deployed successfully"); refetch(); router.push( - `/dashboard/project/${data?.project.projectId}/services/compose/${composeId}?tab=deployments`, + `/dashboard/project/${data?.environment.projectId}/environment/${data?.environmentId}/services/compose/${composeId}?tab=deployments`, ); }) .catch(() => { @@ -195,6 +195,7 @@ export const ComposeActions = ({ composeId }: Props) => { + + + + Environments + + + {environments?.map((environment) => { + const servicesCount = + environment.mariadb.length + + environment.mongo.length + + environment.mysql.length + + environment.postgres.length + + environment.redis.length + + environment.applications.length + + environment.compose.length; + return ( +

+ { + router.push( + `/dashboard/project/${projectId}/environment/${environment.environmentId}`, + ); + }} + > +
+ + {environment.name} ({servicesCount}) + + {environment.environmentId === currentEnvironmentId && ( +
+ )} +
+ + + {/* Action buttons for non-production environments */} + {/* + + */} + {environment.name !== "production" && ( +
+ + + {canDeleteEnvironments && ( + + )} +
+ )} +
+ ); + })} + + + {canCreateEnvironments && ( + setIsCreateDialogOpen(true)} + > + + Create Environment + + )} + + + + + + + Create Environment + + Create a new environment for your project. + + + +
+
+ + setName(e.target.value)} + placeholder="Environment name" + /> +
+
+ +