mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
feat(multi-server): enable docker terminal inside of containers
This commit is contained in:
@@ -55,115 +55,61 @@ export const setupDockerContainerTerminalWebSocketServer = (
|
||||
const conn = new Client();
|
||||
let stdout = "";
|
||||
let stderr = "";
|
||||
// conn
|
||||
// .once("ready", () => {
|
||||
// console.log("Client :: ready");
|
||||
// conn.exec(
|
||||
// `docker run -i ${containerId} ${activeWay}`,
|
||||
// (err, stream) => {
|
||||
// if (err) throw err;
|
||||
conn
|
||||
.once("ready", () => {
|
||||
conn.exec(
|
||||
`docker exec -it ${containerId} ${activeWay}`,
|
||||
{ pty: true },
|
||||
(err, stream) => {
|
||||
if (err) throw err;
|
||||
|
||||
// stream
|
||||
// .on("close", (code: number, signal: string) => {
|
||||
// console.log(
|
||||
// `Stream :: close :: code: ${code}, signal: ${signal}`,
|
||||
// );
|
||||
// conn.end();
|
||||
// })
|
||||
// .on("data", (data: string) => {
|
||||
// stdout += data.toString();
|
||||
// ws.send(data.toString());
|
||||
// })
|
||||
// .stderr.on("data", (data) => {
|
||||
// stderr += data.toString();
|
||||
// ws.send(data.toString());
|
||||
// console.error("Error: ", data.toString());
|
||||
// });
|
||||
stream
|
||||
.on("close", (code: number, signal: string) => {
|
||||
console.log(
|
||||
`Stream :: close :: code: ${code}, signal: ${signal}`,
|
||||
);
|
||||
ws.send(`\nContainer closed with code: ${code}\n`);
|
||||
conn.end();
|
||||
})
|
||||
.on("data", (data: string) => {
|
||||
stdout += data.toString();
|
||||
ws.send(data.toString());
|
||||
})
|
||||
.stderr.on("data", (data) => {
|
||||
stderr += data.toString();
|
||||
ws.send(data.toString());
|
||||
console.error("Error: ", data.toString());
|
||||
});
|
||||
|
||||
// // Maneja la entrada de comandos desde WebSocket
|
||||
// ws.on("message", (message) => {
|
||||
// try {
|
||||
// let command: string | Buffer[] | Buffer | ArrayBuffer;
|
||||
// if (Buffer.isBuffer(message)) {
|
||||
// command = message.toString("utf8");
|
||||
// } else {
|
||||
// command = message;
|
||||
// }
|
||||
// stream.write(command.toString());
|
||||
// } catch (error) {
|
||||
// // @ts-ignore
|
||||
// const errorMessage = error?.message as unknown as string;
|
||||
// ws.send(errorMessage);
|
||||
// }
|
||||
// });
|
||||
ws.on("message", (message) => {
|
||||
try {
|
||||
let command: string | Buffer[] | Buffer | ArrayBuffer;
|
||||
if (Buffer.isBuffer(message)) {
|
||||
command = message.toString("utf8");
|
||||
} else {
|
||||
command = message;
|
||||
}
|
||||
stream.write(command.toString());
|
||||
} catch (error) {
|
||||
// @ts-ignore
|
||||
const errorMessage = error?.message as unknown as string;
|
||||
ws.send(errorMessage);
|
||||
}
|
||||
});
|
||||
|
||||
// // Cuando se cierra la conexión WebSocket
|
||||
// ws.on("close", () => {
|
||||
// stream.end();
|
||||
// });
|
||||
// },
|
||||
// );
|
||||
// })p
|
||||
// .connect({
|
||||
// host: server.ipAddress,
|
||||
// port: server.port,
|
||||
// username: server.username,
|
||||
// privateKey: keys.privateKey,
|
||||
// timeout: 99999,
|
||||
// });
|
||||
// conn
|
||||
// .once("ready", () => {
|
||||
// console.log("Client :: ready");
|
||||
// conn.shell((err, stream) => {
|
||||
// if (err) throw err;
|
||||
|
||||
// stream
|
||||
// .on("close", (code: number, signal: string) => {
|
||||
// console.log(
|
||||
// `Stream :: close :: code: ${code}, signal: ${signal}`,
|
||||
// );
|
||||
// conn.end();
|
||||
// })
|
||||
// .on("data", (data: string) => {
|
||||
// stdout += data.toString();
|
||||
// ws.send(data.toString());
|
||||
// })
|
||||
// .stderr.on("data", (data) => {
|
||||
// stderr += data.toString();
|
||||
// ws.send(data.toString());
|
||||
// console.error("Error: ", data.toString());
|
||||
// });
|
||||
// stream.write(`docker exec -it ${containerId} ${activeWay}\n`);
|
||||
// // Maneja la entrada de comandos desde WebSocket
|
||||
// ws.on("message", (message) => {
|
||||
// try {
|
||||
// let command: string | Buffer[] | Buffer | ArrayBuffer;
|
||||
// if (Buffer.isBuffer(message)) {
|
||||
// command = message.toString("utf8");
|
||||
// } else {
|
||||
// command = message;
|
||||
// }
|
||||
// stream.write(command.toString());
|
||||
// } catch (error) {
|
||||
// // @ts-ignore
|
||||
// const errorMessage = error?.message as unknown as string;
|
||||
// ws.send(errorMessage);
|
||||
// }
|
||||
// });
|
||||
|
||||
// // Cuando se cierra la conexión WebSocket
|
||||
// ws.on("close", () => {
|
||||
// stream.end();
|
||||
// });
|
||||
// });
|
||||
// })
|
||||
// .connect({
|
||||
// host: server.ipAddress,
|
||||
// port: server.port,
|
||||
// username: server.username,
|
||||
// privateKey: keys.privateKey,
|
||||
// timeout: 99999,
|
||||
// });
|
||||
ws.on("close", () => {
|
||||
stream.end();
|
||||
});
|
||||
},
|
||||
);
|
||||
})
|
||||
.connect({
|
||||
host: server.ipAddress,
|
||||
port: server.port,
|
||||
username: server.username,
|
||||
privateKey: keys.privateKey,
|
||||
timeout: 99999,
|
||||
});
|
||||
} else {
|
||||
const shell = getShell();
|
||||
const ptyProcess = spawn(
|
||||
|
||||
Reference in New Issue
Block a user