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

@@ -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)
}
}
}