From a0d9f06a35770eca5634bed5e7dfe0bd5c031e88 Mon Sep 17 00:00:00 2001 From: Mauricio Siu Date: Sat, 7 Feb 2026 23:34:35 -0600 Subject: [PATCH] fix(logs): ensure safe access to service error in ShowDockerLogs component - Updated the ShowDockerLogs component to use optional chaining when accessing the error property of services, preventing potential runtime errors. - Refactored the deployApplication function to create an applicationEntity object, ensuring consistent use of serverId across repository cloning functions. - Removed unused createEnvFile function from utils, streamlining the codebase. --- .../dashboard/application/logs/show.tsx | 2 +- packages/server/src/services/application.ts | 15 +++++++++------ packages/server/src/utils/builders/utils.ts | 19 ------------------- .../server/src/utils/filesystem/directory.ts | 3 ++- 4 files changed, 12 insertions(+), 27 deletions(-) diff --git a/apps/dokploy/components/dashboard/application/logs/show.tsx b/apps/dokploy/components/dashboard/application/logs/show.tsx index d1f5b1669..941ddef50 100644 --- a/apps/dokploy/components/dashboard/application/logs/show.tsx +++ b/apps/dokploy/components/dashboard/application/logs/show.tsx @@ -175,7 +175,7 @@ export const ShowDockerLogs = ({ appName, serverId }: Props) => { services?.find((c) => c.containerId === containerId)?.error && (
Error: - {services.find((c) => c.containerId === containerId)?.error} + {services?.find((c) => c.containerId === containerId)?.error}
)} { const application = await findApplicationById(applicationId); const serverId = application.buildServerId || application.serverId; + const applicationEntity = { + ...application, + serverId: serverId, + }; const buildLink = `${await getDokployUrl()}/dashboard/project/${application.environment.projectId}/environment/${application.environmentId}/services/application/${application.applicationId}?tab=deployments`; const deployment = await createDeployment({ @@ -185,15 +189,15 @@ export const deployApplication = async ({ try { let command = "set -e;"; if (application.sourceType === "github") { - command += await cloneGithubRepository(application); + command += await cloneGithubRepository(applicationEntity); } else if (application.sourceType === "gitlab") { - command += await cloneGitlabRepository(application); + command += await cloneGitlabRepository(applicationEntity); } else if (application.sourceType === "gitea") { - command += await cloneGiteaRepository(application); + command += await cloneGiteaRepository(applicationEntity); } else if (application.sourceType === "bitbucket") { - command += await cloneBitbucketRepository(application); + command += await cloneBitbucketRepository(applicationEntity); } else if (application.sourceType === "git") { - command += await cloneGitRepository(application); + command += await cloneGitRepository(applicationEntity); } else if (application.sourceType === "docker") { command += await buildRemoteDocker(application); } @@ -258,7 +262,6 @@ export const deployApplication = async ({ type: "application", serverId: serverId, }); - if (commitInfo) { await updateDeployment(deployment.deploymentId, { title: commitInfo.message, diff --git a/packages/server/src/utils/builders/utils.ts b/packages/server/src/utils/builders/utils.ts index cce8dfd95..97ea69ef8 100644 --- a/packages/server/src/utils/builders/utils.ts +++ b/packages/server/src/utils/builders/utils.ts @@ -1,25 +1,6 @@ -import { existsSync, mkdirSync, writeFileSync } from "node:fs"; import { dirname, join } from "node:path"; import { encodeBase64, prepareEnvironmentVariables } from "../docker/utils"; -export const createEnvFile = ( - directory: string, - env: string | null, - projectEnv?: string | null, - environmentEnv?: string | null, -) => { - const envFilePath = join(dirname(directory), ".env"); - if (!existsSync(dirname(envFilePath))) { - mkdirSync(dirname(envFilePath), { recursive: true }); - } - const envFileContent = prepareEnvironmentVariables( - env, - projectEnv, - environmentEnv, - ).join("\n"); - writeFileSync(envFilePath, envFileContent); -}; - export const createEnvFileCommand = ( directory: string, env: string | null, diff --git a/packages/server/src/utils/filesystem/directory.ts b/packages/server/src/utils/filesystem/directory.ts index f80f6ba31..a64d4cc24 100644 --- a/packages/server/src/utils/filesystem/directory.ts +++ b/packages/server/src/utils/filesystem/directory.ts @@ -102,7 +102,8 @@ export const removeMonitoringDirectory = async ( }; export const getBuildAppDirectory = (application: Application) => { - const { APPLICATIONS_PATH } = paths(!!application.serverId); + const serverId = application.buildServerId || application.serverId; + const { APPLICATIONS_PATH } = paths(!!serverId); const { appName, buildType, sourceType, customGitBuildPath, dockerfile } = application; let buildPath = "";