feat: update docker api invoke

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2020-01-03 14:33:39 +08:00
parent b497c9750e
commit 67b410e448
13 changed files with 66 additions and 15 deletions

View File

@ -1,4 +1,4 @@
import * as docker from '@dayu/docker-api'
import docker from '@dayu/docker-api'
import { controller, httpGet } from "@cc-server/binding";
const STACK_LABEL = 'com.docker.stack.namespace';
@ -28,7 +28,7 @@ class DashboardController {
stacks: Array.from(new Set(stacks)),
services,
networks: networks.map(n => n.Name),
containers: containers.map(c => c.Names),
containers: containers.map(c => c.Names[0].substr(1)),
images: images.map(i => i.Id),
volumes: volumes.Volumes.map(v => v.Name)
}

View File

@ -1,4 +1,4 @@
import * as docker from '@dayu/docker-api'
import docker from '@dayu/docker-api'
import { controller, get, requestParam } from '@cc-server/binding'
@controller('/config')

View File

@ -1,4 +1,4 @@
import * as docker from '@dayu/docker-api'
import docker from '@dayu/docker-api'
import { io, interfaces, namespace, listener, Message } from '@cc-server/ws'
import { controller, get, post, requestParam } from '@cc-server/binding'

View File

@ -1,5 +1,5 @@
import docker from '@dayu/docker-api'
import { controller, httpGet, httpPost } from 'inversify-express-utils';
import * as docker from '@dayu/docker-api'
@controller('/node')
class NodeController {

View File

@ -1,4 +1,4 @@
import * as docker from '@dayu/docker-api'
import docker from '@dayu/docker-api'
import { namespace, listener, interfaces, io, Message } from '@cc-server/ws'
import { controller, post, get, requestParam, queryParam } from '@cc-server/binding';

View File

@ -1,5 +1,5 @@
import docker from '@dayu/docker-api'
import { controller, get, post, requestParam } from '@cc-server/binding';
import * as docker from '@dayu/docker-api'
const STACK_LABEL = 'com.docker.stack.namespace';
@ -26,7 +26,7 @@ class StackController {
}
return {
status: 0,
data: result
data: { rows: result }
};
}

View File

@ -1,5 +1,5 @@
import docker from '@dayu/docker-api'
import { controller, httpGet, httpPost } from 'inversify-express-utils';
import * as docker from '@dayu/docker-api'
@controller('/swarm')
class SwarmController {

View File

@ -1,5 +1,5 @@
import docker from '@dayu/docker-api'
import { controller, httpGet, httpPost } from 'inversify-express-utils';
import * as docker from '@dayu/docker-api'
import { io, namespace, listener, interfaces, Message } from '@cc-server/ws';
@controller('')

View File

@ -1,5 +1,6 @@
import docker from '@dayu/docker-api'
import { namespace, listener, interfaces, io, Message } from '@cc-server/ws'
import { controller, post, get, requestParam, queryParam } from '@cc-server/binding';
import * as docker from '@dayu/docker-api'
@controller('/task')
class TaskController {
@ -19,3 +20,20 @@ class TaskController {
};
}
}
@namespace("/task")
class TaskNamespace extends interfaces.Namespace {
@listener()
async logs(socket: io.Socket, data: any) {
try {
let stream = await docker.task.logs(data.id, data);
this.defer(socket, () => stream.connection.destroy());
stream.on('data', (chunk: ArrayBuffer) => {
let log = Buffer.from(chunk.slice(8, chunk.byteLength - 1)).toString();
socket.send(log);
})
} catch (ex) {
return new Message(ex.message);
}
}
}

View File

@ -1,5 +1,5 @@
import docker from '@dayu/docker-api'
import { controller, get, post, requestParam } from '@cc-server/binding';
import * as docker from '@dayu/docker-api'
const GROUP_LABEL = 'pw.yumc.group.name'

View File

@ -10,8 +10,8 @@ import * as path from 'path'
// process.env.DOCKER_HOST = '/var/run/docker.sock'
// process.env.DOCKER_HOST = 'https://dscli.miaowoo.cc'
// process.env.DOCKER_HOST = 'http://172.20.0.90:2378'
// process.env.DOCKER_HOST = 'https://dcli.yumc.pw'
process.env.DOCKER_HOST = 'http://172.16.200.12:8376'
process.env.DOCKER_HOST = 'https://dcli.yumc.pw'
// process.env.DOCKER_HOST = 'http://172.16.200.12:8376'
let CC_MONGO_URL = process.env.CC_MONGO_URL
let CC_MONGO_DB = process.env.CC_MONGO_DB
// if (process.env.local) {

View File

@ -33,6 +33,13 @@
]
},
"commands": [
{
"command": "dayu.task.logs",
"title": "View Task Logs",
"icon": {
"dark": "src/images/browser.svg"
}
},
{
"command": "dayu.container.logs",
"title": "View Container Logs",
@ -55,6 +62,11 @@
"when": "view == docker-explorer && viewItem =~ /.*\"type\":\"CONTAINER\".*/",
"group": "inline"
},
{
"command": "dayu.task.logs",
"when": "view == docker-explorer && viewItem =~ /.*\"type\":\"TASK\".*/",
"group": "inline"
},
{
"command": "dayu.service.logs",
"when": "view == docker-explorer && viewItem =~ /.*\"type\":\"SERVICE\".*/",

View File

@ -13,6 +13,8 @@ enum Type {
NETWORK = "NETWORK",
STACKS = "STACKS",
STACK = "STACK",
TASKS = "TASKS",
TASK = "TASK",
NODES = "NODES",
NODE = "NODE"
}
@ -26,6 +28,11 @@ export class DockerProvider extends BaseProvider<vscode.TreeItem> {
constructor(context: vscode.ExtensionContext) {
super();
context.subscriptions.push(
vscode.commands.registerCommand('dayu.task.logs', (item: vscode.TreeItem) => {
let value: ItemContextValue = JSON.parse(item.contextValue);
let url = `https://dayu-api.miaowoo.cc/logs/?action=task&data=${value.data.id}`;
return vscode.commands.executeCommand("mini-browser.openUrl", url);
}),
vscode.commands.registerCommand('dayu.container.logs', (item: vscode.TreeItem) => {
let value: ItemContextValue = JSON.parse(item.contextValue);
let url = `https://dayu-api.miaowoo.cc/logs/?action=container&data=${value.data.id}`;
@ -81,6 +88,20 @@ export class DockerProvider extends BaseProvider<vscode.TreeItem> {
tooltip: JSON.stringify(n, undefined, 2)
})
})
case Type.TASKS:
let tasks = await docker.task.list();
return tasks.map(n => {
return this.createTreeItem({
label: n.ID,
context: {
type: Type.NODE,
data: {
id: n.ID
}
},
tooltip: JSON.stringify(n, undefined, 2)
})
})
case Type.CONTAINERS:
let containers = await docker.container.list();
return containers.map(c => {