mirror of
https://github.com/LukeHagar/dokploy.git
synced 2025-12-09 12:27:48 +00:00
@@ -10,6 +10,7 @@
|
||||
"dependencies": {
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0",
|
||||
"@dokploy/builders": "workspace:*",
|
||||
"@hono/node-server": "^1.12.1",
|
||||
"hono": "^4.5.8",
|
||||
"dotenv": "^16.3.1",
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
ALTER TABLE "ssh-key" ADD COLUMN "privateKey" text DEFAULT '' NOT NULL;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -267,13 +267,6 @@
|
||||
"when": 1726988289562,
|
||||
"tag": "0037_legal_namor",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 38,
|
||||
"version": "6",
|
||||
"when": 1727903587684,
|
||||
"tag": "0038_mushy_blindfold",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -34,6 +34,7 @@
|
||||
"test": "vitest --config __test__/vitest.config.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@dokploy/builders": "workspace:*",
|
||||
"@codemirror/lang-json": "^6.0.1",
|
||||
"@codemirror/lang-yaml": "^6.1.1",
|
||||
"@codemirror/language": "^6.10.1",
|
||||
|
||||
@@ -14,7 +14,6 @@ import {
|
||||
findSSHKeyById,
|
||||
removeSSHKeyById,
|
||||
updateSSHKeyById,
|
||||
execAsync,
|
||||
} from "@dokploy/builders";
|
||||
|
||||
export const sshRouter = createTRPCRouter({
|
||||
|
||||
@@ -3,30 +3,28 @@ import { z } from "zod";
|
||||
export const sshKeyCreate = z.object({
|
||||
name: z.string().min(1),
|
||||
description: z.string().optional(),
|
||||
publicKey: z.string(),
|
||||
// .refine(
|
||||
// (key) => {
|
||||
// // const rsaPubPattern = /^ssh-rsa\s+([A-Za-z0-9+/=]+)\s*(.*)?\s*$/;
|
||||
// // const ed25519PubPattern = /^ssh-ed25519\s+([A-Za-z0-9+/=]+)\s*(.*)?\s*$/;
|
||||
// // return rsaPubPattern.test(key) || ed25519PubPattern.test(key);
|
||||
// },
|
||||
// {
|
||||
// message: "Invalid public key format",
|
||||
// },
|
||||
// )
|
||||
privateKey: z.string(),
|
||||
// .refine(
|
||||
// (key) => {
|
||||
// // const rsaPrivPattern =
|
||||
// // /^-----BEGIN RSA PRIVATE KEY-----\n([A-Za-z0-9+/=\n]+)-----END RSA PRIVATE KEY-----\s*$/;
|
||||
// // const ed25519PrivPattern =
|
||||
// // /^-----BEGIN OPENSSH PRIVATE KEY-----\n([A-Za-z0-9+/=\n]+)-----END OPENSSH PRIVATE KEY-----\s*$/;
|
||||
// // return rsaPrivPattern.test(key) || ed25519PrivPattern.test(key);
|
||||
// },
|
||||
// {
|
||||
// message: "Invalid private key format",
|
||||
// },
|
||||
// ),
|
||||
publicKey: z.string().refine(
|
||||
(key) => {
|
||||
const rsaPubPattern = /^ssh-rsa\s+([A-Za-z0-9+/=]+)\s*(.*)?\s*$/;
|
||||
const ed25519PubPattern = /^ssh-ed25519\s+([A-Za-z0-9+/=]+)\s*(.*)?\s*$/;
|
||||
return rsaPubPattern.test(key) || ed25519PubPattern.test(key);
|
||||
},
|
||||
{
|
||||
message: "Invalid public key format",
|
||||
},
|
||||
),
|
||||
privateKey: z.string().refine(
|
||||
(key) => {
|
||||
const rsaPrivPattern =
|
||||
/^-----BEGIN RSA PRIVATE KEY-----\n([A-Za-z0-9+/=\n]+)-----END RSA PRIVATE KEY-----\s*$/;
|
||||
const ed25519PrivPattern =
|
||||
/^-----BEGIN OPENSSH PRIVATE KEY-----\n([A-Za-z0-9+/=\n]+)-----END OPENSSH PRIVATE KEY-----\s*$/;
|
||||
return rsaPrivPattern.test(key) || ed25519PrivPattern.test(key);
|
||||
},
|
||||
{
|
||||
message: "Invalid private key format",
|
||||
},
|
||||
),
|
||||
});
|
||||
|
||||
export const sshKeyUpdate = sshKeyCreate.pick({
|
||||
|
||||
@@ -2,7 +2,11 @@ import type http from "node:http";
|
||||
import { spawn } from "node-pty";
|
||||
import { Client } from "ssh2";
|
||||
import { WebSocketServer } from "ws";
|
||||
import { findServerById, validateWebSocketRequest } from "@dokploy/builders";
|
||||
import {
|
||||
findServerById,
|
||||
readSSHKey,
|
||||
validateWebSocketRequest,
|
||||
} from "@dokploy/builders";
|
||||
import { getShell } from "./utils";
|
||||
|
||||
export const setupDockerContainerLogsWebSocketServer = (
|
||||
@@ -48,6 +52,7 @@ export const setupDockerContainerLogsWebSocketServer = (
|
||||
const server = await findServerById(serverId);
|
||||
|
||||
if (!server.sshKeyId) return;
|
||||
const keys = await readSSHKey(server.sshKeyId);
|
||||
const client = new Client();
|
||||
new Promise<void>((resolve, reject) => {
|
||||
client
|
||||
@@ -79,7 +84,7 @@ export const setupDockerContainerLogsWebSocketServer = (
|
||||
host: server.ipAddress,
|
||||
port: server.port,
|
||||
username: server.username,
|
||||
privateKey: server.sshKey?.privateKey,
|
||||
privateKey: keys.privateKey,
|
||||
timeout: 99999,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,7 +2,11 @@ import type http from "node:http";
|
||||
import { spawn } from "node-pty";
|
||||
import { Client } from "ssh2";
|
||||
import { WebSocketServer } from "ws";
|
||||
import { findServerById, validateWebSocketRequest } from "@dokploy/builders";
|
||||
import {
|
||||
findServerById,
|
||||
readSSHKey,
|
||||
validateWebSocketRequest,
|
||||
} from "@dokploy/builders";
|
||||
import { getShell } from "./utils";
|
||||
|
||||
export const setupDockerContainerTerminalWebSocketServer = (
|
||||
@@ -49,6 +53,7 @@ export const setupDockerContainerTerminalWebSocketServer = (
|
||||
if (!server.sshKeyId)
|
||||
throw new Error("No SSH key available for this server");
|
||||
|
||||
const keys = await readSSHKey(server.sshKeyId);
|
||||
const conn = new Client();
|
||||
let stdout = "";
|
||||
let stderr = "";
|
||||
@@ -104,7 +109,7 @@ export const setupDockerContainerTerminalWebSocketServer = (
|
||||
host: server.ipAddress,
|
||||
port: server.port,
|
||||
username: server.username,
|
||||
privateKey: server.sshKey?.privateKey,
|
||||
privateKey: keys.privateKey,
|
||||
timeout: 99999,
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -2,7 +2,11 @@ import { spawn } from "node:child_process";
|
||||
import type http from "node:http";
|
||||
import { Client } from "ssh2";
|
||||
import { WebSocketServer } from "ws";
|
||||
import { findServerById, validateWebSocketRequest } from "@dokploy/builders";
|
||||
import {
|
||||
findServerById,
|
||||
readSSHKey,
|
||||
validateWebSocketRequest,
|
||||
} from "@dokploy/builders";
|
||||
|
||||
export const setupDeploymentLogsWebSocketServer = (
|
||||
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>,
|
||||
@@ -47,6 +51,7 @@ export const setupDeploymentLogsWebSocketServer = (
|
||||
const server = await findServerById(serverId);
|
||||
|
||||
if (!server.sshKeyId) return;
|
||||
const keys = await readSSHKey(server.sshKeyId);
|
||||
const client = new Client();
|
||||
new Promise<void>((resolve, reject) => {
|
||||
client
|
||||
@@ -78,7 +83,7 @@ export const setupDeploymentLogsWebSocketServer = (
|
||||
host: server.ipAddress,
|
||||
port: server.port,
|
||||
username: server.username,
|
||||
privateKey: server.sshKey?.privateKey,
|
||||
privateKey: keys.privateKey,
|
||||
timeout: 99999,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
createDefaultServerTraefikConfig,
|
||||
createDefaultTraefikConfig,
|
||||
initializeTraefik,
|
||||
} from "../../packages/builders/src";
|
||||
} from "@dokploy/builders";
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
|
||||
@@ -26,13 +26,9 @@
|
||||
/* Path Aliases */
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@dokploy/builders": ["../../packages/builders"], // Apunta a las fuentes de `builders`
|
||||
"@dokploy/builders/*": ["../../packages/builders/src/*"]
|
||||
"@/*": ["./*"]
|
||||
}
|
||||
},
|
||||
"references": [
|
||||
{ "path": "../../packages/builders" } // Referencia explícita a builders
|
||||
],
|
||||
|
||||
"include": [
|
||||
"next-env.d.ts",
|
||||
|
||||
@@ -9,13 +9,8 @@
|
||||
"moduleResolution": "Node",
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@dokploy/builders": ["../../packages/builders/src"], // Apunta a las fuentes de `builders`
|
||||
"@dokploy/builders/*": ["../../packages/builders/src/*"]
|
||||
"@/*": ["./*"]
|
||||
}
|
||||
},
|
||||
"references": [
|
||||
{ "path": "../../packages/builders" } // Referencia explícita a builders
|
||||
],
|
||||
|
||||
"include": ["next-env.d.ts", "./server/**/*"]
|
||||
}
|
||||
|
||||
1
apps/dokploy/tsconfig.tsbuildinfo
Normal file
1
apps/dokploy/tsconfig.tsbuildinfo
Normal file
File diff suppressed because one or more lines are too long
@@ -1,14 +1,12 @@
|
||||
{
|
||||
"name": "dokploy",
|
||||
"private": true,
|
||||
"workspaces": ["apps/*", "packages/*"],
|
||||
"scripts": {
|
||||
"dokploy:setup": "pnpm --filter=dokploy run setup",
|
||||
"dokploy:dev": "pnpm --filter=dokploy run dev",
|
||||
"dokploy:build": "pnpm --filter=dokploy run build",
|
||||
"dokploy:start": "pnpm --filter=dokploy run start",
|
||||
"test": "pnpm --filter=dokploy run test",
|
||||
"builder:dev": "pnpm --filter=builders run dev",
|
||||
"docker:build:canary": "./apps/dokploy/docker/build.sh canary",
|
||||
"docs:dev": "pnpm --filter=docs run dev",
|
||||
"docs:build": "pnpm --filter=docs run build",
|
||||
|
||||
@@ -4,8 +4,10 @@ import path from "node:path";
|
||||
build({
|
||||
entryPoints: ["./src/**/*.ts", "./src/**/*.tsx"], // Punto de entrada principal de tu aplicación
|
||||
outdir: "dist",
|
||||
bundle: false, // Cambia a true si deseas bundlear tu código
|
||||
platform: "node",
|
||||
format: "esm",
|
||||
target: ["esnext"],
|
||||
sourcemap: false,
|
||||
tsconfig: "./tsconfig.server.json",
|
||||
plugins: [
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "@dokploy/builders",
|
||||
"version": "1.0.0",
|
||||
"main": "src/index.ts",
|
||||
"types": "src/index.ts",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "tsc --project tsconfig.server.json --watch && tsc-alias -p tsconfig.server.json",
|
||||
"dev": "tsup --config ./tsup.ts --watch",
|
||||
"build": "tsc --project tsconfig.server.json && tsc-alias -p tsconfig.server.json",
|
||||
"esbuild": "tsx --watch ./esbuild.config.ts & tsc-alias -p tsconfig.server.json --watch",
|
||||
"esbuild": "tsx ./esbuild.config.ts",
|
||||
"build:types": "tsc --emitDeclarationOnly --experimenta-dts"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@@ -12,7 +12,6 @@ export const sshKeys = pgTable("ssh-key", {
|
||||
.notNull()
|
||||
.primaryKey()
|
||||
.$defaultFn(() => nanoid()),
|
||||
privateKey: text("privateKey").notNull().default(""),
|
||||
publicKey: text("publicKey").notNull(),
|
||||
name: text("name").notNull(),
|
||||
description: text("description"),
|
||||
@@ -38,7 +37,6 @@ export const apiCreateSshKey = createSchema
|
||||
.pick({
|
||||
name: true,
|
||||
description: true,
|
||||
privateKey: true,
|
||||
publicKey: true,
|
||||
})
|
||||
.merge(sshKeyCreate.pick({ privateKey: true }));
|
||||
|
||||
@@ -3,30 +3,28 @@ import { z } from "zod";
|
||||
export const sshKeyCreate = z.object({
|
||||
name: z.string().min(1),
|
||||
description: z.string().optional(),
|
||||
publicKey: z.string(),
|
||||
// .refine(
|
||||
// (key) => {
|
||||
// const rsaPubPattern = /^ssh-rsa\s+([A-Za-z0-9+/=]+)\s*(.*)?\s*$/;
|
||||
// const ed25519PubPattern = /^ssh-ed25519\s+([A-Za-z0-9+/=]+)\s*(.*)?\s*$/;
|
||||
// return rsaPubPattern.test(key) || ed25519PubPattern.test(key);
|
||||
// },
|
||||
// {
|
||||
// message: "Invalid public key format",
|
||||
// },
|
||||
// )
|
||||
privateKey: z.string(),
|
||||
// .refine(
|
||||
// (key) => {
|
||||
// const rsaPrivPattern =
|
||||
// /^-----BEGIN RSA PRIVATE KEY-----\n([A-Za-z0-9+/=\n]+)-----END RSA PRIVATE KEY-----\s*$/;
|
||||
// const ed25519PrivPattern =
|
||||
// /^-----BEGIN OPENSSH PRIVATE KEY-----\n([A-Za-z0-9+/=\n]+)-----END OPENSSH PRIVATE KEY-----\s*$/;
|
||||
// return rsaPrivPattern.test(key) || ed25519PrivPattern.test(key);
|
||||
// },
|
||||
// {
|
||||
// message: "Invalid private key format",
|
||||
// },
|
||||
// ),
|
||||
publicKey: z.string().refine(
|
||||
(key) => {
|
||||
const rsaPubPattern = /^ssh-rsa\s+([A-Za-z0-9+/=]+)\s*(.*)?\s*$/;
|
||||
const ed25519PubPattern = /^ssh-ed25519\s+([A-Za-z0-9+/=]+)\s*(.*)?\s*$/;
|
||||
return rsaPubPattern.test(key) || ed25519PubPattern.test(key);
|
||||
},
|
||||
{
|
||||
message: "Invalid public key format",
|
||||
},
|
||||
),
|
||||
privateKey: z.string().refine(
|
||||
(key) => {
|
||||
const rsaPrivPattern =
|
||||
/^-----BEGIN RSA PRIVATE KEY-----\n([A-Za-z0-9+/=\n]+)-----END RSA PRIVATE KEY-----\s*$/;
|
||||
const ed25519PrivPattern =
|
||||
/^-----BEGIN OPENSSH PRIVATE KEY-----\n([A-Za-z0-9+/=\n]+)-----END OPENSSH PRIVATE KEY-----\s*$/;
|
||||
return rsaPrivPattern.test(key) || ed25519PrivPattern.test(key);
|
||||
},
|
||||
{
|
||||
message: "Invalid private key format",
|
||||
},
|
||||
),
|
||||
});
|
||||
|
||||
export const sshKeyUpdate = sshKeyCreate.pick({
|
||||
|
||||
@@ -6,10 +6,14 @@ import {
|
||||
type apiUpdateSshKey,
|
||||
sshKeys,
|
||||
} from "@/server/db/schema";
|
||||
import { removeSSHKey, saveSSHKey } from "@/server/utils/filesystem/ssh";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { eq } from "drizzle-orm";
|
||||
|
||||
export const createSshKey = async (input: typeof apiCreateSshKey._type) => {
|
||||
export const createSshKey = async ({
|
||||
privateKey,
|
||||
...input
|
||||
}: typeof apiCreateSshKey._type) => {
|
||||
await db.transaction(async (tx) => {
|
||||
const sshKey = await tx
|
||||
.insert(sshKeys)
|
||||
@@ -18,6 +22,10 @@ export const createSshKey = async (input: typeof apiCreateSshKey._type) => {
|
||||
.then((response) => response[0])
|
||||
.catch((e) => console.error(e));
|
||||
|
||||
if (sshKey) {
|
||||
saveSSHKey(sshKey.sshKeyId, sshKey.publicKey, privateKey);
|
||||
}
|
||||
|
||||
if (!sshKey) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
@@ -36,6 +44,8 @@ export const removeSSHKeyById = async (
|
||||
.where(eq(sshKeys.sshKeyId, sshKeyId))
|
||||
.returning();
|
||||
|
||||
removeSSHKey(sshKeyId);
|
||||
|
||||
return result[0];
|
||||
};
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
} from "@/server/setup/traefik-setup";
|
||||
import { Client } from "ssh2";
|
||||
import { recreateDirectory } from "../utils/filesystem/directory";
|
||||
import { readSSHKey } from "../utils/filesystem/ssh";
|
||||
|
||||
import slug from "slugify";
|
||||
|
||||
@@ -69,7 +70,13 @@ const installRequirements = async (serverId: string, logPath: string) => {
|
||||
writeStream.close();
|
||||
throw new Error("No SSH Key found");
|
||||
}
|
||||
const keys = await readSSHKey(server.sshKeyId);
|
||||
|
||||
if (!keys.privateKey) {
|
||||
writeStream.write("❌ No SSH Key found");
|
||||
writeStream.close();
|
||||
throw new Error("No SSH Key found");
|
||||
}
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
client
|
||||
.once("ready", () => {
|
||||
@@ -135,7 +142,7 @@ const installRequirements = async (serverId: string, logPath: string) => {
|
||||
host: server.ipAddress,
|
||||
port: server.port,
|
||||
username: server.username,
|
||||
privateKey: server.sshKey?.privateKey,
|
||||
privateKey: keys.privateKey,
|
||||
timeout: 99999,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
recreateDirectory,
|
||||
recreateDirectoryRemote,
|
||||
} from "../filesystem/directory";
|
||||
import { readSSHKey } from "../filesystem/ssh";
|
||||
import { execAsyncRemote } from "../process/execAsync";
|
||||
|
||||
export const unzipDrop = async (zipFile: File, application: Application) => {
|
||||
@@ -89,6 +90,7 @@ const getSFTPConnection = async (serverId: string): Promise<SFTPWrapper> => {
|
||||
const server = await findServerById(serverId);
|
||||
if (!server.sshKeyId) throw new Error("No SSH key available for this server");
|
||||
|
||||
const keys = await readSSHKey(server.sshKeyId);
|
||||
return new Promise((resolve, reject) => {
|
||||
const conn = new Client();
|
||||
conn
|
||||
@@ -102,7 +104,7 @@ const getSFTPConnection = async (serverId: string): Promise<SFTPWrapper> => {
|
||||
host: server.ipAddress,
|
||||
port: server.port,
|
||||
username: server.username,
|
||||
privateKey: server.sshKey?.privateKey,
|
||||
privateKey: keys.privateKey,
|
||||
timeout: 99999,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,26 +1,99 @@
|
||||
import { utils } from "ssh2";
|
||||
import * as fs from "node:fs";
|
||||
import * as path from "node:path";
|
||||
import { paths } from "@/server/constants";
|
||||
import { spawnAsync } from "../process/spawnAsync";
|
||||
|
||||
export const generateSSHKey = async (type: "rsa" | "ed25519" = "rsa") => {
|
||||
export const readSSHKey = async (id: string) => {
|
||||
const { SSH_PATH } = paths();
|
||||
try {
|
||||
if (type === "rsa") {
|
||||
const keys = utils.generateKeyPairSync("rsa", {
|
||||
bits: 4096,
|
||||
comment: "dokploy",
|
||||
});
|
||||
return {
|
||||
privateKey: keys.private,
|
||||
publicKey: keys.public,
|
||||
};
|
||||
if (!fs.existsSync(SSH_PATH)) {
|
||||
fs.mkdirSync(SSH_PATH, { recursive: true });
|
||||
}
|
||||
const keys = utils.generateKeyPairSync("ed25519", {
|
||||
comment: "dokploy",
|
||||
});
|
||||
|
||||
return {
|
||||
privateKey: keys.private,
|
||||
publicKey: keys.public,
|
||||
privateKey: fs.readFileSync(path.join(SSH_PATH, `${id}_rsa`), {
|
||||
encoding: "utf-8",
|
||||
}),
|
||||
publicKey: fs.readFileSync(path.join(SSH_PATH, `${id}_rsa.pub`), {
|
||||
encoding: "utf-8",
|
||||
}),
|
||||
};
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const saveSSHKey = async (
|
||||
id: string,
|
||||
publicKey: string,
|
||||
privateKey: string,
|
||||
) => {
|
||||
const { SSH_PATH } = paths();
|
||||
const applicationDirectory = SSH_PATH;
|
||||
|
||||
const privateKeyPath = path.join(applicationDirectory, `${id}_rsa`);
|
||||
const publicKeyPath = path.join(applicationDirectory, `${id}_rsa.pub`);
|
||||
|
||||
const privateKeyStream = fs.createWriteStream(privateKeyPath, {
|
||||
mode: 0o600,
|
||||
});
|
||||
privateKeyStream.write(privateKey);
|
||||
privateKeyStream.end();
|
||||
|
||||
fs.writeFileSync(publicKeyPath, publicKey);
|
||||
};
|
||||
|
||||
export const generateSSHKey = async (type: "rsa" | "ed25519" = "rsa") => {
|
||||
const { SSH_PATH } = paths();
|
||||
const applicationDirectory = SSH_PATH;
|
||||
|
||||
if (!fs.existsSync(applicationDirectory)) {
|
||||
fs.mkdirSync(applicationDirectory, { recursive: true });
|
||||
}
|
||||
|
||||
const keyPath = path.join(applicationDirectory, "temp_rsa");
|
||||
|
||||
if (fs.existsSync(`${keyPath}`)) {
|
||||
fs.unlinkSync(`${keyPath}`);
|
||||
}
|
||||
|
||||
if (fs.existsSync(`${keyPath}.pub`)) {
|
||||
fs.unlinkSync(`${keyPath}.pub`);
|
||||
}
|
||||
|
||||
const args = [
|
||||
"-t",
|
||||
type,
|
||||
"-b",
|
||||
"4096",
|
||||
"-C",
|
||||
"dokploy",
|
||||
"-m",
|
||||
"PEM",
|
||||
"-f",
|
||||
keyPath,
|
||||
"-N",
|
||||
"",
|
||||
];
|
||||
|
||||
try {
|
||||
await spawnAsync("ssh-keygen", args);
|
||||
const data = await readSSHKey("temp");
|
||||
await removeSSHKey("temp");
|
||||
return data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const removeSSHKey = async (id: string) => {
|
||||
try {
|
||||
const { SSH_PATH } = paths();
|
||||
const publicKeyPath = path.join(SSH_PATH, `${id}_rsa.pub`);
|
||||
const privateKeyPath = path.join(SSH_PATH, `${id}_rsa`);
|
||||
await fs.promises.unlink(publicKeyPath);
|
||||
await fs.promises.unlink(privateKeyPath);
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@ import { exec } from "node:child_process";
|
||||
import util from "node:util";
|
||||
import { findServerById } from "@/server/services/server";
|
||||
import { Client } from "ssh2";
|
||||
import { readSSHKey } from "../filesystem/ssh";
|
||||
export const execAsync = util.promisify(exec);
|
||||
|
||||
export const execAsyncRemote = async (
|
||||
@@ -12,6 +13,8 @@ export const execAsyncRemote = async (
|
||||
const server = await findServerById(serverId);
|
||||
if (!server.sshKeyId) throw new Error("No SSH key available for this server");
|
||||
|
||||
const keys = await readSSHKey(server.sshKeyId);
|
||||
|
||||
let stdout = "";
|
||||
let stderr = "";
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -59,7 +62,7 @@ export const execAsyncRemote = async (
|
||||
host: server.ipAddress,
|
||||
port: server.port,
|
||||
username: server.username,
|
||||
privateKey: server.sshKey?.privateKey,
|
||||
privateKey: keys.privateKey,
|
||||
timeout: 99999,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { findServerById } from "@/server/services/server";
|
||||
import { docker } from "@/server/constants";
|
||||
import Dockerode from "dockerode";
|
||||
import { readSSHKey } from "../filesystem/ssh";
|
||||
|
||||
export const getRemoteDocker = async (serverId?: string | null) => {
|
||||
if (!serverId) return docker;
|
||||
const server = await findServerById(serverId);
|
||||
if (!server.sshKeyId) return docker;
|
||||
const keys = await readSSHKey(server.sshKeyId);
|
||||
const dockerode = new Dockerode({
|
||||
host: server.ipAddress,
|
||||
port: server.port,
|
||||
@@ -13,7 +15,7 @@ export const getRemoteDocker = async (serverId?: string | null) => {
|
||||
protocol: "ssh",
|
||||
// @ts-ignore
|
||||
sshOptions: {
|
||||
privateKey: server.sshKey?.privateKey,
|
||||
privateKey: keys.privateKey,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Client } from "ssh2";
|
||||
import { WebSocketServer } from "ws";
|
||||
import { findServerById } from "@/server/services/server";
|
||||
import { validateWebSocketRequest } from "../auth/auth";
|
||||
import { readSSHKey } from "../utils/filesystem/ssh";
|
||||
import { getShell } from "./utils";
|
||||
|
||||
export const setupDockerContainerLogsWebSocketServer = (
|
||||
@@ -49,6 +50,7 @@ export const setupDockerContainerLogsWebSocketServer = (
|
||||
const server = await findServerById(serverId);
|
||||
|
||||
if (!server.sshKeyId) return;
|
||||
const keys = await readSSHKey(server.sshKeyId);
|
||||
const client = new Client();
|
||||
new Promise<void>((resolve, reject) => {
|
||||
client
|
||||
@@ -80,7 +82,7 @@ export const setupDockerContainerLogsWebSocketServer = (
|
||||
host: server.ipAddress,
|
||||
port: server.port,
|
||||
username: server.username,
|
||||
privateKey: server.sshKey?.privateKey,
|
||||
privateKey: keys.privateKey,
|
||||
timeout: 99999,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Client } from "ssh2";
|
||||
import { WebSocketServer } from "ws";
|
||||
import { findServerById } from "@/server/services/server";
|
||||
import { validateWebSocketRequest } from "../auth/auth";
|
||||
import { readSSHKey } from "../utils/filesystem/ssh";
|
||||
import { getShell } from "./utils";
|
||||
|
||||
export const setupDockerContainerTerminalWebSocketServer = (
|
||||
@@ -50,6 +51,7 @@ export const setupDockerContainerTerminalWebSocketServer = (
|
||||
if (!server.sshKeyId)
|
||||
throw new Error("No SSH key available for this server");
|
||||
|
||||
const keys = await readSSHKey(server.sshKeyId);
|
||||
const conn = new Client();
|
||||
let stdout = "";
|
||||
let stderr = "";
|
||||
@@ -105,7 +107,7 @@ export const setupDockerContainerTerminalWebSocketServer = (
|
||||
host: server.ipAddress,
|
||||
port: server.port,
|
||||
username: server.username,
|
||||
privateKey: server.sshKey?.privateKey,
|
||||
privateKey: keys.privateKey,
|
||||
timeout: 99999,
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Client } from "ssh2";
|
||||
import { WebSocketServer } from "ws";
|
||||
import { findServerById } from "@/server/services/server";
|
||||
import { validateWebSocketRequest } from "../auth/auth";
|
||||
import { readSSHKey } from "../utils/filesystem/ssh";
|
||||
|
||||
export const setupDeploymentLogsWebSocketServer = (
|
||||
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>,
|
||||
@@ -48,6 +49,7 @@ export const setupDeploymentLogsWebSocketServer = (
|
||||
const server = await findServerById(serverId);
|
||||
|
||||
if (!server.sshKeyId) return;
|
||||
const keys = await readSSHKey(server.sshKeyId);
|
||||
const client = new Client();
|
||||
new Promise<void>((resolve, reject) => {
|
||||
client
|
||||
@@ -79,7 +81,7 @@ export const setupDeploymentLogsWebSocketServer = (
|
||||
host: server.ipAddress,
|
||||
port: server.port,
|
||||
username: server.username,
|
||||
privateKey: server.sshKey?.privateKey,
|
||||
privateKey: keys.privateKey,
|
||||
timeout: 99999,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -6,17 +6,16 @@
|
||||
"target": "es2022",
|
||||
"allowJs": true,
|
||||
"resolveJsonModule": true,
|
||||
"composite": true,
|
||||
"moduleDetection": "force",
|
||||
"isolatedModules": true,
|
||||
/* Strictness */
|
||||
"strict": true,
|
||||
"noUncheckedIndexedAccess": true,
|
||||
"checkJs": true,
|
||||
"rootDir": "./src",
|
||||
|
||||
/* Bundled projects */
|
||||
"lib": ["dom", "dom.iterable", "ES2022"],
|
||||
"noEmit": false,
|
||||
"noEmit": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Bundler",
|
||||
"jsx": "preserve",
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
"noEmit": false,
|
||||
"declaration": true,
|
||||
"moduleResolution": "Node",
|
||||
"rootDir": "./src",
|
||||
"baseUrl": ".",
|
||||
"incremental": false,
|
||||
"jsx": "react-jsx",
|
||||
|
||||
46
pnpm-lock.yaml
generated
46
pnpm-lock.yaml
generated
@@ -42,6 +42,9 @@ importers:
|
||||
|
||||
apps/api:
|
||||
dependencies:
|
||||
'@dokploy/builders':
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/builders
|
||||
'@hono/node-server':
|
||||
specifier: ^1.12.1
|
||||
version: 1.12.1
|
||||
@@ -146,6 +149,9 @@ importers:
|
||||
'@codemirror/view':
|
||||
specifier: 6.29.0
|
||||
version: 6.29.0
|
||||
'@dokploy/builders':
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/builders
|
||||
'@dokploy/trpc-openapi':
|
||||
specifier: 0.0.4
|
||||
version: 0.0.4(@trpc/server@10.45.2)(zod@3.23.8)
|
||||
@@ -585,7 +591,7 @@ importers:
|
||||
version: 3.1.2
|
||||
otpauth:
|
||||
specifier: ^9.2.3
|
||||
version: 9.3.4
|
||||
version: 9.3.1
|
||||
postgres:
|
||||
specifier: 3.4.4
|
||||
version: 3.4.4
|
||||
@@ -594,7 +600,7 @@ importers:
|
||||
version: 6.0.2
|
||||
qrcode:
|
||||
specifier: ^1.5.3
|
||||
version: 1.5.4
|
||||
version: 1.5.3
|
||||
react:
|
||||
specifier: 18.2.0
|
||||
version: 18.2.0
|
||||
@@ -643,7 +649,7 @@ importers:
|
||||
version: 2.1.6
|
||||
'@types/nodemailer':
|
||||
specifier: ^6.4.15
|
||||
version: 6.4.16
|
||||
version: 6.4.15
|
||||
'@types/qrcode':
|
||||
specifier: ^1.5.5
|
||||
version: 1.5.5
|
||||
@@ -1834,9 +1840,9 @@ packages:
|
||||
cpu: [x64]
|
||||
os: [win32]
|
||||
|
||||
'@noble/hashes@1.5.0':
|
||||
resolution: {integrity: sha512-1j6kQFb7QRru7eKN3ZDvRcP13rugwdxZqCjbiAVZfIJwgj2A65UmT4TgARXGlXgnRkORLTDTrO19ZErt7+QXgA==}
|
||||
engines: {node: ^14.21.3 || >=16}
|
||||
'@noble/hashes@1.4.0':
|
||||
resolution: {integrity: sha512-V1JJ1WTRUqHHrOSh597hURcMqVKVGL/ea3kv0gSnEdsEZ0/+VyPghM1lMNGc00z7CIQorSvbKpuJkxvuHbvdbg==}
|
||||
engines: {node: '>= 16'}
|
||||
|
||||
'@node-rs/argon2-android-arm-eabi@1.7.0':
|
||||
resolution: {integrity: sha512-udDqkr5P9E+wYX1SZwAVPdyfYvaF4ry9Tm+R9LkfSHbzWH0uhU6zjIwNRp7m+n4gx691rk+lqqDAIP8RLKwbhg==}
|
||||
@@ -3513,8 +3519,8 @@ packages:
|
||||
'@types/node@20.4.6':
|
||||
resolution: {integrity: sha512-q0RkvNgMweWWIvSMDiXhflGUKMdIxBo2M2tYM/0kEGDueQByFzK4KZAgu5YHGFNxziTlppNpTIBcqHQAxlfHdA==}
|
||||
|
||||
'@types/nodemailer@6.4.16':
|
||||
resolution: {integrity: sha512-uz6hN6Pp0upXMcilM61CoKyjT7sskBoOWpptkjjJp8jIMlTdc3xG01U7proKkXzruMS4hS0zqtHNkNPFB20rKQ==}
|
||||
'@types/nodemailer@6.4.15':
|
||||
resolution: {integrity: sha512-0EBJxawVNjPkng1zm2vopRctuWVCxk34JcIlRuXSf54habUWdz1FB7wHDqOqvDa8Mtpt0Q3LTXQkAs2LNyK5jQ==}
|
||||
|
||||
'@types/prop-types@15.7.12':
|
||||
resolution: {integrity: sha512-5zvhXYtRNRluoE/jAp4GVsSduVUzNWKkOZrCDBWYtE7biZywwdC2AcEzg+cSMLFRfVgeAFqpfNabiPjxFddV1Q==}
|
||||
@@ -4730,6 +4736,9 @@ packages:
|
||||
emoji-regex@9.2.2:
|
||||
resolution: {integrity: sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==}
|
||||
|
||||
encode-utf8@1.0.3:
|
||||
resolution: {integrity: sha512-ucAnuBEhUK4boH2HjVYG5Q2mQyPorvv0u/ocS+zhdw0S8AlHYY+GOFhP1Gio5z4icpP2ivFSvhtFjQi8+T9ppw==}
|
||||
|
||||
end-of-stream@1.4.4:
|
||||
resolution: {integrity: sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==}
|
||||
|
||||
@@ -6720,8 +6729,8 @@ packages:
|
||||
oslo@1.2.0:
|
||||
resolution: {integrity: sha512-OoFX6rDsNcOQVAD2gQD/z03u4vEjWZLzJtwkmgfRF+KpQUXwdgEXErD7zNhyowmHwHefP+PM9Pw13pgpHMRlzw==}
|
||||
|
||||
otpauth@9.3.4:
|
||||
resolution: {integrity: sha512-qXv+lpsCUO9ewitLYfeDKbLYt7UUCivnU/fwGK2OqhgrCBsRkTUNKWsgKAhkXG3aistOY+jEeuL90JEBu6W3mQ==}
|
||||
otpauth@9.3.1:
|
||||
resolution: {integrity: sha512-E6d2tMxPofHNk4sRFp+kqW7vQ+WJGO9VLI2N/W00DnI+ThskU12Qa10kyNSGklrzhN5c+wRUsN4GijVgCU2N9w==}
|
||||
|
||||
p-cancelable@3.0.0:
|
||||
resolution: {integrity: sha512-mlVgR3PGuzlo0MmTdk4cXqXWlwQDLnONTAg6sm62XkMJEiRxN3GL3SffkYvqwonbkJBcrI7Uvv5Zh9yjvn2iUw==}
|
||||
@@ -7038,8 +7047,8 @@ packages:
|
||||
resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==}
|
||||
engines: {node: '>=6'}
|
||||
|
||||
qrcode@1.5.4:
|
||||
resolution: {integrity: sha512-1ca71Zgiu6ORjHqFBDpnSMTR2ReToX4l1Au1VFLyVeBTFavzQnv5JxMFr3ukHVKpSrSA2MCk0lNJSykjUfz7Zg==}
|
||||
qrcode@1.5.3:
|
||||
resolution: {integrity: sha512-puyri6ApkEHYiVl4CFzo1tDkAZ+ATcnbJrJ6RiBM1Fhctdn/ix9MTE3hRph33omisEbC/2fcfemsseiKgBPKZg==}
|
||||
engines: {node: '>=10.13.0'}
|
||||
hasBin: true
|
||||
|
||||
@@ -9307,7 +9316,7 @@ snapshots:
|
||||
'@next/swc-win32-x64-msvc@14.2.5':
|
||||
optional: true
|
||||
|
||||
'@noble/hashes@1.5.0': {}
|
||||
'@noble/hashes@1.4.0': {}
|
||||
|
||||
'@node-rs/argon2-android-arm-eabi@1.7.0':
|
||||
optional: true
|
||||
@@ -11585,7 +11594,7 @@ snapshots:
|
||||
|
||||
'@types/node@20.4.6': {}
|
||||
|
||||
'@types/nodemailer@6.4.16':
|
||||
'@types/nodemailer@6.4.15':
|
||||
dependencies:
|
||||
'@types/node': 20.14.10
|
||||
|
||||
@@ -12829,6 +12838,8 @@ snapshots:
|
||||
|
||||
emoji-regex@9.2.2: {}
|
||||
|
||||
encode-utf8@1.0.3: {}
|
||||
|
||||
end-of-stream@1.4.4:
|
||||
dependencies:
|
||||
once: 1.4.0
|
||||
@@ -15441,9 +15452,9 @@ snapshots:
|
||||
'@node-rs/argon2': 1.7.0
|
||||
'@node-rs/bcrypt': 1.9.0
|
||||
|
||||
otpauth@9.3.4:
|
||||
otpauth@9.3.1:
|
||||
dependencies:
|
||||
'@noble/hashes': 1.5.0
|
||||
'@noble/hashes': 1.4.0
|
||||
|
||||
p-cancelable@3.0.0: {}
|
||||
|
||||
@@ -15697,9 +15708,10 @@ snapshots:
|
||||
|
||||
punycode@2.3.1: {}
|
||||
|
||||
qrcode@1.5.4:
|
||||
qrcode@1.5.3:
|
||||
dependencies:
|
||||
dijkstrajs: 1.0.3
|
||||
encode-utf8: 1.0.3
|
||||
pngjs: 5.0.0
|
||||
yargs: 15.4.1
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./packages/builders" },
|
||||
{ "path": "./apps/dokploy" }
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user