feat: add image volume controller

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
2019-08-01 17:22:37 +08:00
parent 28d541b26f
commit f0810cc9d9
15 changed files with 196 additions and 28 deletions

View File

@@ -0,0 +1,17 @@
import { Labels } from '../common'
export declare namespace image {
export interface Image {
Containers: number;
Created: number;
Id: string;
Labels: Labels;
ParentId: string;
RepoDigests: string[];
RepoTags: string[];
SharedSize: number;
Size: number;
VirtualSize: number;
}
}

View File

@@ -1,6 +1,8 @@
export * from './node'
export * from './task'
export * from './image'
export * from './swarm'
export * from './volume'
export * from './system'
export * from './network'
export * from './service'

View File

@@ -0,0 +1,19 @@
import { Labels, Options } from '../common'
export declare namespace volume {
export interface Volume {
CreatedAt: Date;
Driver: string;
Labels: Labels;
Mountpoint: string;
Name: string;
Options: Options;
Scope: string;
}
export interface VolumeJSON {
Volumes: Volume[];
Warnings?: any;
}
}

View File

@@ -0,0 +1,8 @@
import * as api from '../utils/api'
import * as types from '../api/types'
export namespace image {
export async function list() {
return await api.get<types.image.Image[]>('/images/json');
}
}

View File

@@ -1,6 +1,8 @@
export * from './node'
export * from './task'
export * from './image'
export * from './swarm'
export * from './volume'
export * from './system'
export * from './network'
export * from './service'

View File

@@ -6,4 +6,7 @@ export namespace service {
export async function list(filters?: opts.service.ListOpts) {
return await api.get<types.service.Service[]>('/services', filters);
}
export async function create() {
}
}

View File

@@ -10,13 +10,7 @@ export namespace system {
return await api.get<types.system.Version>('/version');
}
export async function events(cb: (events: object) => void) {
let stream = await api.stream<any>('/events');
stream.on('data', (chunk: ArrayBuffer) => {
cb(JSON.parse(Buffer.from(chunk).toString()))
})
stream.on('end', () => {
cb(undefined);
})
export async function events() {
return await api.stream('/events');
}
}

View File

@@ -0,0 +1,8 @@
import * as api from '../utils/api'
import * as types from '../api/types'
export namespace volume {
export async function list() {
return await api.get<types.volume.VolumeJSON>('/volumes');
}
}

View File

@@ -11,6 +11,10 @@ export async function post<T>(path: string, data?: object): Promise<T> {
return await handle<T>("POST", path, { data });
}
export async function del<T>(path: string, data?: object): Promise<T> {
return await handle<T>("DELETE", path, { params: data });
}
export async function stream<T = http.ServerResponse>(path: string, data?: object): Promise<T> {
return await handle<T>("GET", path, { params: data, responseType: "stream" });
}
@@ -64,8 +68,7 @@ function init() {
const instanceConfig: AxiosRequestConfig = {
headers: {
'Content-Type': 'application/json'
},
timeout: 5000
}
}
if (process.env.DOCKER_HOST.startsWith("/")) {
instanceConfig.socketPath = process.env.DOCKER_HOST