Kaydet (Commit) aace521c authored tarafından Hakkı Dizdar's avatar Hakkı Dizdar

Soket ile logların alınabilmesi için fonksiyon geliştirildi

üst 5e85eb58
const Docker = require("dockerode");
const docker = new Docker();
const stream = require("stream");
const logs = (ws, container) => {
var logStream = new stream.PassThrough();
logStream.on("data", function (chunk) {
ws.send({
method: "logs",
event: "log",
container: container.id,
output: chunk.toString("utf8"),
});
});
container = docker.getContainer(container);
container.logs(
{
follow: true,
stdout: true,
stderr: true,
},
function (err, stream) {
if (err) {
return console.error(err.message);
}
container.modem.demuxStream(stream, logStream, logStream);
}
);
};
module.exports = logs;
...@@ -478,6 +478,11 @@ ...@@ -478,6 +478,11 @@
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
}, },
"emitter-component": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/emitter-component/-/emitter-component-1.1.1.tgz",
"integrity": "sha1-Bl4tvtaVm/RwZ57avq95gdEAOrY="
},
"emoji-regex": { "emoji-regex": {
"version": "8.0.0", "version": "8.0.0",
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
...@@ -1410,6 +1415,14 @@ ...@@ -1410,6 +1415,14 @@
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
"integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=" "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow="
}, },
"stream": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/stream/-/stream-0.0.2.tgz",
"integrity": "sha1-f1Nj8Ff2WSxVlfALyAon9c7B8O8=",
"requires": {
"emitter-component": "^1.1.1"
}
},
"streamsearch": { "streamsearch": {
"version": "0.1.2", "version": "0.1.2",
"resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-0.1.2.tgz", "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-0.1.2.tgz",
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
"cors": "^2.8.5", "cors": "^2.8.5",
"dockerode": "^3.3.0", "dockerode": "^3.3.0",
"express": "^4.17.1", "express": "^4.17.1",
"express-ws": "^4.0.0" "express-ws": "^4.0.0",
"stream": "0.0.2"
} }
} }
const pull = require("../docker/controllers/pull"); const pull = require("../docker/controllers/pull");
const logs = require("../docker/controllers/logs");
const handler = (ws, _) => { const handler = (ws, _) => {
ws = { ws = {
...@@ -18,6 +19,7 @@ const handler = (ws, _) => { ...@@ -18,6 +19,7 @@ const handler = (ws, _) => {
try { try {
m = JSON.parse(m); m = JSON.parse(m);
m.method === "pull" && pull(ws, m.image); m.method === "pull" && pull(ws, m.image);
m.method === "logs" && logs(ws, m.container);
} catch (e) {} } catch (e) {}
}); });
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment