Skip to content

Commit

Permalink
Merge pull request #990 from Dokploy/986-error-to-save-the-deployment
Browse files Browse the repository at this point in the history
fix: omit macos files and create folders every time
  • Loading branch information
Siumauricio authored Dec 25, 2024
2 parents 229a9a3 + 364c2e1 commit a325b29
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,13 @@ import {
import { api } from "@/utils/api";
import { Layers, Loader2 } from "lucide-react";
import React from "react";
import { columns } from "./columns";
import { type ApplicationList, columns } from "./columns";
import { DataTable } from "./data-table";

interface Props {
serverId?: string;
}

interface ApplicationList {
ID: string;
Image: string;
Mode: string;
Name: string;
Ports: string;
Replicas: string;
CurrentState: string;
DesiredState: string;
Error: string;
Node: string;
}

export const ShowNodeApplications = ({ serverId }: Props) => {
const { data: NodeApps, isLoading: NodeAppsLoading } =
api.swarm.getNodeApps.useQuery({ serverId });
Expand Down
4 changes: 2 additions & 2 deletions apps/dokploy/server/api/routers/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,9 @@ export const applicationRouter = createTRPCRouter({
});
}

updateApplication(input.applicationId as string, {
await updateApplication(input.applicationId as string, {
sourceType: "drop",
dropBuildPath: input.dropBuildPath,
dropBuildPath: input.dropBuildPath || "",
});

await unzipDrop(zipFile, app);
Expand Down
28 changes: 20 additions & 8 deletions packages/server/src/utils/builders/drop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export const unzipDrop = async (zipFile: File, application: Application) => {
const buffer = Buffer.from(arrayBuffer);

const zip = new AdmZip(buffer);
const zipEntries = zip.getEntries();
const zipEntries = zip
.getEntries()
.filter((entry) => !entry.entryName.startsWith("__MACOSX"));

const rootEntries = zipEntries.filter(
(entry) =>
Expand Down Expand Up @@ -59,14 +61,22 @@ export const unzipDrop = async (zipFile: File, application: Application) => {

if (!filePath) continue;

const fullPath = path.join(outputPath, filePath);
const fullPath = path.join(outputPath, filePath).replace(/\\/g, "/");

if (application.serverId) {
if (entry.isDirectory) {
await execAsyncRemote(application.serverId, `mkdir -p ${fullPath}`);
} else {
if (!entry.isDirectory) {
if (sftp === null) throw new Error("No SFTP connection available");
await uploadFileToServer(sftp, entry.getData(), fullPath);
try {
const dirPath = path.dirname(fullPath);
await execAsyncRemote(
application.serverId,
`mkdir -p "${dirPath}"`,
);
await uploadFileToServer(sftp, entry.getData(), fullPath);
} catch (err) {
console.error(`Error uploading file ${fullPath}:`, err);
throw err;
}
}
} else {
if (entry.isDirectory) {
Expand Down Expand Up @@ -103,7 +113,6 @@ const getSFTPConnection = async (serverId: string): Promise<SFTPWrapper> => {
port: server.port,
username: server.username,
privateKey: server.sshKey?.privateKey,
timeout: 99999,
});
});
};
Expand All @@ -115,7 +124,10 @@ const uploadFileToServer = (
): Promise<void> => {
return new Promise((resolve, reject) => {
sftp.writeFile(remotePath, data, (err) => {
if (err) return reject(err);
if (err) {
console.error(`SFTP write error for ${remotePath}:`, err);
return reject(err);
}
resolve();
});
});
Expand Down

0 comments on commit a325b29

Please sign in to comment.