Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM nodered/node-red:5.0.4-minimal
FROM nodered/node-red:5.0.6-minimal

WORKDIR /data
RUN openssl genrsa -out privkey.pem 2048
Expand Down
2 changes: 1 addition & 1 deletion flows.json
Original file line number Diff line number Diff line change
Expand Up @@ -8852,7 +8852,7 @@
"t": "set",
"p": "post",
"pt": "msg",
"to": "\"'http://localhost/containers/\" & msg.req.params.id & \"/logs?stdout=true&stderr=true&timestamps=true'\" & \" -H 'content-type: application/json'\"",
"to": "\"'http://localhost/containers/\" & msg.req.params.id & \"/logs?stdout=true&stderr=true&timestamps=true&tail=50'\" & \" -H 'content-type: application/json'\"",
"tot": "jsonata"
}
],
Expand Down
38 changes: 37 additions & 1 deletion lib/docker-exec-websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,46 @@ module.exports = {
create: (containerId) => {
const path = `/ws/engine/containers/${containerId}/exec`;

return new DockerExecWebsocketServer.DockerExecServer({
const server = new DockerExecWebsocketServer.DockerExecServer({
path: path,
containerId: containerId,
server: red.server
});

/**
* docker-exec-websocket-server starts the exec stream with dockerode's
* { stream, stdin, stdout, stderr } options but without Docker's connection
* hijack, and then writes the terminal's stdin as `write(buffer, { binary: true })`.
* Both break input on current dockerode/node:
* - without hijack, dockerode returns an HttpDuplex whose writes never reach
* the container (output works, typed keys are silently dropped),
* - on the hijacked socket, the `{ binary: true }` object is rejected by
* node's stream encoding validation (ERR_UNKNOWN_ENCODING), which the
* library turns into a closed session.
* Both are patched here, on the server's own container handle only.
*/
const containerExec = server.container.exec.bind(server.container);

server.container.exec = async (execOptions) => {
const exec = await containerExec(execOptions);
const execStart = exec.start.bind(exec);

exec.start = async (startOptions) => {
const stream = await execStart({ ...startOptions, hijack: true });
const write = stream.write.bind(stream);

stream.write = (chunk, encoding, callback) => write(
chunk,
typeof encoding === "string" ? encoding : undefined,
typeof encoding === "function" ? encoding : callback
);

return stream;
};

return exec;
};

return server;
}
}
Loading
Loading