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

Imajı indirmek için gerekli geliştirmeler yapıldı

üst 9ac603ee
const Docker = require("dockerode");
const docker = new Docker();
const pull = async (ws, image) => {
if (
image.startsWith("nyxteam/oyunparki-small") ||
image.startsWith("nyxteam/oyunparki-full")
) {
ws.send({
method: "pull",
event: "done",
output: "wrong image",
});
return;
}
await docker.pull(image, function (err, stream) {
const onFinished = (err, output) => {
ws.send({ method: "pull", event: "done", output: output });
};
const onProgress = (event) => {
ws.send({
method: "pull",
event: "progress",
output: JSON.stringify(event),
});
};
docker.modem.followProgress(stream, onFinished, onProgress);
});
};
module.exports = pull;
const express = require("express");
const compression = require("compression");
const app = express();
const Docker = require("dockerode");
const docker1 = new Docker();
const ws = require("express-ws")(app);
app.use(compression());
app.use(express.json());
app.get("/", (_, res) => {
res.send("Merhaba Dünya!");
});
app.get("/images", (_, res) => {
docker1.listImages(function (_, images) {
res.send(
images.filter(
(i) =>
i.RepoTags[0].startsWith("nyxteam/oyunparki-small") ||
i.RepoTags[0].startsWith("nyxteam/oyunparki-full")
).length !== 0
);
});
});
require("./socket")(app);
app.listen(3000);
This diff is collapsed.
......@@ -17,6 +17,9 @@
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1"
"compression": "^1.7.4",
"dockerode": "^3.3.0",
"express": "^4.17.1",
"express-ws": "^4.0.0"
}
}
const pull = require("../docker/controllers/pull");
const handler = (ws, _) => {
ws = {
handler: ws,
send: function (msg) {
try {
if (this.handler.readyState === this.handler.OPEN)
this.handler.send(
typeof msg === "object" ? JSON.stringify(msg) : msg
);
} catch (e) {
console.log(e);
}
},
};
ws.handler.on("message", (m) => {
try {
m = JSON.parse(m);
m.method === "pull" && pull(ws, m.image);
} catch (e) {}
});
};
module.exports = (app) => {
app.ws("/socket/", handler);
app.ws("/socket/.*/", handler);
};
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