refactor: stash

This commit is contained in:
Mauricio Siu
2024-10-02 21:55:54 -06:00
parent ffd19f591d
commit d256998677
32 changed files with 4023 additions and 293 deletions

View File

@@ -10,7 +10,6 @@
"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",

View File

@@ -0,0 +1 @@
ALTER TABLE "ssh-key" ADD COLUMN "privateKey" text DEFAULT '' NOT NULL;

File diff suppressed because it is too large Load Diff

View File

@@ -267,6 +267,13 @@
"when": 1726988289562,
"tag": "0037_legal_namor",
"breakpoints": true
},
{
"idx": 38,
"version": "6",
"when": 1727903587684,
"tag": "0038_mushy_blindfold",
"breakpoints": true
}
]
}

View File

@@ -34,7 +34,6 @@
"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",

View File

@@ -14,6 +14,7 @@ import {
findSSHKeyById,
removeSSHKeyById,
updateSSHKeyById,
execAsync,
} from "@dokploy/builders";
export const sshRouter = createTRPCRouter({

View File

@@ -3,28 +3,30 @@ 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({

View File

@@ -2,11 +2,7 @@ import type http from "node:http";
import { spawn } from "node-pty";
import { Client } from "ssh2";
import { WebSocketServer } from "ws";
import {
findServerById,
readSSHKey,
validateWebSocketRequest,
} from "@dokploy/builders";
import { findServerById, validateWebSocketRequest } from "@dokploy/builders";
import { getShell } from "./utils";
export const setupDockerContainerLogsWebSocketServer = (
@@ -52,7 +48,6 @@ 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
@@ -84,7 +79,7 @@ export const setupDockerContainerLogsWebSocketServer = (
host: server.ipAddress,
port: server.port,
username: server.username,
privateKey: keys.privateKey,
privateKey: server.sshKey?.privateKey,
timeout: 99999,
});
});

View File

@@ -2,11 +2,7 @@ import type http from "node:http";
import { spawn } from "node-pty";
import { Client } from "ssh2";
import { WebSocketServer } from "ws";
import {
findServerById,
readSSHKey,
validateWebSocketRequest,
} from "@dokploy/builders";
import { findServerById, validateWebSocketRequest } from "@dokploy/builders";
import { getShell } from "./utils";
export const setupDockerContainerTerminalWebSocketServer = (
@@ -53,7 +49,6 @@ 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 = "";
@@ -109,7 +104,7 @@ export const setupDockerContainerTerminalWebSocketServer = (
host: server.ipAddress,
port: server.port,
username: server.username,
privateKey: keys.privateKey,
privateKey: server.sshKey?.privateKey,
timeout: 99999,
});
} else {

View File

@@ -2,11 +2,7 @@ import { spawn } from "node:child_process";
import type http from "node:http";
import { Client } from "ssh2";
import { WebSocketServer } from "ws";
import {
findServerById,
readSSHKey,
validateWebSocketRequest,
} from "@dokploy/builders";
import { findServerById, validateWebSocketRequest } from "@dokploy/builders";
export const setupDeploymentLogsWebSocketServer = (
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>,
@@ -51,7 +47,6 @@ 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
@@ -83,7 +78,7 @@ export const setupDeploymentLogsWebSocketServer = (
host: server.ipAddress,
port: server.port,
username: server.username,
privateKey: keys.privateKey,
privateKey: server.sshKey?.privateKey,
timeout: 99999,
});
});

View File

@@ -8,7 +8,7 @@ import {
createDefaultServerTraefikConfig,
createDefaultTraefikConfig,
initializeTraefik,
} from "@dokploy/builders";
} from "../../packages/builders/src";
(async () => {
try {

View File

@@ -1,52 +1,56 @@
{
"compilerOptions": {
/* Base Options: */
"esModuleInterop": true,
"skipLibCheck": true,
"target": "es2022",
"allowJs": true,
"resolveJsonModule": true,
"moduleDetection": "force",
"isolatedModules": true,
"compilerOptions": {
/* Base Options: */
"esModuleInterop": true,
"skipLibCheck": true,
"target": "es2022",
"allowJs": true,
"resolveJsonModule": true,
"moduleDetection": "force",
"isolatedModules": true,
/* Strictness */
"strict": true,
"noUncheckedIndexedAccess": true,
"checkJs": true,
/* Strictness */
"strict": true,
"noUncheckedIndexedAccess": true,
"checkJs": true,
/* Bundled projects */
"lib": ["dom", "dom.iterable", "ES2022"],
"noEmit": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"jsx": "preserve",
"plugins": [{ "name": "next" }],
"incremental": true,
/* Bundled projects */
"lib": ["dom", "dom.iterable", "ES2022"],
"noEmit": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"jsx": "preserve",
"plugins": [{ "name": "next" }],
"incremental": true,
/* Path Aliases */
"baseUrl": ".",
"paths": {
"@/*": ["./*"]
}
},
/* 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",
"**/*.ts",
"**/*.tsx",
"**/*.cjs",
"**/*.js",
".next/types/**/*.ts",
"env.js",
"next.config.mjs"
],
"exclude": [
"node_modules",
"dokploy",
"config",
"dist",
"webpack.config.server.js",
"migration.ts",
"setup.ts"
]
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"**/*.cjs",
"**/*.js",
".next/types/**/*.ts",
"env.js",
"next.config.mjs"
],
"exclude": [
"node_modules",
"dokploy",
"config",
"dist",
"webpack.config.server.js",
"migration.ts",
"setup.ts"
]
}

View File

@@ -1,16 +1,21 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "ESNext",
"outDir": "dist/",
"target": "ESNext",
"isolatedModules": false,
"noEmit": false,
"moduleResolution": "Node",
"baseUrl": ".",
"paths": {
"@/*": ["./*"]
}
},
"include": ["next-env.d.ts", "./server/**/*"]
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "ESNext",
"outDir": "dist/",
"target": "ESNext",
"isolatedModules": false,
"noEmit": false,
"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/**/*"]
}

File diff suppressed because one or more lines are too long