feat: add image volume controller
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
17
packages/docker-api/src/api/types/image.ts
Normal file
17
packages/docker-api/src/api/types/image.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'
|
||||
|
||||
19
packages/docker-api/src/api/types/volume.ts
Normal file
19
packages/docker-api/src/api/types/volume.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
|
||||
8
packages/docker-api/src/client/image.ts
Normal file
8
packages/docker-api/src/client/image.ts
Normal 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');
|
||||
}
|
||||
}
|
||||
@@ -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'
|
||||
|
||||
@@ -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() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
8
packages/docker-api/src/client/volume.ts
Normal file
8
packages/docker-api/src/client/volume.ts
Normal 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');
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user