@@ -9,3 +9,19 @@ export type Options = StringMap
|
||||
export type Config = StringMap
|
||||
export type Labels = StringMap
|
||||
export type Ports = StringMap | ObjectMap
|
||||
export interface Version {
|
||||
Index: number;
|
||||
}
|
||||
export interface Meta {
|
||||
Version: Version;
|
||||
CreatedAt: string;
|
||||
UpdatedAt: string;
|
||||
}
|
||||
export interface Annotations {
|
||||
Name: string;
|
||||
Labels: Labels;
|
||||
}
|
||||
export interface Driver {
|
||||
Name: string;
|
||||
Options: Options;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
export declare namespace query {
|
||||
export interface FilterOpt {
|
||||
export interface Filter<T = any> {
|
||||
filters?: string;
|
||||
}
|
||||
export interface LabelOpt {
|
||||
|
||||
8
packages/docker-api/src/api/opts/config.ts
Normal file
8
packages/docker-api/src/api/opts/config.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
export declare namespace config {
|
||||
export interface FilterOpt {
|
||||
id?: string;
|
||||
label?: string;
|
||||
name?: string;
|
||||
names?: string;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as common from './common'
|
||||
|
||||
export declare namespace container {
|
||||
export interface ListOpts extends common.query.FilterOpt {
|
||||
export interface ListOpts extends common.query.Filter {
|
||||
all?: boolean;
|
||||
limit?: number;
|
||||
size?: boolean;
|
||||
@@ -15,4 +15,26 @@ export declare namespace container {
|
||||
timestamps?: boolean;
|
||||
tail?: number | "all";
|
||||
}
|
||||
export namespace exec {
|
||||
export interface Create {
|
||||
AttachStdin?: boolean;
|
||||
AttachStdout?: boolean;
|
||||
AttachStderr?: boolean;
|
||||
DetachKeys?: string;
|
||||
Tty?: boolean;
|
||||
Cmd?: string[];
|
||||
Env?: string[];
|
||||
Privileged?: boolean;
|
||||
User?: string;
|
||||
WorkingDir?: string;
|
||||
}
|
||||
export interface Start {
|
||||
Detach?: boolean;
|
||||
Tty?: boolean;
|
||||
}
|
||||
export interface Resize {
|
||||
h?: number;
|
||||
w?: number;
|
||||
}
|
||||
}
|
||||
}
|
||||
9
packages/docker-api/src/api/opts/filter.ts
Normal file
9
packages/docker-api/src/api/opts/filter.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export function toJSON(filter: any) {
|
||||
let filters: any = {}
|
||||
for (const key in filter) {
|
||||
let temp: any = {}
|
||||
temp[`${filter[key]}`] = true
|
||||
filters[`${key}`] = temp
|
||||
}
|
||||
return JSON.stringify(filters);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
export * from './swarm'
|
||||
export * from './common'
|
||||
export * from './config'
|
||||
export * from './network'
|
||||
export * from './service'
|
||||
export * from './container'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as common from './common'
|
||||
|
||||
export declare namespace network {
|
||||
export interface ListOpts extends common.query.FilterOpt {
|
||||
export interface ListOpts extends common.query.Filter {
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as common from './common'
|
||||
|
||||
export declare namespace node {
|
||||
export interface ListOpts extends common.query.FilterOpt {
|
||||
export interface ListOpts extends common.query.Filter {
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
import * as common from './common'
|
||||
|
||||
export declare namespace service {
|
||||
export interface ListOpts extends common.query.FilterOpt {
|
||||
export interface FilterOpt {
|
||||
|
||||
}
|
||||
export interface LogsOpts {
|
||||
details?: boolean;
|
||||
|
||||
11
packages/docker-api/src/api/types/config.ts
Normal file
11
packages/docker-api/src/api/types/config.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Meta, Annotations } from '../common'
|
||||
|
||||
export declare namespace config {
|
||||
export interface Spec extends Annotations {
|
||||
Data: string;
|
||||
}
|
||||
export interface Config extends Meta {
|
||||
ID: string;
|
||||
Spec: Spec;
|
||||
}
|
||||
}
|
||||
@@ -302,4 +302,36 @@ export declare namespace container {
|
||||
ContainersDeleted: string[];
|
||||
SpaceReclaimed: number;
|
||||
}
|
||||
|
||||
export namespace exec {
|
||||
export interface CreateResult {
|
||||
Id: string;
|
||||
}
|
||||
export interface StartResult {
|
||||
|
||||
}
|
||||
export interface ResizeResult {
|
||||
|
||||
}
|
||||
export interface ProcessConfig {
|
||||
arguments: string[];
|
||||
entrypoint: string;
|
||||
privileged: boolean;
|
||||
tty: boolean;
|
||||
user: string;
|
||||
}
|
||||
export interface ExecJson {
|
||||
CanRemove: boolean;
|
||||
ContainerID: string;
|
||||
DetachKeys: string;
|
||||
ExitCode: number;
|
||||
ID: string;
|
||||
OpenStderr: boolean;
|
||||
OpenStdin: boolean;
|
||||
OpenStdout: boolean;
|
||||
ProcessConfig: ProcessConfig;
|
||||
Running: boolean;
|
||||
Pid: number;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ export * from './node'
|
||||
export * from './task'
|
||||
export * from './image'
|
||||
export * from './swarm'
|
||||
export * from './config'
|
||||
export * from './volume'
|
||||
export * from './system'
|
||||
export * from './network'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Labels, Options, StringMap } from '../common'
|
||||
import { Labels, Options, StringMap, Annotations } from '../common'
|
||||
|
||||
export declare namespace network {
|
||||
export interface Config {
|
||||
@@ -48,8 +48,7 @@ export declare namespace network {
|
||||
Tasks: Task;
|
||||
}
|
||||
|
||||
export interface NetworkResource {
|
||||
Name: string;
|
||||
export interface NetworkResource extends Annotations {
|
||||
Id: string;
|
||||
Created: string;
|
||||
Scope: string;
|
||||
@@ -63,7 +62,6 @@ export declare namespace network {
|
||||
ConfigOnly: boolean;
|
||||
Containers?: Containers;
|
||||
Options: Options;
|
||||
Labels: Labels;
|
||||
Peers: network.PeerInfo[];
|
||||
Services: network.ServiceInfo[];
|
||||
}
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import { Version, Labels, Meta } from '../common'
|
||||
|
||||
export declare namespace swarm {
|
||||
export interface Version {
|
||||
Index: number;
|
||||
}
|
||||
|
||||
export interface Labels {
|
||||
}
|
||||
|
||||
export interface Orchestration {
|
||||
TaskHistoryRetentionLimit?: number;
|
||||
}
|
||||
@@ -55,11 +50,8 @@ export declare namespace swarm {
|
||||
Manager: string;
|
||||
}
|
||||
|
||||
export interface Info {
|
||||
export interface Info extends Meta {
|
||||
ID: string;
|
||||
Version: Version;
|
||||
CreatedAt: string;
|
||||
UpdatedAt: string;
|
||||
Spec: Spec;
|
||||
TLSInfo: TLSInfo;
|
||||
RootRotationInProgress: boolean;
|
||||
|
||||
18
packages/docker-api/src/client/config.ts
Normal file
18
packages/docker-api/src/client/config.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import * as api from '../utils/api'
|
||||
import * as opts from '../api/opts'
|
||||
import * as types from '../api/types'
|
||||
import * as filterUtil from '../api/opts/filter'
|
||||
|
||||
export namespace config {
|
||||
export async function list(filter?: opts.config.FilterOpt) {
|
||||
return await api.get<types.config.Config[]>('/configs', {
|
||||
filters: filterUtil.toJSON(filter)
|
||||
});
|
||||
}
|
||||
export async function inspect(id: string) {
|
||||
return await api.get(`/configs/${id}`)
|
||||
}
|
||||
export async function create() {
|
||||
return await api.post<{}>('/configs/create')
|
||||
}
|
||||
}
|
||||
@@ -26,4 +26,29 @@ export namespace container {
|
||||
}
|
||||
return await api.stream(`/containers/${id}/logs`, data);
|
||||
}
|
||||
|
||||
export namespace exec {
|
||||
export function create(id: string, opts: opts.container.exec.Create = {}): Promise<types.container.exec.CreateResult> {
|
||||
let request = {
|
||||
AttachStdin: true,
|
||||
AttachStdout: true,
|
||||
AttachStderr: true,
|
||||
DetachKeys: 'ctrl-d',
|
||||
Tty: true,
|
||||
Cmd: '/bin/sh',
|
||||
...opts
|
||||
}
|
||||
request.AttachStderr = true
|
||||
return api.post<types.container.exec.CreateResult>(`/containers/${id}/exec`, request)
|
||||
}
|
||||
export function start(id: string, opts: opts.container.exec.Start = {}) {
|
||||
return api.post<types.container.exec.StartResult>(`/exec/${id}/start`, opts)
|
||||
}
|
||||
export function resize(id: string, opts: opts.container.exec.Resize = {}) {
|
||||
return api.post<types.container.exec.ResizeResult>(`/exec/${id}/resize`, opts)
|
||||
}
|
||||
export function inspect(id: string) {
|
||||
return api.get<types.container.exec.ExecJson>(`/exec/${id}/json`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ export * from './node'
|
||||
export * from './task'
|
||||
export * from './image'
|
||||
export * from './swarm'
|
||||
export * from './config'
|
||||
export * from './volume'
|
||||
export * from './system'
|
||||
export * from './network'
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import * as api from '../utils/api';
|
||||
import * as opts from '../api/opts';
|
||||
import * as types from '../api/types';
|
||||
import * as filterUtil from '../api/opts/filter'
|
||||
import * as http from 'http'
|
||||
|
||||
export namespace service {
|
||||
export async function list(filters?: opts.service.ListOpts) {
|
||||
return await api.get<types.service.Service[]>('/services', filters);
|
||||
export async function list(filter?: opts.service.FilterOpt) {
|
||||
return await api.get<types.service.Service[]>('/services', {
|
||||
filters: filterUtil.toJSON(filter)
|
||||
});
|
||||
}
|
||||
export async function create() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user