feat: add task and dashboard controller
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
		@@ -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"
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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:
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										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