From 6397fd6095094f909242915dea64020bdd05e948 Mon Sep 17 00:00:00 2001 From: nurikk <1525421+nurikk@users.noreply.github.com> Date: Sun, 15 Mar 2026 14:13:01 +0000 Subject: [PATCH 1/7] feat: inject git commit hash and message as Docker build args Automatically inject DOKPLOY_COMMIT_HASH and DOKPLOY_COMMIT_MESSAGE as build-time arguments during Docker image builds, making them available as runtime environment variables in deployed containers. Applied to all builders: - Dockerfile: --build-arg - Railpack: --build-arg (docker buildx) - Nixpacks: --env - Heroku: --env - Paketo: --env - Static: inherits from Dockerfile builder Closes #4006 --- .../deploy/builders-commit-info.test.ts | 199 ++++++++++++++++++ .../server/src/utils/builders/docker-file.ts | 12 +- packages/server/src/utils/builders/heroku.ts | 4 +- .../server/src/utils/builders/nixpacks.ts | 4 +- packages/server/src/utils/builders/paketo.ts | 4 +- .../server/src/utils/builders/railpack.ts | 4 +- packages/server/src/utils/builders/utils.ts | 23 ++ 7 files changed, 243 insertions(+), 7 deletions(-) create mode 100644 apps/dokploy/__test__/deploy/builders-commit-info.test.ts diff --git a/apps/dokploy/__test__/deploy/builders-commit-info.test.ts b/apps/dokploy/__test__/deploy/builders-commit-info.test.ts new file mode 100644 index 0000000000..ae5b9889f5 --- /dev/null +++ b/apps/dokploy/__test__/deploy/builders-commit-info.test.ts @@ -0,0 +1,199 @@ +import { describe, expect, it, vi } from "vitest"; + +vi.mock("@dokploy/server/db", () => { + const createChainableMock = (): any => { + const chain = { + set: vi.fn(() => chain), + where: vi.fn(() => chain), + returning: vi.fn().mockResolvedValue([{}] as any), + from: vi.fn(() => chain), + innerJoin: vi.fn(() => chain), + then: (resolve: (v: any) => void) => { + resolve([]); + }, + } as any; + return chain; + }; + + return { + db: { + select: vi.fn(() => createChainableMock()), + insert: vi.fn(), + update: vi.fn(() => createChainableMock()), + delete: vi.fn(), + query: {}, + }, + }; +}); + +import { getDockerCommand } from "@dokploy/server/utils/builders/docker-file"; +import { getHerokuCommand } from "@dokploy/server/utils/builders/heroku"; +import { getNixpacksCommand } from "@dokploy/server/utils/builders/nixpacks"; +import { getPaketoCommand } from "@dokploy/server/utils/builders/paketo"; +import { getRailpackCommand } from "@dokploy/server/utils/builders/railpack"; +import { + getCommitInfoBuildArgs, + getCommitInfoEnvArgs, + getGitCommitInfoCommands, +} from "@dokploy/server/utils/builders/utils"; +import type { ApplicationNested } from "@dokploy/server/utils/builders"; + +const createMockApplication = (overrides = {}): ApplicationNested => + ({ + applicationId: "test-app-id", + appName: "test-app", + name: "Test App", + sourceType: "git" as const, + buildType: "dockerfile" as const, + buildPath: "/", + dockerfile: "Dockerfile", + dockerContextPath: null, + dockerBuildStage: null, + env: null, + buildArgs: null, + buildSecrets: null, + publishDirectory: null, + cleanCache: false, + createEnvFile: false, + isStaticSpa: false, + enableSubmodules: false, + serverId: null, + herokuVersion: "24", + railpackVersion: "0.1.0", + environmentId: "env-id", + environment: { + projectId: "project-id", + env: "", + name: "production", + project: { + name: "Test Project", + organizationId: "org-id", + env: "", + }, + }, + mounts: [], + security: null, + redirects: [], + ports: [], + registry: null, + buildRegistry: null, + rollbackRegistry: null, + deployments: [], + domains: [], + ...overrides, + }) as unknown as ApplicationNested; + +describe("Git Commit Info Helpers", () => { + it("getGitCommitInfoCommands should return shell commands to extract commit info", () => { + const commands = getGitCommitInfoCommands(); + expect(commands).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse --short HEAD"); + expect(commands).toContain("DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s"); + expect(commands).toContain('|| echo "unknown"'); + }); + + it("getCommitInfoBuildArgs should return --build-arg flags", () => { + const args = getCommitInfoBuildArgs(); + expect(args).toContain('--build-arg DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); + expect(args).toContain('--build-arg DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'); + }); + + it("getCommitInfoEnvArgs should return --env flags", () => { + const args = getCommitInfoEnvArgs(); + expect(args).toContain('--env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); + expect(args).toContain('--env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'); + }); +}); + +describe("Dockerfile builder - commit info injection", () => { + it("should include git commit info extraction commands", () => { + const command = getDockerCommand(createMockApplication()); + expect(command).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse --short HEAD"); + expect(command).toContain("DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s"); + }); + + it("should pass commit info as --build-arg to docker build", () => { + const command = getDockerCommand(createMockApplication()); + expect(command).toContain('--build-arg DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); + expect(command).toContain('--build-arg DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'); + }); + + it("should include commit info alongside user-defined build args", () => { + const command = getDockerCommand( + createMockApplication({ buildArgs: "MY_VAR=hello" }), + ); + expect(command).toContain("--build-arg MY_VAR"); + expect(command).toContain('--build-arg DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); + }); +}); + +describe("Nixpacks builder - commit info injection", () => { + it("should include git commit info extraction commands", () => { + const command = getNixpacksCommand( + createMockApplication({ buildType: "nixpacks" }), + ); + expect(command).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse --short HEAD"); + expect(command).toContain("DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s"); + }); + + it("should pass commit info as --env to nixpacks build", () => { + const command = getNixpacksCommand( + createMockApplication({ buildType: "nixpacks" }), + ); + expect(command).toContain('--env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); + expect(command).toContain('--env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'); + }); +}); + +describe("Heroku builder - commit info injection", () => { + it("should include git commit info extraction commands", () => { + const command = getHerokuCommand( + createMockApplication({ buildType: "heroku_buildpacks" }), + ); + expect(command).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse --short HEAD"); + expect(command).toContain("DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s"); + }); + + it("should pass commit info as --env to pack build", () => { + const command = getHerokuCommand( + createMockApplication({ buildType: "heroku_buildpacks" }), + ); + expect(command).toContain('--env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); + expect(command).toContain('--env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'); + }); +}); + +describe("Paketo builder - commit info injection", () => { + it("should include git commit info extraction commands", () => { + const command = getPaketoCommand( + createMockApplication({ buildType: "paketo_buildpacks" }), + ); + expect(command).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse --short HEAD"); + expect(command).toContain("DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s"); + }); + + it("should pass commit info as --env to pack build", () => { + const command = getPaketoCommand( + createMockApplication({ buildType: "paketo_buildpacks" }), + ); + expect(command).toContain('--env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); + expect(command).toContain('--env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'); + }); +}); + +describe("Railpack builder - commit info injection", () => { + it("should include git commit info extraction commands", () => { + const command = getRailpackCommand( + createMockApplication({ buildType: "railpack" }), + ); + expect(command).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse --short HEAD"); + expect(command).toContain("DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s"); + }); + + it("should pass commit info as --build-arg to docker buildx", () => { + const command = getRailpackCommand( + createMockApplication({ buildType: "railpack" }), + ); + expect(command).toContain('--build-arg DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); + expect(command).toContain('--build-arg DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'); + }); +}); diff --git a/packages/server/src/utils/builders/docker-file.ts b/packages/server/src/utils/builders/docker-file.ts index ea53a5bffe..9916679c1a 100644 --- a/packages/server/src/utils/builders/docker-file.ts +++ b/packages/server/src/utils/builders/docker-file.ts @@ -8,7 +8,11 @@ import { getDockerContextPath, } from "../filesystem/directory"; import type { ApplicationNested } from "."; -import { createEnvFileCommand } from "./utils"; +import { + createEnvFileCommand, + getCommitInfoBuildArgs, + getGitCommitInfoCommands, +} from "./utils"; export const getDockerCommand = (application: ApplicationNested) => { const { @@ -86,12 +90,14 @@ export const getDockerCommand = (application: ApplicationNested) => { command += ` echo "Building ${appName}" ; -cd ${dockerContextPath} || { +cd ${dockerContextPath} || { echo "❌ The path ${dockerContextPath} does not exist" ; exit 1; } -${joinedSecrets} docker ${commandArgs.join(" ")} || { +${getGitCommitInfoCommands()} + +${joinedSecrets} docker ${commandArgs.join(" ")} ${getCommitInfoBuildArgs()} || { echo "❌ Docker build failed" ; exit 1; } diff --git a/packages/server/src/utils/builders/heroku.ts b/packages/server/src/utils/builders/heroku.ts index 8b38c694d5..3c710dd1e6 100644 --- a/packages/server/src/utils/builders/heroku.ts +++ b/packages/server/src/utils/builders/heroku.ts @@ -1,6 +1,7 @@ import { prepareEnvironmentVariablesForShell } from "../docker/utils"; import { getBuildAppDirectory } from "../filesystem/directory"; import type { ApplicationNested } from "."; +import { getGitCommitInfoCommands } from "./utils"; export const getHerokuCommand = (application: ApplicationNested) => { const { env, appName, cleanCache } = application; @@ -31,8 +32,9 @@ export const getHerokuCommand = (application: ApplicationNested) => { const command = `pack ${args.join(" ")}`; const bashCommand = ` +${getGitCommitInfoCommands()} echo "Starting heroku build..." ; -${command} || { +${command} --env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH" --env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE" || { echo "❌ Heroku build failed" ; exit 1; } diff --git a/packages/server/src/utils/builders/nixpacks.ts b/packages/server/src/utils/builders/nixpacks.ts index b7134ea658..5605f6629c 100644 --- a/packages/server/src/utils/builders/nixpacks.ts +++ b/packages/server/src/utils/builders/nixpacks.ts @@ -4,6 +4,7 @@ import { nanoid } from "nanoid"; import { prepareEnvironmentVariablesForShell } from "../docker/utils"; import { getBuildAppDirectory } from "../filesystem/directory"; import type { ApplicationNested } from "."; +import { getGitCommitInfoCommands } from "./utils"; export const getNixpacksCommand = (application: ApplicationNested) => { const { env, appName, publishDirectory, cleanCache } = application; @@ -32,8 +33,9 @@ export const getNixpacksCommand = (application: ApplicationNested) => { } const command = `nixpacks ${args.join(" ")}`; let bashCommand = ` + ${getGitCommitInfoCommands()} echo "Starting nixpacks build..." ; - ${command} || { + ${command} --env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH" --env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE" || { echo "❌ Nixpacks build failed" ; exit 1; } diff --git a/packages/server/src/utils/builders/paketo.ts b/packages/server/src/utils/builders/paketo.ts index bb4f8c8a48..24d64df079 100644 --- a/packages/server/src/utils/builders/paketo.ts +++ b/packages/server/src/utils/builders/paketo.ts @@ -1,6 +1,7 @@ import { prepareEnvironmentVariablesForShell } from "../docker/utils"; import { getBuildAppDirectory } from "../filesystem/directory"; import type { ApplicationNested } from "."; +import { getGitCommitInfoCommands } from "./utils"; export const getPaketoCommand = (application: ApplicationNested) => { const { env, appName, cleanCache } = application; @@ -31,8 +32,9 @@ export const getPaketoCommand = (application: ApplicationNested) => { const command = `pack ${args.join(" ")}`; const bashCommand = ` +${getGitCommitInfoCommands()} echo "Starting Paketo build..." ; -${command} || { +${command} --env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH" --env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE" || { echo "❌ Paketo build failed" ; exit 1; } diff --git a/packages/server/src/utils/builders/railpack.ts b/packages/server/src/utils/builders/railpack.ts index 62fa9f9756..dafbb106ed 100644 --- a/packages/server/src/utils/builders/railpack.ts +++ b/packages/server/src/utils/builders/railpack.ts @@ -8,6 +8,7 @@ import { } from "../docker/utils"; import { getBuildAppDirectory } from "../filesystem/directory"; import type { ApplicationNested } from "."; +import { getCommitInfoBuildArgs, getGitCommitInfoCommands } from "./utils"; const calculateSecretsHash = (envVariables: string[]): string => { const hash = createHash("sha256"); @@ -102,7 +103,8 @@ echo "✅ Railpack prepare completed." ; echo "Building with Railpack frontend..." ; # Export environment variables for secrets ${exportEnvs.join("\n")} -docker ${buildArgs.join(" ")} || { +${getGitCommitInfoCommands()} +docker ${buildArgs.join(" ")} ${getCommitInfoBuildArgs()} || { echo "❌ Railpack build failed" ; docker buildx rm builder-containerd || true exit 1; diff --git a/packages/server/src/utils/builders/utils.ts b/packages/server/src/utils/builders/utils.ts index 97ea69ef8c..882fee126b 100644 --- a/packages/server/src/utils/builders/utils.ts +++ b/packages/server/src/utils/builders/utils.ts @@ -18,3 +18,26 @@ export const createEnvFileCommand = ( return `echo "${encodedContent}" | base64 -d > "${envFilePath}";`; }; + +/** + * Returns shell commands to extract git commit hash and message + * into DOKPLOY_COMMIT_HASH and DOKPLOY_COMMIT_MESSAGE shell variables. + */ +export const getGitCommitInfoCommands = () => { + return `DOKPLOY_COMMIT_HASH=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown") +DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s 2>/dev/null || echo "unknown")`; +}; + +/** + * Returns docker --build-arg flags for commit info. + */ +export const getCommitInfoBuildArgs = () => { + return '--build-arg DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH" --build-arg DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'; +}; + +/** + * Returns --env flags for commit info (for pack/nixpacks builders). + */ +export const getCommitInfoEnvArgs = () => { + return '--env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH" --env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'; +}; From 18677c9e723a6b805af583cfe54e85bd4d527553 Mon Sep 17 00:00:00 2001 From: nurikk <1525421+nurikk@users.noreply.github.com> Date: Sun, 15 Mar 2026 14:20:40 +0000 Subject: [PATCH 2/7] refactor: use getCommitInfoEnvArgs() helper in heroku, nixpacks, paketo builders Addresses review feedback: replace inlined --env flags with the shared helper to avoid maintenance burden if variable names change. --- packages/server/src/utils/builders/heroku.ts | 4 ++-- packages/server/src/utils/builders/nixpacks.ts | 4 ++-- packages/server/src/utils/builders/paketo.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/server/src/utils/builders/heroku.ts b/packages/server/src/utils/builders/heroku.ts index 3c710dd1e6..4daf6e8e37 100644 --- a/packages/server/src/utils/builders/heroku.ts +++ b/packages/server/src/utils/builders/heroku.ts @@ -1,7 +1,7 @@ import { prepareEnvironmentVariablesForShell } from "../docker/utils"; import { getBuildAppDirectory } from "../filesystem/directory"; import type { ApplicationNested } from "."; -import { getGitCommitInfoCommands } from "./utils"; +import { getCommitInfoEnvArgs, getGitCommitInfoCommands } from "./utils"; export const getHerokuCommand = (application: ApplicationNested) => { const { env, appName, cleanCache } = application; @@ -34,7 +34,7 @@ export const getHerokuCommand = (application: ApplicationNested) => { const bashCommand = ` ${getGitCommitInfoCommands()} echo "Starting heroku build..." ; -${command} --env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH" --env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE" || { +${command} ${getCommitInfoEnvArgs()} || { echo "❌ Heroku build failed" ; exit 1; } diff --git a/packages/server/src/utils/builders/nixpacks.ts b/packages/server/src/utils/builders/nixpacks.ts index 5605f6629c..6df77a8fd2 100644 --- a/packages/server/src/utils/builders/nixpacks.ts +++ b/packages/server/src/utils/builders/nixpacks.ts @@ -4,7 +4,7 @@ import { nanoid } from "nanoid"; import { prepareEnvironmentVariablesForShell } from "../docker/utils"; import { getBuildAppDirectory } from "../filesystem/directory"; import type { ApplicationNested } from "."; -import { getGitCommitInfoCommands } from "./utils"; +import { getCommitInfoEnvArgs, getGitCommitInfoCommands } from "./utils"; export const getNixpacksCommand = (application: ApplicationNested) => { const { env, appName, publishDirectory, cleanCache } = application; @@ -35,7 +35,7 @@ export const getNixpacksCommand = (application: ApplicationNested) => { let bashCommand = ` ${getGitCommitInfoCommands()} echo "Starting nixpacks build..." ; - ${command} --env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH" --env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE" || { + ${command} ${getCommitInfoEnvArgs()} || { echo "❌ Nixpacks build failed" ; exit 1; } diff --git a/packages/server/src/utils/builders/paketo.ts b/packages/server/src/utils/builders/paketo.ts index 24d64df079..58c4417f99 100644 --- a/packages/server/src/utils/builders/paketo.ts +++ b/packages/server/src/utils/builders/paketo.ts @@ -1,7 +1,7 @@ import { prepareEnvironmentVariablesForShell } from "../docker/utils"; import { getBuildAppDirectory } from "../filesystem/directory"; import type { ApplicationNested } from "."; -import { getGitCommitInfoCommands } from "./utils"; +import { getCommitInfoEnvArgs, getGitCommitInfoCommands } from "./utils"; export const getPaketoCommand = (application: ApplicationNested) => { const { env, appName, cleanCache } = application; @@ -34,7 +34,7 @@ export const getPaketoCommand = (application: ApplicationNested) => { const bashCommand = ` ${getGitCommitInfoCommands()} echo "Starting Paketo build..." ; -${command} --env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH" --env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE" || { +${command} ${getCommitInfoEnvArgs()} || { echo "❌ Paketo build failed" ; exit 1; } From 510d761c53d08ec7fda7de35d50d73273f2e4def Mon Sep 17 00:00:00 2001 From: nurikk <1525421+nurikk@users.noreply.github.com> Date: Sun, 15 Mar 2026 14:24:15 +0000 Subject: [PATCH 3/7] feat: add DOKPLOY_COMMIT_HASH_LONG build variable Includes the full commit hash alongside the short hash, useful for programmatic lookups and API integrations. --- .../__test__/deploy/builders-commit-info.test.ts | 13 +++++++++++++ packages/server/src/utils/builders/utils.ts | 5 +++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/apps/dokploy/__test__/deploy/builders-commit-info.test.ts b/apps/dokploy/__test__/deploy/builders-commit-info.test.ts index ae5b9889f5..60ba65aa28 100644 --- a/apps/dokploy/__test__/deploy/builders-commit-info.test.ts +++ b/apps/dokploy/__test__/deploy/builders-commit-info.test.ts @@ -87,6 +87,7 @@ describe("Git Commit Info Helpers", () => { it("getGitCommitInfoCommands should return shell commands to extract commit info", () => { const commands = getGitCommitInfoCommands(); expect(commands).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse --short HEAD"); + expect(commands).toContain("DOKPLOY_COMMIT_HASH_LONG=$(git rev-parse HEAD"); expect(commands).toContain("DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s"); expect(commands).toContain('|| echo "unknown"'); }); @@ -94,12 +95,14 @@ describe("Git Commit Info Helpers", () => { it("getCommitInfoBuildArgs should return --build-arg flags", () => { const args = getCommitInfoBuildArgs(); expect(args).toContain('--build-arg DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); + expect(args).toContain('--build-arg DOKPLOY_COMMIT_HASH_LONG="$DOKPLOY_COMMIT_HASH_LONG"'); expect(args).toContain('--build-arg DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'); }); it("getCommitInfoEnvArgs should return --env flags", () => { const args = getCommitInfoEnvArgs(); expect(args).toContain('--env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); + expect(args).toContain('--env DOKPLOY_COMMIT_HASH_LONG="$DOKPLOY_COMMIT_HASH_LONG"'); expect(args).toContain('--env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'); }); }); @@ -108,12 +111,14 @@ describe("Dockerfile builder - commit info injection", () => { it("should include git commit info extraction commands", () => { const command = getDockerCommand(createMockApplication()); expect(command).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse --short HEAD"); + expect(command).toContain("DOKPLOY_COMMIT_HASH_LONG=$(git rev-parse HEAD"); expect(command).toContain("DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s"); }); it("should pass commit info as --build-arg to docker build", () => { const command = getDockerCommand(createMockApplication()); expect(command).toContain('--build-arg DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); + expect(command).toContain('--build-arg DOKPLOY_COMMIT_HASH_LONG="$DOKPLOY_COMMIT_HASH_LONG"'); expect(command).toContain('--build-arg DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'); }); @@ -132,6 +137,7 @@ describe("Nixpacks builder - commit info injection", () => { createMockApplication({ buildType: "nixpacks" }), ); expect(command).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse --short HEAD"); + expect(command).toContain("DOKPLOY_COMMIT_HASH_LONG=$(git rev-parse HEAD"); expect(command).toContain("DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s"); }); @@ -140,6 +146,7 @@ describe("Nixpacks builder - commit info injection", () => { createMockApplication({ buildType: "nixpacks" }), ); expect(command).toContain('--env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); + expect(command).toContain('--env DOKPLOY_COMMIT_HASH_LONG="$DOKPLOY_COMMIT_HASH_LONG"'); expect(command).toContain('--env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'); }); }); @@ -150,6 +157,7 @@ describe("Heroku builder - commit info injection", () => { createMockApplication({ buildType: "heroku_buildpacks" }), ); expect(command).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse --short HEAD"); + expect(command).toContain("DOKPLOY_COMMIT_HASH_LONG=$(git rev-parse HEAD"); expect(command).toContain("DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s"); }); @@ -158,6 +166,7 @@ describe("Heroku builder - commit info injection", () => { createMockApplication({ buildType: "heroku_buildpacks" }), ); expect(command).toContain('--env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); + expect(command).toContain('--env DOKPLOY_COMMIT_HASH_LONG="$DOKPLOY_COMMIT_HASH_LONG"'); expect(command).toContain('--env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'); }); }); @@ -168,6 +177,7 @@ describe("Paketo builder - commit info injection", () => { createMockApplication({ buildType: "paketo_buildpacks" }), ); expect(command).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse --short HEAD"); + expect(command).toContain("DOKPLOY_COMMIT_HASH_LONG=$(git rev-parse HEAD"); expect(command).toContain("DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s"); }); @@ -176,6 +186,7 @@ describe("Paketo builder - commit info injection", () => { createMockApplication({ buildType: "paketo_buildpacks" }), ); expect(command).toContain('--env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); + expect(command).toContain('--env DOKPLOY_COMMIT_HASH_LONG="$DOKPLOY_COMMIT_HASH_LONG"'); expect(command).toContain('--env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'); }); }); @@ -186,6 +197,7 @@ describe("Railpack builder - commit info injection", () => { createMockApplication({ buildType: "railpack" }), ); expect(command).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse --short HEAD"); + expect(command).toContain("DOKPLOY_COMMIT_HASH_LONG=$(git rev-parse HEAD"); expect(command).toContain("DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s"); }); @@ -194,6 +206,7 @@ describe("Railpack builder - commit info injection", () => { createMockApplication({ buildType: "railpack" }), ); expect(command).toContain('--build-arg DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); + expect(command).toContain('--build-arg DOKPLOY_COMMIT_HASH_LONG="$DOKPLOY_COMMIT_HASH_LONG"'); expect(command).toContain('--build-arg DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'); }); }); diff --git a/packages/server/src/utils/builders/utils.ts b/packages/server/src/utils/builders/utils.ts index 882fee126b..13f8fe6428 100644 --- a/packages/server/src/utils/builders/utils.ts +++ b/packages/server/src/utils/builders/utils.ts @@ -25,6 +25,7 @@ export const createEnvFileCommand = ( */ export const getGitCommitInfoCommands = () => { return `DOKPLOY_COMMIT_HASH=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown") +DOKPLOY_COMMIT_HASH_LONG=$(git rev-parse HEAD 2>/dev/null || echo "unknown") DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s 2>/dev/null || echo "unknown")`; }; @@ -32,12 +33,12 @@ DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s 2>/dev/null || echo "unknown")`; * Returns docker --build-arg flags for commit info. */ export const getCommitInfoBuildArgs = () => { - return '--build-arg DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH" --build-arg DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'; + return '--build-arg DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH" --build-arg DOKPLOY_COMMIT_HASH_LONG="$DOKPLOY_COMMIT_HASH_LONG" --build-arg DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'; }; /** * Returns --env flags for commit info (for pack/nixpacks builders). */ export const getCommitInfoEnvArgs = () => { - return '--env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH" --env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'; + return '--env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH" --env DOKPLOY_COMMIT_HASH_LONG="$DOKPLOY_COMMIT_HASH_LONG" --env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'; }; From 7be7db837c5882125fa8fb81537d1b9a4564d339 Mon Sep 17 00:00:00 2001 From: nurikk <1525421+nurikk@users.noreply.github.com> Date: Sun, 15 Mar 2026 14:27:23 +0000 Subject: [PATCH 4/7] refactor: rename DOKPLOY_COMMIT_HASH to DOKPLOY_COMMIT_SHORT, DOKPLOY_COMMIT_HASH_LONG to DOKPLOY_COMMIT_HASH DOKPLOY_COMMIT_HASH now contains the full hash (more useful as default), DOKPLOY_COMMIT_SHORT contains the 7-char short hash. --- .../deploy/builders-commit-info.test.ts | 38 +++++++++---------- packages/server/src/utils/builders/utils.ts | 10 ++--- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/apps/dokploy/__test__/deploy/builders-commit-info.test.ts b/apps/dokploy/__test__/deploy/builders-commit-info.test.ts index 60ba65aa28..b6ccdb927c 100644 --- a/apps/dokploy/__test__/deploy/builders-commit-info.test.ts +++ b/apps/dokploy/__test__/deploy/builders-commit-info.test.ts @@ -86,8 +86,8 @@ const createMockApplication = (overrides = {}): ApplicationNested => describe("Git Commit Info Helpers", () => { it("getGitCommitInfoCommands should return shell commands to extract commit info", () => { const commands = getGitCommitInfoCommands(); - expect(commands).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse --short HEAD"); - expect(commands).toContain("DOKPLOY_COMMIT_HASH_LONG=$(git rev-parse HEAD"); + expect(commands).toContain("DOKPLOY_COMMIT_SHORT=$(git rev-parse --short HEAD"); + expect(commands).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse HEAD"); expect(commands).toContain("DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s"); expect(commands).toContain('|| echo "unknown"'); }); @@ -95,14 +95,14 @@ describe("Git Commit Info Helpers", () => { it("getCommitInfoBuildArgs should return --build-arg flags", () => { const args = getCommitInfoBuildArgs(); expect(args).toContain('--build-arg DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); - expect(args).toContain('--build-arg DOKPLOY_COMMIT_HASH_LONG="$DOKPLOY_COMMIT_HASH_LONG"'); + expect(args).toContain('--build-arg DOKPLOY_COMMIT_SHORT="$DOKPLOY_COMMIT_SHORT"'); expect(args).toContain('--build-arg DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'); }); it("getCommitInfoEnvArgs should return --env flags", () => { const args = getCommitInfoEnvArgs(); expect(args).toContain('--env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); - expect(args).toContain('--env DOKPLOY_COMMIT_HASH_LONG="$DOKPLOY_COMMIT_HASH_LONG"'); + expect(args).toContain('--env DOKPLOY_COMMIT_SHORT="$DOKPLOY_COMMIT_SHORT"'); expect(args).toContain('--env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'); }); }); @@ -110,15 +110,15 @@ describe("Git Commit Info Helpers", () => { describe("Dockerfile builder - commit info injection", () => { it("should include git commit info extraction commands", () => { const command = getDockerCommand(createMockApplication()); - expect(command).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse --short HEAD"); - expect(command).toContain("DOKPLOY_COMMIT_HASH_LONG=$(git rev-parse HEAD"); + expect(command).toContain("DOKPLOY_COMMIT_SHORT=$(git rev-parse --short HEAD"); + expect(command).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse HEAD"); expect(command).toContain("DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s"); }); it("should pass commit info as --build-arg to docker build", () => { const command = getDockerCommand(createMockApplication()); expect(command).toContain('--build-arg DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); - expect(command).toContain('--build-arg DOKPLOY_COMMIT_HASH_LONG="$DOKPLOY_COMMIT_HASH_LONG"'); + expect(command).toContain('--build-arg DOKPLOY_COMMIT_SHORT="$DOKPLOY_COMMIT_SHORT"'); expect(command).toContain('--build-arg DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'); }); @@ -136,8 +136,8 @@ describe("Nixpacks builder - commit info injection", () => { const command = getNixpacksCommand( createMockApplication({ buildType: "nixpacks" }), ); - expect(command).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse --short HEAD"); - expect(command).toContain("DOKPLOY_COMMIT_HASH_LONG=$(git rev-parse HEAD"); + expect(command).toContain("DOKPLOY_COMMIT_SHORT=$(git rev-parse --short HEAD"); + expect(command).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse HEAD"); expect(command).toContain("DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s"); }); @@ -146,7 +146,7 @@ describe("Nixpacks builder - commit info injection", () => { createMockApplication({ buildType: "nixpacks" }), ); expect(command).toContain('--env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); - expect(command).toContain('--env DOKPLOY_COMMIT_HASH_LONG="$DOKPLOY_COMMIT_HASH_LONG"'); + expect(command).toContain('--env DOKPLOY_COMMIT_SHORT="$DOKPLOY_COMMIT_SHORT"'); expect(command).toContain('--env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'); }); }); @@ -156,8 +156,8 @@ describe("Heroku builder - commit info injection", () => { const command = getHerokuCommand( createMockApplication({ buildType: "heroku_buildpacks" }), ); - expect(command).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse --short HEAD"); - expect(command).toContain("DOKPLOY_COMMIT_HASH_LONG=$(git rev-parse HEAD"); + expect(command).toContain("DOKPLOY_COMMIT_SHORT=$(git rev-parse --short HEAD"); + expect(command).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse HEAD"); expect(command).toContain("DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s"); }); @@ -166,7 +166,7 @@ describe("Heroku builder - commit info injection", () => { createMockApplication({ buildType: "heroku_buildpacks" }), ); expect(command).toContain('--env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); - expect(command).toContain('--env DOKPLOY_COMMIT_HASH_LONG="$DOKPLOY_COMMIT_HASH_LONG"'); + expect(command).toContain('--env DOKPLOY_COMMIT_SHORT="$DOKPLOY_COMMIT_SHORT"'); expect(command).toContain('--env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'); }); }); @@ -176,8 +176,8 @@ describe("Paketo builder - commit info injection", () => { const command = getPaketoCommand( createMockApplication({ buildType: "paketo_buildpacks" }), ); - expect(command).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse --short HEAD"); - expect(command).toContain("DOKPLOY_COMMIT_HASH_LONG=$(git rev-parse HEAD"); + expect(command).toContain("DOKPLOY_COMMIT_SHORT=$(git rev-parse --short HEAD"); + expect(command).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse HEAD"); expect(command).toContain("DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s"); }); @@ -186,7 +186,7 @@ describe("Paketo builder - commit info injection", () => { createMockApplication({ buildType: "paketo_buildpacks" }), ); expect(command).toContain('--env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); - expect(command).toContain('--env DOKPLOY_COMMIT_HASH_LONG="$DOKPLOY_COMMIT_HASH_LONG"'); + expect(command).toContain('--env DOKPLOY_COMMIT_SHORT="$DOKPLOY_COMMIT_SHORT"'); expect(command).toContain('--env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'); }); }); @@ -196,8 +196,8 @@ describe("Railpack builder - commit info injection", () => { const command = getRailpackCommand( createMockApplication({ buildType: "railpack" }), ); - expect(command).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse --short HEAD"); - expect(command).toContain("DOKPLOY_COMMIT_HASH_LONG=$(git rev-parse HEAD"); + expect(command).toContain("DOKPLOY_COMMIT_SHORT=$(git rev-parse --short HEAD"); + expect(command).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse HEAD"); expect(command).toContain("DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s"); }); @@ -206,7 +206,7 @@ describe("Railpack builder - commit info injection", () => { createMockApplication({ buildType: "railpack" }), ); expect(command).toContain('--build-arg DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); - expect(command).toContain('--build-arg DOKPLOY_COMMIT_HASH_LONG="$DOKPLOY_COMMIT_HASH_LONG"'); + expect(command).toContain('--build-arg DOKPLOY_COMMIT_SHORT="$DOKPLOY_COMMIT_SHORT"'); expect(command).toContain('--build-arg DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'); }); }); diff --git a/packages/server/src/utils/builders/utils.ts b/packages/server/src/utils/builders/utils.ts index 13f8fe6428..a7d15b3217 100644 --- a/packages/server/src/utils/builders/utils.ts +++ b/packages/server/src/utils/builders/utils.ts @@ -21,11 +21,11 @@ export const createEnvFileCommand = ( /** * Returns shell commands to extract git commit hash and message - * into DOKPLOY_COMMIT_HASH and DOKPLOY_COMMIT_MESSAGE shell variables. + * into DOKPLOY_COMMIT_HASH, DOKPLOY_COMMIT_SHORT, and DOKPLOY_COMMIT_MESSAGE shell variables. */ export const getGitCommitInfoCommands = () => { - return `DOKPLOY_COMMIT_HASH=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown") -DOKPLOY_COMMIT_HASH_LONG=$(git rev-parse HEAD 2>/dev/null || echo "unknown") + return `DOKPLOY_COMMIT_HASH=$(git rev-parse HEAD 2>/dev/null || echo "unknown") +DOKPLOY_COMMIT_SHORT=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown") DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s 2>/dev/null || echo "unknown")`; }; @@ -33,12 +33,12 @@ DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s 2>/dev/null || echo "unknown")`; * Returns docker --build-arg flags for commit info. */ export const getCommitInfoBuildArgs = () => { - return '--build-arg DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH" --build-arg DOKPLOY_COMMIT_HASH_LONG="$DOKPLOY_COMMIT_HASH_LONG" --build-arg DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'; + return '--build-arg DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH" --build-arg DOKPLOY_COMMIT_SHORT="$DOKPLOY_COMMIT_SHORT" --build-arg DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'; }; /** * Returns --env flags for commit info (for pack/nixpacks builders). */ export const getCommitInfoEnvArgs = () => { - return '--env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH" --env DOKPLOY_COMMIT_HASH_LONG="$DOKPLOY_COMMIT_HASH_LONG" --env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'; + return '--env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH" --env DOKPLOY_COMMIT_SHORT="$DOKPLOY_COMMIT_SHORT" --env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'; }; From 1956c0603c87bebd00f692f39c0bb070262c9163 Mon Sep 17 00:00:00 2001 From: nurikk <1525421+nurikk@users.noreply.github.com> Date: Sun, 15 Mar 2026 14:43:07 +0000 Subject: [PATCH 5/7] test: remove redundant db mock, already handled by global setup.ts --- .../deploy/builders-commit-info.test.ts | 28 +------------------ 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/apps/dokploy/__test__/deploy/builders-commit-info.test.ts b/apps/dokploy/__test__/deploy/builders-commit-info.test.ts index b6ccdb927c..82a80a6b31 100644 --- a/apps/dokploy/__test__/deploy/builders-commit-info.test.ts +++ b/apps/dokploy/__test__/deploy/builders-commit-info.test.ts @@ -1,30 +1,4 @@ -import { describe, expect, it, vi } from "vitest"; - -vi.mock("@dokploy/server/db", () => { - const createChainableMock = (): any => { - const chain = { - set: vi.fn(() => chain), - where: vi.fn(() => chain), - returning: vi.fn().mockResolvedValue([{}] as any), - from: vi.fn(() => chain), - innerJoin: vi.fn(() => chain), - then: (resolve: (v: any) => void) => { - resolve([]); - }, - } as any; - return chain; - }; - - return { - db: { - select: vi.fn(() => createChainableMock()), - insert: vi.fn(), - update: vi.fn(() => createChainableMock()), - delete: vi.fn(), - query: {}, - }, - }; -}); +import { describe, expect, it } from "vitest"; import { getDockerCommand } from "@dokploy/server/utils/builders/docker-file"; import { getHerokuCommand } from "@dokploy/server/utils/builders/heroku"; From 01b9b542c0fc3a02857ddffd7236d067c639d3b0 Mon Sep 17 00:00:00 2001 From: nurikk <1525421+nurikk@users.noreply.github.com> Date: Sun, 15 Mar 2026 14:44:52 +0000 Subject: [PATCH 6/7] test: slim down mock to only fields used by builders --- .../deploy/builders-commit-info.test.ts | 32 +------------------ 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/apps/dokploy/__test__/deploy/builders-commit-info.test.ts b/apps/dokploy/__test__/deploy/builders-commit-info.test.ts index 82a80a6b31..ef2f58628d 100644 --- a/apps/dokploy/__test__/deploy/builders-commit-info.test.ts +++ b/apps/dokploy/__test__/deploy/builders-commit-info.test.ts @@ -14,46 +14,16 @@ import type { ApplicationNested } from "@dokploy/server/utils/builders"; const createMockApplication = (overrides = {}): ApplicationNested => ({ - applicationId: "test-app-id", appName: "test-app", - name: "Test App", - sourceType: "git" as const, buildType: "dockerfile" as const, - buildPath: "/", - dockerfile: "Dockerfile", - dockerContextPath: null, - dockerBuildStage: null, env: null, buildArgs: null, buildSecrets: null, - publishDirectory: null, cleanCache: false, - createEnvFile: false, - isStaticSpa: false, - enableSubmodules: false, - serverId: null, - herokuVersion: "24", - railpackVersion: "0.1.0", - environmentId: "env-id", environment: { - projectId: "project-id", env: "", - name: "production", - project: { - name: "Test Project", - organizationId: "org-id", - env: "", - }, + project: { env: "" }, }, - mounts: [], - security: null, - redirects: [], - ports: [], - registry: null, - buildRegistry: null, - rollbackRegistry: null, - deployments: [], - domains: [], ...overrides, }) as unknown as ApplicationNested; From db42b4ca8c8d591e0a17176eea2ffdd2247ee135 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Sun, 15 Mar 2026 14:45:15 +0000 Subject: [PATCH 7/7] [autofix.ci] apply automated fixes --- .../deploy/builders-commit-info.test.ts | 132 +++++++++++++----- 1 file changed, 99 insertions(+), 33 deletions(-) diff --git a/apps/dokploy/__test__/deploy/builders-commit-info.test.ts b/apps/dokploy/__test__/deploy/builders-commit-info.test.ts index ef2f58628d..d02d335d5c 100644 --- a/apps/dokploy/__test__/deploy/builders-commit-info.test.ts +++ b/apps/dokploy/__test__/deploy/builders-commit-info.test.ts @@ -30,40 +30,64 @@ const createMockApplication = (overrides = {}): ApplicationNested => describe("Git Commit Info Helpers", () => { it("getGitCommitInfoCommands should return shell commands to extract commit info", () => { const commands = getGitCommitInfoCommands(); - expect(commands).toContain("DOKPLOY_COMMIT_SHORT=$(git rev-parse --short HEAD"); + expect(commands).toContain( + "DOKPLOY_COMMIT_SHORT=$(git rev-parse --short HEAD", + ); expect(commands).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse HEAD"); - expect(commands).toContain("DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s"); + expect(commands).toContain( + "DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s", + ); expect(commands).toContain('|| echo "unknown"'); }); it("getCommitInfoBuildArgs should return --build-arg flags", () => { const args = getCommitInfoBuildArgs(); - expect(args).toContain('--build-arg DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); - expect(args).toContain('--build-arg DOKPLOY_COMMIT_SHORT="$DOKPLOY_COMMIT_SHORT"'); - expect(args).toContain('--build-arg DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'); + expect(args).toContain( + '--build-arg DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"', + ); + expect(args).toContain( + '--build-arg DOKPLOY_COMMIT_SHORT="$DOKPLOY_COMMIT_SHORT"', + ); + expect(args).toContain( + '--build-arg DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"', + ); }); it("getCommitInfoEnvArgs should return --env flags", () => { const args = getCommitInfoEnvArgs(); expect(args).toContain('--env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); - expect(args).toContain('--env DOKPLOY_COMMIT_SHORT="$DOKPLOY_COMMIT_SHORT"'); - expect(args).toContain('--env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'); + expect(args).toContain( + '--env DOKPLOY_COMMIT_SHORT="$DOKPLOY_COMMIT_SHORT"', + ); + expect(args).toContain( + '--env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"', + ); }); }); describe("Dockerfile builder - commit info injection", () => { it("should include git commit info extraction commands", () => { const command = getDockerCommand(createMockApplication()); - expect(command).toContain("DOKPLOY_COMMIT_SHORT=$(git rev-parse --short HEAD"); + expect(command).toContain( + "DOKPLOY_COMMIT_SHORT=$(git rev-parse --short HEAD", + ); expect(command).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse HEAD"); - expect(command).toContain("DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s"); + expect(command).toContain( + "DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s", + ); }); it("should pass commit info as --build-arg to docker build", () => { const command = getDockerCommand(createMockApplication()); - expect(command).toContain('--build-arg DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); - expect(command).toContain('--build-arg DOKPLOY_COMMIT_SHORT="$DOKPLOY_COMMIT_SHORT"'); - expect(command).toContain('--build-arg DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'); + expect(command).toContain( + '--build-arg DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"', + ); + expect(command).toContain( + '--build-arg DOKPLOY_COMMIT_SHORT="$DOKPLOY_COMMIT_SHORT"', + ); + expect(command).toContain( + '--build-arg DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"', + ); }); it("should include commit info alongside user-defined build args", () => { @@ -71,7 +95,9 @@ describe("Dockerfile builder - commit info injection", () => { createMockApplication({ buildArgs: "MY_VAR=hello" }), ); expect(command).toContain("--build-arg MY_VAR"); - expect(command).toContain('--build-arg DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); + expect(command).toContain( + '--build-arg DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"', + ); }); }); @@ -80,18 +106,28 @@ describe("Nixpacks builder - commit info injection", () => { const command = getNixpacksCommand( createMockApplication({ buildType: "nixpacks" }), ); - expect(command).toContain("DOKPLOY_COMMIT_SHORT=$(git rev-parse --short HEAD"); + expect(command).toContain( + "DOKPLOY_COMMIT_SHORT=$(git rev-parse --short HEAD", + ); expect(command).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse HEAD"); - expect(command).toContain("DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s"); + expect(command).toContain( + "DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s", + ); }); it("should pass commit info as --env to nixpacks build", () => { const command = getNixpacksCommand( createMockApplication({ buildType: "nixpacks" }), ); - expect(command).toContain('--env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); - expect(command).toContain('--env DOKPLOY_COMMIT_SHORT="$DOKPLOY_COMMIT_SHORT"'); - expect(command).toContain('--env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'); + expect(command).toContain( + '--env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"', + ); + expect(command).toContain( + '--env DOKPLOY_COMMIT_SHORT="$DOKPLOY_COMMIT_SHORT"', + ); + expect(command).toContain( + '--env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"', + ); }); }); @@ -100,18 +136,28 @@ describe("Heroku builder - commit info injection", () => { const command = getHerokuCommand( createMockApplication({ buildType: "heroku_buildpacks" }), ); - expect(command).toContain("DOKPLOY_COMMIT_SHORT=$(git rev-parse --short HEAD"); + expect(command).toContain( + "DOKPLOY_COMMIT_SHORT=$(git rev-parse --short HEAD", + ); expect(command).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse HEAD"); - expect(command).toContain("DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s"); + expect(command).toContain( + "DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s", + ); }); it("should pass commit info as --env to pack build", () => { const command = getHerokuCommand( createMockApplication({ buildType: "heroku_buildpacks" }), ); - expect(command).toContain('--env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); - expect(command).toContain('--env DOKPLOY_COMMIT_SHORT="$DOKPLOY_COMMIT_SHORT"'); - expect(command).toContain('--env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'); + expect(command).toContain( + '--env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"', + ); + expect(command).toContain( + '--env DOKPLOY_COMMIT_SHORT="$DOKPLOY_COMMIT_SHORT"', + ); + expect(command).toContain( + '--env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"', + ); }); }); @@ -120,18 +166,28 @@ describe("Paketo builder - commit info injection", () => { const command = getPaketoCommand( createMockApplication({ buildType: "paketo_buildpacks" }), ); - expect(command).toContain("DOKPLOY_COMMIT_SHORT=$(git rev-parse --short HEAD"); + expect(command).toContain( + "DOKPLOY_COMMIT_SHORT=$(git rev-parse --short HEAD", + ); expect(command).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse HEAD"); - expect(command).toContain("DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s"); + expect(command).toContain( + "DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s", + ); }); it("should pass commit info as --env to pack build", () => { const command = getPaketoCommand( createMockApplication({ buildType: "paketo_buildpacks" }), ); - expect(command).toContain('--env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); - expect(command).toContain('--env DOKPLOY_COMMIT_SHORT="$DOKPLOY_COMMIT_SHORT"'); - expect(command).toContain('--env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'); + expect(command).toContain( + '--env DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"', + ); + expect(command).toContain( + '--env DOKPLOY_COMMIT_SHORT="$DOKPLOY_COMMIT_SHORT"', + ); + expect(command).toContain( + '--env DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"', + ); }); }); @@ -140,17 +196,27 @@ describe("Railpack builder - commit info injection", () => { const command = getRailpackCommand( createMockApplication({ buildType: "railpack" }), ); - expect(command).toContain("DOKPLOY_COMMIT_SHORT=$(git rev-parse --short HEAD"); + expect(command).toContain( + "DOKPLOY_COMMIT_SHORT=$(git rev-parse --short HEAD", + ); expect(command).toContain("DOKPLOY_COMMIT_HASH=$(git rev-parse HEAD"); - expect(command).toContain("DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s"); + expect(command).toContain( + "DOKPLOY_COMMIT_MESSAGE=$(git log -1 --pretty=%s", + ); }); it("should pass commit info as --build-arg to docker buildx", () => { const command = getRailpackCommand( createMockApplication({ buildType: "railpack" }), ); - expect(command).toContain('--build-arg DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"'); - expect(command).toContain('--build-arg DOKPLOY_COMMIT_SHORT="$DOKPLOY_COMMIT_SHORT"'); - expect(command).toContain('--build-arg DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"'); + expect(command).toContain( + '--build-arg DOKPLOY_COMMIT_HASH="$DOKPLOY_COMMIT_HASH"', + ); + expect(command).toContain( + '--build-arg DOKPLOY_COMMIT_SHORT="$DOKPLOY_COMMIT_SHORT"', + ); + expect(command).toContain( + '--build-arg DOKPLOY_COMMIT_MESSAGE="$DOKPLOY_COMMIT_MESSAGE"', + ); }); });