( serverId: string, onData?: (data: any) => void, )
| 260 | }; |
| 261 | |
| 262 | const installRequirements = async ( |
| 263 | serverId: string, |
| 264 | onData?: (data: any) => void, |
| 265 | ) => { |
| 266 | const client = new Client(); |
| 267 | const server = await findServerById(serverId); |
| 268 | if (!server.sshKeyId) { |
| 269 | onData?.("❌ No SSH Key found, please assign one to this server"); |
| 270 | throw new Error("No SSH Key found"); |
| 271 | } |
| 272 | |
| 273 | const isBuildServer = server.serverType === "build"; |
| 274 | |
| 275 | return new Promise<void>((resolve, reject) => { |
| 276 | client |
| 277 | .once("ready", () => { |
| 278 | const command = server.command || defaultCommand(isBuildServer); |
| 279 | client.exec(command, (err, stream) => { |
| 280 | if (err) { |
| 281 | onData?.(err.message); |
| 282 | reject(err); |
| 283 | return; |
| 284 | } |
| 285 | stream |
| 286 | .on("close", () => { |
| 287 | client.end(); |
| 288 | resolve(); |
| 289 | }) |
| 290 | .on("data", (data: string) => { |
| 291 | onData?.(data.toString()); |
| 292 | }) |
| 293 | .stderr.on("data", (data) => { |
| 294 | onData?.(data.toString()); |
| 295 | }); |
| 296 | }); |
| 297 | }) |
| 298 | .on("error", (err) => { |
| 299 | client.end(); |
| 300 | if (err.level === "client-authentication") { |
| 301 | const technicalDetail = `Error: ${err.message} ${err.level}`; |
| 302 | const friendlyMessage = [ |
| 303 | "", |
| 304 | "❌ Couldn't connect to your server — the SSH key was not accepted.", |
| 305 | "", |
| 306 | "This usually means the key doesn't match what's on the server, or the key format is invalid.", |
| 307 | "", |
| 308 | `Technical details: ${technicalDetail}`, |
| 309 | "", |
| 310 | "💡 Hints:", |
| 311 | " • Check that the SSH key you added in Dokploy is the same one installed on the server (e.g. in ~/.ssh/authorized_keys).", |
| 312 | " • Try generating a new SSH key in Dokploy and add only the public key to the server, then try again.", |
| 313 | " • Make sure to follow the instructions on the Setup Server Button on the SSH Keys tab", |
| 314 | ].join("\n"); |
| 315 | onData?.(friendlyMessage); |
| 316 | reject( |
| 317 | new Error( |
| 318 | `Authentication failed: Invalid SSH private key. ${technicalDetail}`, |
| 319 | ), |
no test coverage detected