Skip to content

Commit a897fe6

Browse files
authored
Merge pull request #3640 from Dokploy/3636-bug-build-server-env-file-creation-fails---no-such-file-or-directory-on-remote-build-server
3636 bug build server env file creation fails no such file or directory on remote build server
2 parents 4bc494e + a0d9f06 commit a897fe6

6 files changed

Lines changed: 18 additions & 31 deletions

File tree

apps/dokploy/components/dashboard/application/logs/show.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export const ShowDockerLogs = ({ appName, serverId }: Props) => {
175175
services?.find((c) => c.containerId === containerId)?.error && (
176176
<div className="rounded-md bg-destructive/10 border border-destructive/20 px-3 py-2 text-sm text-destructive">
177177
<span className="font-medium">Error: </span>
178-
{services.find((c) => c.containerId === containerId)?.error}
178+
{services?.find((c) => c.containerId === containerId)?.error}
179179
</div>
180180
)}
181181
<DockerLogs

apps/dokploy/server/wss/listen-deployment.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,13 @@ export const setupDeploymentLogsWebSocketServer = (
3434

3535
// Generate unique connection ID for tracking
3636
const connectionId = `deployment-logs-${Date.now()}-${Math.random().toString(36).substring(7)}`;
37-
3837
if (!logPath) {
3938
console.log(`[${connectionId}] logPath no provided`);
4039
ws.close(4000, "logPath no provided");
4140
return;
4241
}
4342

44-
if (!readValidDirectory(logPath)) {
43+
if (!readValidDirectory(logPath, serverId)) {
4544
ws.close(4000, "Invalid log path");
4645
return;
4746
}

apps/dokploy/server/wss/utils.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ export const isValidShell = (shell: string): boolean => {
3232
return allowedShells.includes(shell);
3333
};
3434

35-
export const readValidDirectory = (directory: string) => {
36-
const { BASE_PATH } = paths();
35+
export const readValidDirectory = (
36+
directory: string,
37+
serverId?: string | null,
38+
) => {
39+
const { BASE_PATH } = paths(!!serverId);
3740

3841
const resolvedBase = path.resolve(BASE_PATH);
3942
const resolvedDir = path.resolve(directory);

packages/server/src/services/application.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ export const deployApplication = async ({
174174
}) => {
175175
const application = await findApplicationById(applicationId);
176176
const serverId = application.buildServerId || application.serverId;
177+
const applicationEntity = {
178+
...application,
179+
serverId: serverId,
180+
};
177181

178182
const buildLink = `${await getDokployUrl()}/dashboard/project/${application.environment.projectId}/environment/${application.environmentId}/services/application/${application.applicationId}?tab=deployments`;
179183
const deployment = await createDeployment({
@@ -185,15 +189,15 @@ export const deployApplication = async ({
185189
try {
186190
let command = "set -e;";
187191
if (application.sourceType === "github") {
188-
command += await cloneGithubRepository(application);
192+
command += await cloneGithubRepository(applicationEntity);
189193
} else if (application.sourceType === "gitlab") {
190-
command += await cloneGitlabRepository(application);
194+
command += await cloneGitlabRepository(applicationEntity);
191195
} else if (application.sourceType === "gitea") {
192-
command += await cloneGiteaRepository(application);
196+
command += await cloneGiteaRepository(applicationEntity);
193197
} else if (application.sourceType === "bitbucket") {
194-
command += await cloneBitbucketRepository(application);
198+
command += await cloneBitbucketRepository(applicationEntity);
195199
} else if (application.sourceType === "git") {
196-
command += await cloneGitRepository(application);
200+
command += await cloneGitRepository(applicationEntity);
197201
} else if (application.sourceType === "docker") {
198202
command += await buildRemoteDocker(application);
199203
}
@@ -258,7 +262,6 @@ export const deployApplication = async ({
258262
type: "application",
259263
serverId: serverId,
260264
});
261-
262265
if (commitInfo) {
263266
await updateDeployment(deployment.deploymentId, {
264267
title: commitInfo.message,

packages/server/src/utils/builders/utils.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,6 @@
1-
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
21
import { dirname, join } from "node:path";
32
import { encodeBase64, prepareEnvironmentVariables } from "../docker/utils";
43

5-
export const createEnvFile = (
6-
directory: string,
7-
env: string | null,
8-
projectEnv?: string | null,
9-
environmentEnv?: string | null,
10-
) => {
11-
const envFilePath = join(dirname(directory), ".env");
12-
if (!existsSync(dirname(envFilePath))) {
13-
mkdirSync(dirname(envFilePath), { recursive: true });
14-
}
15-
const envFileContent = prepareEnvironmentVariables(
16-
env,
17-
projectEnv,
18-
environmentEnv,
19-
).join("\n");
20-
writeFileSync(envFilePath, envFileContent);
21-
};
22-
234
export const createEnvFileCommand = (
245
directory: string,
256
env: string | null,

packages/server/src/utils/filesystem/directory.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ export const removeMonitoringDirectory = async (
102102
};
103103

104104
export const getBuildAppDirectory = (application: Application) => {
105-
const { APPLICATIONS_PATH } = paths(!!application.serverId);
105+
const serverId = application.buildServerId || application.serverId;
106+
const { APPLICATIONS_PATH } = paths(!!serverId);
106107
const { appName, buildType, sourceType, customGitBuildPath, dockerfile } =
107108
application;
108109
let buildPath = "";

0 commit comments

Comments
 (0)