feat: add more docker api
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@cc-server/core": "^0.3.3",
|
||||
"@cc-server/core": "^0.6.1",
|
||||
"axios": "^0.19.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
6
packages/docker-api/src/api/opts/node.ts
Normal file
6
packages/docker-api/src/api/opts/node.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import * as common from './common'
|
||||
|
||||
export declare namespace node {
|
||||
export interface ListOpts extends common.query.FilterOpt {
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,18 @@ import { Labels } from '../common'
|
||||
export declare namespace swarm {
|
||||
type NodeAvailability = string;
|
||||
|
||||
export interface UnlockOpts {
|
||||
UnlockKey: string;
|
||||
}
|
||||
|
||||
export interface JoinOpts {
|
||||
ListenAddr?: string;
|
||||
AdvertiseAddr?: string;
|
||||
DataPathAddr?: string;
|
||||
RemoteAddrs?: string[];
|
||||
JoinToken?: string;
|
||||
}
|
||||
|
||||
export interface InitOpts {
|
||||
ListenAddr?: string;
|
||||
AdvertiseAddr?: string;
|
||||
|
||||
@@ -297,4 +297,9 @@ export declare namespace container {
|
||||
NetworkSettings: SummaryNetworkSettings;
|
||||
Mounts: Mount[];
|
||||
}
|
||||
|
||||
export interface ContainerPrune {
|
||||
ContainersDeleted: string[];
|
||||
SpaceReclaimed: number;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,16 +8,22 @@ export namespace container {
|
||||
return await api.get<types.container.Container[]>('/containers/json', filters)
|
||||
}
|
||||
|
||||
export async function info(id: string, query: { size: boolean } = { size: false }) {
|
||||
export async function inspect(id: string, query: { size: boolean } = { size: false }) {
|
||||
return await api.get<types.container.ContainerJSON>(`/containers/${id}/json`, query);
|
||||
}
|
||||
|
||||
export function prune() {
|
||||
return api.post<types.container.ContainerPrune>('/containers/prune');
|
||||
}
|
||||
|
||||
export async function logs(id: string, opts: opts.container.LogsOpts = {}): Promise<http.ServerResponse> {
|
||||
return await api.stream(`/containers/${id}/logs`, Object.assign({
|
||||
let data = {
|
||||
follow: true,
|
||||
stdout: true,
|
||||
stderr: true,
|
||||
tail: 10
|
||||
}, opts));
|
||||
tail: 10,
|
||||
...opts
|
||||
}
|
||||
return await api.stream(`/containers/${id}/logs`, data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ export namespace service {
|
||||
return await api.get<types.service.Service[]>('/services', filters);
|
||||
}
|
||||
export async function create() {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
export async function inspect(id: string, query: { insertDefaults: boolean } = { insertDefaults: false }) {
|
||||
return await api.get<any>(`/services/${id}`, query);
|
||||
}
|
||||
}
|
||||
|
||||
0
packages/docker-api/src/client/stack.ts
Normal file
0
packages/docker-api/src/client/stack.ts
Normal file
@@ -10,4 +10,20 @@ export namespace swarm {
|
||||
export async function init(opts: opts.swarm.InitOpts) {
|
||||
return await api.post<string>('/swarm/init', opts);
|
||||
}
|
||||
|
||||
export async function join(opts: opts.swarm.JoinOpts) {
|
||||
return await api.post<string>('/swarm/join', opts);
|
||||
}
|
||||
|
||||
export async function leave(force: boolean = false) {
|
||||
return await api.post<string>(`/swarm/leave?force=${force}`);
|
||||
}
|
||||
|
||||
export async function unlockkey() {
|
||||
return await api.get<string>(`/swarm/unlockkey`);
|
||||
}
|
||||
|
||||
export async function unlock(opts: opts.swarm.UnlockOpts) {
|
||||
return await api.post<string>(`/swarm/unlockkey`, opts);
|
||||
}
|
||||
}
|
||||
@@ -23,9 +23,9 @@ async function handle<T>(method: Method, path: string, reqConfig?: AxiosRequestC
|
||||
let config: AxiosRequestConfig = {
|
||||
method,
|
||||
url: path,
|
||||
...reqConfig
|
||||
};
|
||||
let startTime = Date.now();
|
||||
Object.assign(config, reqConfig)
|
||||
let response: AxiosResponse;
|
||||
try {
|
||||
response = await api.request(config);
|
||||
@@ -57,10 +57,6 @@ RESPONSE BODY : ${toString.call(response.data.pipe) === "[object Function]" ?
|
||||
HANDLE TIME : ${Date.now() - startTime}ms
|
||||
=======================================`);
|
||||
}
|
||||
// console.log(`${method} ${path} HTTP/1.1
|
||||
// ${config.data ? JSON.stringify(config.data, null, 2) + '\n' : ''}
|
||||
// HTTP/1.1 ${response.status} ${response.statusText}
|
||||
// ${config.responseType != 'stream' ? JSON.stringify(response.data, null, 2) : config.responseType}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user