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:
@@ -1,6 +1,5 @@
|
||||
import { ShowBuildChooseForm } from "@/components/dashboard/application/build/show";
|
||||
import { ShowProviderForm } from "@/components/dashboard/application/general/generic/show";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Toggle } from "@/components/ui/toggle";
|
||||
@@ -76,8 +75,6 @@ export const ShowGeneralApplication = ({ applicationId }: Props) => {
|
||||
Open Terminal
|
||||
</Button>
|
||||
</DockerTerminalModal>
|
||||
|
||||
{/* {data?.server?.name || "No Server"} */}
|
||||
</CardContent>
|
||||
</Card>
|
||||
<ShowProviderForm applicationId={applicationId} />
|
||||
|
||||
@@ -75,7 +75,10 @@ export const ComposeActions = ({ composeId }: Props) => {
|
||||
<StopCompose composeId={composeId} />
|
||||
)}
|
||||
|
||||
<DockerTerminalModal appName={data?.appName || ""}>
|
||||
<DockerTerminalModal
|
||||
appName={data?.appName || ""}
|
||||
serverId={data?.serverId || ""}
|
||||
>
|
||||
<Button variant="outline">
|
||||
<Terminal />
|
||||
Open Terminal
|
||||
|
||||
@@ -124,7 +124,10 @@ export const columns: ColumnDef<Container>[] = [
|
||||
containerId={container.containerId}
|
||||
serverId={container.serverId || ""}
|
||||
/>
|
||||
<DockerTerminalModal containerId={container.containerId}>
|
||||
<DockerTerminalModal
|
||||
containerId={container.containerId}
|
||||
serverId={container.serverId || ""}
|
||||
>
|
||||
Terminal
|
||||
</DockerTerminalModal>
|
||||
</DropdownMenuContent>
|
||||
|
||||
@@ -36,7 +36,10 @@ export const ShowGeneralMariadb = ({ mariadbId }: Props) => {
|
||||
) : (
|
||||
<StopMariadb mariadbId={mariadbId} />
|
||||
)}
|
||||
<DockerTerminalModal appName={data?.appName || ""}>
|
||||
<DockerTerminalModal
|
||||
appName={data?.appName || ""}
|
||||
serverId={data?.serverId || ""}
|
||||
>
|
||||
<Button variant="outline">
|
||||
<Terminal />
|
||||
Open Terminal
|
||||
|
||||
@@ -34,7 +34,10 @@ export const ShowGeneralMongo = ({ mongoId }: Props) => {
|
||||
) : (
|
||||
<StopMongo mongoId={mongoId} />
|
||||
)}
|
||||
<DockerTerminalModal appName={data?.appName || ""}>
|
||||
<DockerTerminalModal
|
||||
appName={data?.appName || ""}
|
||||
serverId={data?.serverId || ""}
|
||||
>
|
||||
<Button variant="outline">
|
||||
<Terminal />
|
||||
Open Terminal
|
||||
|
||||
@@ -35,7 +35,10 @@ export const ShowGeneralMysql = ({ mysqlId }: Props) => {
|
||||
<StopMysql mysqlId={mysqlId} />
|
||||
)}
|
||||
|
||||
<DockerTerminalModal appName={data?.appName || ""}>
|
||||
<DockerTerminalModal
|
||||
appName={data?.appName || ""}
|
||||
serverId={data?.serverId || ""}
|
||||
>
|
||||
<Button variant="outline">
|
||||
<Terminal />
|
||||
Open Terminal
|
||||
|
||||
@@ -38,7 +38,10 @@ export const ShowGeneralPostgres = ({ postgresId }: Props) => {
|
||||
<StopPostgres postgresId={postgresId} />
|
||||
)}
|
||||
|
||||
<DockerTerminalModal appName={data?.appName || ""}>
|
||||
<DockerTerminalModal
|
||||
appName={data?.appName || ""}
|
||||
serverId={data?.serverId || ""}
|
||||
>
|
||||
<Button variant="outline">
|
||||
<Terminal />
|
||||
Open Terminal
|
||||
|
||||
@@ -37,7 +37,10 @@ export const ShowGeneralRedis = ({ redisId }: Props) => {
|
||||
<StopRedis redisId={redisId} />
|
||||
)}
|
||||
|
||||
<DockerTerminalModal appName={data?.appName || ""}>
|
||||
<DockerTerminalModal
|
||||
appName={data?.appName || ""}
|
||||
serverId={data?.serverId || ""}
|
||||
>
|
||||
<Button variant="outline">
|
||||
<Terminal />
|
||||
Open Terminal
|
||||
|
||||
@@ -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