浏览代码

feat: stdin commands works with Docker

Kristian Vos 4 年之前
父节点
当前提交
18293c0b90
共有 2 个文件被更改,包括 10 次插入11 次删除
  1. 8 11
      backend/index.js
  2. 2 0
      docker-compose.yml

+ 8 - 11
backend/index.js

@@ -337,11 +337,12 @@ moduleManager.addModule("utils");
 moduleManager.initialize();
 
 process.stdin.on("data", function(data) {
-    if (data.toString() === "lockdown\r\n") {
+    const command = data.toString().replace(/\r?\n|\r/g, "");
+    if (command === "lockdown") {
         console.log("Locking down.");
         moduleManager._lockdown();
     }
-    if (data.toString() === "status\r\n") {
+    if (command === "status") {
         console.log("Status:");
 
         for (let moduleName in moduleManager.modules) {
@@ -357,23 +358,19 @@ process.stdin.on("data", function(data) {
         }
         // moduleManager._lockdown();
     }
-    if (data.toString().startsWith("running")) {
-        const parts = data
-            .toString()
-            .substr(0, data.toString().length - 2)
+    if (command.startsWith("running")) {
+        const parts = command
             .split(" ");
 
         console.log(moduleManager.modules[parts[1]].runningJobs);
     }
-    if (data.toString().startsWith("stats")) {
-        const parts = data
-            .toString()
-            .substr(0, data.toString().length - 2)
+    if (command.startsWith("stats")) {
+        const parts = command
             .split(" ");
 
         console.log(moduleManager.modules[parts[1]].jobStatistics);
     }
-    if (data.toString().startsWith("debug")) {
+    if (command.startsWith("debug")) {
         moduleManager.modules["utils"].runJob("DEBUG");
     }
 });

+ 2 - 0
docker-compose.yml

@@ -12,6 +12,8 @@ services:
     - redis
     environment:
     - SNYK_TOKEN=${SNYK_TOKEN}
+    stdin_open: true
+    tty: true
   frontend:
     build: ./frontend
     ports: