feat: add task and dashboard controller
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
30
packages/core/src/controller/dashboard.ts
Normal file
30
packages/core/src/controller/dashboard.ts
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user