feat: add task and dashboard controller

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
2019-07-05 16:04:05 +08:00
parent c47137ec4a
commit 28d541b26f
9 changed files with 277 additions and 11 deletions

View File

@@ -11,7 +11,7 @@
},
"scripts": {
"dev": "npx ts-node-dev --respawn --prefer-ts --debounce=1500 --ignore-watch=[] --project tsconfig.json",
"debug": "npx nodemon -V --watch ../../node_modules --delay 1500ms dist/index.js",
"debug": "npx nodemon dist/index.js",
"clean": "rimraf dist",
"watch": "npx tsc --watch",
"build": "yarn clean && npx tsc",
@@ -29,5 +29,18 @@
"rimraf": "^2.6.3",
"ts-node-dev": "^1.0.0-pre.40",
"typescript": "^3.5.2"
},
"nodemonConfig": {
"verbose": true,
"ignore": [
".git",
"public"
],
"watch": [
"./",
"../../node_modules"
],
"delay": "1500",
"ext": "js,json"
}
}

View File

@@ -34,10 +34,10 @@ socket.on('connect', () => {
case "container":
socket.emit('logs', {
id: query.data,
since: Date.now() / 1000 - 60 * 15,
until: Date.now() / 1000,
stderr: false,
tail: "all"
// since: Date.now() / 1000 - 60 * 15,
// until: Date.now() / 1000,
// stderr: false,
tail: "200"
})
break;
default:

View File

@@ -0,0 +1,30 @@
import * as docker from '@dayu/docker-api'
import { controller, httpGet } from "@cc-server/binding";
const STACK_LABEL = 'com.docker.stack.namespace';
@controller('/dashboard')
class DashboardController {
@httpGet('')
async index() {
let stacks = [];
let services = [];
let svrs = await docker.service.list();
for (const service of svrs) {
if (service.Spec.Labels[STACK_LABEL]) {
stacks.push(service.Spec.Labels[STACK_LABEL]);
}
services.push(service.Spec.Name)
}
let networks = await docker.network.list();
let nodes = await docker.node.list();
let tasks = await docker.task.list();
return {
nodes: nodes.map(n => n.Description.Hostname),
tasks: tasks.map(t => t.ID),
stacks: Array.from(new Set(stacks)),
services,
networks: networks.map(n => n.Name)
}
}
}