Sync gRPC Compose API, added compose example

Signed-off-by: Guillaume Tardif <guillaume.tardif@docker.com>
This commit is contained in:
Guillaume Tardif 2020-11-17 11:49:46 +01:00
Родитель cd16904698
Коммит 368663ca7c
7 изменённых файлов: 1853 добавлений и 4 удалений

33
examples/compose.ts Normal file
Просмотреть файл

@ -0,0 +1,33 @@
/*
Copyright 2020 Docker CLI JavaScript SDK authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import * as grpc from '@grpc/grpc-js';
import { Compose } from '../src';
import { ComposeStacksRequest, ComposeStacksResponse } from '../src/compose';
const client = new Compose();
client.stacks(new ComposeStacksRequest(),
(error: grpc.ServiceError | null, res: ComposeStacksResponse) => {
if (error != null) {
throw error;
}
res.getStacksList().forEach(stack => {
console.log(stack.getName() + " - " + stack.getStatus())
});
}
)

17
src/compose.ts Normal file
Просмотреть файл

@ -0,0 +1,17 @@
/*
Copyright 2020 Docker CLI JavaScript SDK authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
export * from './protos/compose/v1/compose_pb';

Просмотреть файл

@ -22,6 +22,8 @@ option go_package = "github.com/docker/compose-cli/protos/compose/v1;v1";
service Compose {
rpc Up(ComposeUpRequest) returns (ComposeUpResponse);
rpc Down(ComposeDownRequest) returns (ComposeDownResponse);
rpc Stacks(ComposeStacksRequest)returns (ComposeStacksResponse);
rpc Services(ComposeServicesRequest)returns (ComposeServicesResponse);
}
message ComposeUpRequest {
@ -31,10 +33,48 @@ message ComposeUpRequest {
}
message ComposeUpResponse {
string projectName = 1;
}
message ComposeDownRequest {
string projectName = 1;
string workDir = 2;
repeated string files = 3;
}
message ComposeDownResponse {
string projectName = 1;
}
message ComposeStacksRequest {
string projectName = 1;
}
message ComposeStacksResponse {
repeated Stack stacks = 1;
}
message Stack {
string id = 1;
string name = 2;
string status = 3;
string reason = 4;
}
message ComposeServicesRequest {
string projectName = 1;
string workDir = 2;
repeated string files = 3;
}
message ComposeServicesResponse {
repeated Service services = 1;
}
message Service {
string id = 1;
string name = 2;
uint32 replicas = 3;
uint32 desired = 4;
repeated string Ports = 5;
}

34
src/protos/compose/v1/compose_grpc_pb.d.ts поставляемый
Просмотреть файл

@ -11,6 +11,8 @@ import * as compose_v1_compose_pb from "../../compose/v1/compose_pb";
interface IComposeService extends grpc.ServiceDefinition<grpc.UntypedServiceImplementation> {
up: IComposeService_IUp;
down: IComposeService_IDown;
stacks: IComposeService_IStacks;
services: IComposeService_IServices;
}
interface IComposeService_IUp extends grpc.MethodDefinition<compose_v1_compose_pb.ComposeUpRequest, compose_v1_compose_pb.ComposeUpResponse> {
@ -31,12 +33,32 @@ interface IComposeService_IDown extends grpc.MethodDefinition<compose_v1_compose
responseSerialize: grpc.serialize<compose_v1_compose_pb.ComposeDownResponse>;
responseDeserialize: grpc.deserialize<compose_v1_compose_pb.ComposeDownResponse>;
}
interface IComposeService_IStacks extends grpc.MethodDefinition<compose_v1_compose_pb.ComposeStacksRequest, compose_v1_compose_pb.ComposeStacksResponse> {
path: string; // "/com.docker.api.protos.compose.v1.Compose/Stacks"
requestStream: false;
responseStream: false;
requestSerialize: grpc.serialize<compose_v1_compose_pb.ComposeStacksRequest>;
requestDeserialize: grpc.deserialize<compose_v1_compose_pb.ComposeStacksRequest>;
responseSerialize: grpc.serialize<compose_v1_compose_pb.ComposeStacksResponse>;
responseDeserialize: grpc.deserialize<compose_v1_compose_pb.ComposeStacksResponse>;
}
interface IComposeService_IServices extends grpc.MethodDefinition<compose_v1_compose_pb.ComposeServicesRequest, compose_v1_compose_pb.ComposeServicesResponse> {
path: string; // "/com.docker.api.protos.compose.v1.Compose/Services"
requestStream: false;
responseStream: false;
requestSerialize: grpc.serialize<compose_v1_compose_pb.ComposeServicesRequest>;
requestDeserialize: grpc.deserialize<compose_v1_compose_pb.ComposeServicesRequest>;
responseSerialize: grpc.serialize<compose_v1_compose_pb.ComposeServicesResponse>;
responseDeserialize: grpc.deserialize<compose_v1_compose_pb.ComposeServicesResponse>;
}
export const ComposeService: IComposeService;
export interface IComposeServer {
up: grpc.handleUnaryCall<compose_v1_compose_pb.ComposeUpRequest, compose_v1_compose_pb.ComposeUpResponse>;
down: grpc.handleUnaryCall<compose_v1_compose_pb.ComposeDownRequest, compose_v1_compose_pb.ComposeDownResponse>;
stacks: grpc.handleUnaryCall<compose_v1_compose_pb.ComposeStacksRequest, compose_v1_compose_pb.ComposeStacksResponse>;
services: grpc.handleUnaryCall<compose_v1_compose_pb.ComposeServicesRequest, compose_v1_compose_pb.ComposeServicesResponse>;
}
export interface IComposeClient {
@ -46,6 +68,12 @@ export interface IComposeClient {
down(request: compose_v1_compose_pb.ComposeDownRequest, callback: (error: grpc.ServiceError | null, response: compose_v1_compose_pb.ComposeDownResponse) => void): grpc.ClientUnaryCall;
down(request: compose_v1_compose_pb.ComposeDownRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: compose_v1_compose_pb.ComposeDownResponse) => void): grpc.ClientUnaryCall;
down(request: compose_v1_compose_pb.ComposeDownRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: compose_v1_compose_pb.ComposeDownResponse) => void): grpc.ClientUnaryCall;
stacks(request: compose_v1_compose_pb.ComposeStacksRequest, callback: (error: grpc.ServiceError | null, response: compose_v1_compose_pb.ComposeStacksResponse) => void): grpc.ClientUnaryCall;
stacks(request: compose_v1_compose_pb.ComposeStacksRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: compose_v1_compose_pb.ComposeStacksResponse) => void): grpc.ClientUnaryCall;
stacks(request: compose_v1_compose_pb.ComposeStacksRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: compose_v1_compose_pb.ComposeStacksResponse) => void): grpc.ClientUnaryCall;
services(request: compose_v1_compose_pb.ComposeServicesRequest, callback: (error: grpc.ServiceError | null, response: compose_v1_compose_pb.ComposeServicesResponse) => void): grpc.ClientUnaryCall;
services(request: compose_v1_compose_pb.ComposeServicesRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: compose_v1_compose_pb.ComposeServicesResponse) => void): grpc.ClientUnaryCall;
services(request: compose_v1_compose_pb.ComposeServicesRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: compose_v1_compose_pb.ComposeServicesResponse) => void): grpc.ClientUnaryCall;
}
export class ComposeClient extends grpc.Client implements IComposeClient {
@ -56,4 +84,10 @@ export class ComposeClient extends grpc.Client implements IComposeClient {
public down(request: compose_v1_compose_pb.ComposeDownRequest, callback: (error: grpc.ServiceError | null, response: compose_v1_compose_pb.ComposeDownResponse) => void): grpc.ClientUnaryCall;
public down(request: compose_v1_compose_pb.ComposeDownRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: compose_v1_compose_pb.ComposeDownResponse) => void): grpc.ClientUnaryCall;
public down(request: compose_v1_compose_pb.ComposeDownRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: compose_v1_compose_pb.ComposeDownResponse) => void): grpc.ClientUnaryCall;
public stacks(request: compose_v1_compose_pb.ComposeStacksRequest, callback: (error: grpc.ServiceError | null, response: compose_v1_compose_pb.ComposeStacksResponse) => void): grpc.ClientUnaryCall;
public stacks(request: compose_v1_compose_pb.ComposeStacksRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: compose_v1_compose_pb.ComposeStacksResponse) => void): grpc.ClientUnaryCall;
public stacks(request: compose_v1_compose_pb.ComposeStacksRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: compose_v1_compose_pb.ComposeStacksResponse) => void): grpc.ClientUnaryCall;
public services(request: compose_v1_compose_pb.ComposeServicesRequest, callback: (error: grpc.ServiceError | null, response: compose_v1_compose_pb.ComposeServicesResponse) => void): grpc.ClientUnaryCall;
public services(request: compose_v1_compose_pb.ComposeServicesRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: compose_v1_compose_pb.ComposeServicesResponse) => void): grpc.ClientUnaryCall;
public services(request: compose_v1_compose_pb.ComposeServicesRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: compose_v1_compose_pb.ComposeServicesResponse) => void): grpc.ClientUnaryCall;
}

Просмотреть файл

@ -42,6 +42,50 @@ function deserialize_com_docker_api_protos_compose_v1_ComposeDownResponse(buffer
return compose_v1_compose_pb.ComposeDownResponse.deserializeBinary(new Uint8Array(buffer_arg));
}
function serialize_com_docker_api_protos_compose_v1_ComposeServicesRequest(arg) {
if (!(arg instanceof compose_v1_compose_pb.ComposeServicesRequest)) {
throw new Error('Expected argument of type com.docker.api.protos.compose.v1.ComposeServicesRequest');
}
return Buffer.from(arg.serializeBinary());
}
function deserialize_com_docker_api_protos_compose_v1_ComposeServicesRequest(buffer_arg) {
return compose_v1_compose_pb.ComposeServicesRequest.deserializeBinary(new Uint8Array(buffer_arg));
}
function serialize_com_docker_api_protos_compose_v1_ComposeServicesResponse(arg) {
if (!(arg instanceof compose_v1_compose_pb.ComposeServicesResponse)) {
throw new Error('Expected argument of type com.docker.api.protos.compose.v1.ComposeServicesResponse');
}
return Buffer.from(arg.serializeBinary());
}
function deserialize_com_docker_api_protos_compose_v1_ComposeServicesResponse(buffer_arg) {
return compose_v1_compose_pb.ComposeServicesResponse.deserializeBinary(new Uint8Array(buffer_arg));
}
function serialize_com_docker_api_protos_compose_v1_ComposeStacksRequest(arg) {
if (!(arg instanceof compose_v1_compose_pb.ComposeStacksRequest)) {
throw new Error('Expected argument of type com.docker.api.protos.compose.v1.ComposeStacksRequest');
}
return Buffer.from(arg.serializeBinary());
}
function deserialize_com_docker_api_protos_compose_v1_ComposeStacksRequest(buffer_arg) {
return compose_v1_compose_pb.ComposeStacksRequest.deserializeBinary(new Uint8Array(buffer_arg));
}
function serialize_com_docker_api_protos_compose_v1_ComposeStacksResponse(arg) {
if (!(arg instanceof compose_v1_compose_pb.ComposeStacksResponse)) {
throw new Error('Expected argument of type com.docker.api.protos.compose.v1.ComposeStacksResponse');
}
return Buffer.from(arg.serializeBinary());
}
function deserialize_com_docker_api_protos_compose_v1_ComposeStacksResponse(buffer_arg) {
return compose_v1_compose_pb.ComposeStacksResponse.deserializeBinary(new Uint8Array(buffer_arg));
}
function serialize_com_docker_api_protos_compose_v1_ComposeUpRequest(arg) {
if (!(arg instanceof compose_v1_compose_pb.ComposeUpRequest)) {
throw new Error('Expected argument of type com.docker.api.protos.compose.v1.ComposeUpRequest');
@ -88,6 +132,28 @@ var ComposeService = exports.ComposeService = {
responseSerialize: serialize_com_docker_api_protos_compose_v1_ComposeDownResponse,
responseDeserialize: deserialize_com_docker_api_protos_compose_v1_ComposeDownResponse,
},
stacks: {
path: '/com.docker.api.protos.compose.v1.Compose/Stacks',
requestStream: false,
responseStream: false,
requestType: compose_v1_compose_pb.ComposeStacksRequest,
responseType: compose_v1_compose_pb.ComposeStacksResponse,
requestSerialize: serialize_com_docker_api_protos_compose_v1_ComposeStacksRequest,
requestDeserialize: deserialize_com_docker_api_protos_compose_v1_ComposeStacksRequest,
responseSerialize: serialize_com_docker_api_protos_compose_v1_ComposeStacksResponse,
responseDeserialize: deserialize_com_docker_api_protos_compose_v1_ComposeStacksResponse,
},
services: {
path: '/com.docker.api.protos.compose.v1.Compose/Services',
requestStream: false,
responseStream: false,
requestType: compose_v1_compose_pb.ComposeServicesRequest,
responseType: compose_v1_compose_pb.ComposeServicesResponse,
requestSerialize: serialize_com_docker_api_protos_compose_v1_ComposeServicesRequest,
requestDeserialize: deserialize_com_docker_api_protos_compose_v1_ComposeServicesRequest,
responseSerialize: serialize_com_docker_api_protos_compose_v1_ComposeServicesResponse,
responseDeserialize: deserialize_com_docker_api_protos_compose_v1_ComposeServicesResponse,
},
};
exports.ComposeClient = grpc.makeGenericClientConstructor(ComposeService);

192
src/protos/compose/v1/compose_pb.d.ts поставляемый
Просмотреть файл

@ -38,6 +38,9 @@ export namespace ComposeUpRequest {
}
export class ComposeUpResponse extends jspb.Message {
getProjectname(): string;
setProjectname(value: string): ComposeUpResponse;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): ComposeUpResponse.AsObject;
@ -51,10 +54,22 @@ export class ComposeUpResponse extends jspb.Message {
export namespace ComposeUpResponse {
export type AsObject = {
projectname: string,
}
}
export class ComposeDownRequest extends jspb.Message {
getProjectname(): string;
setProjectname(value: string): ComposeDownRequest;
getWorkdir(): string;
setWorkdir(value: string): ComposeDownRequest;
clearFilesList(): void;
getFilesList(): Array<string>;
setFilesList(value: Array<string>): ComposeDownRequest;
addFiles(value: string, index?: number): string;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): ComposeDownRequest.AsObject;
@ -68,10 +83,16 @@ export class ComposeDownRequest extends jspb.Message {
export namespace ComposeDownRequest {
export type AsObject = {
projectname: string,
workdir: string,
filesList: Array<string>,
}
}
export class ComposeDownResponse extends jspb.Message {
getProjectname(): string;
setProjectname(value: string): ComposeDownResponse;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): ComposeDownResponse.AsObject;
@ -85,5 +106,176 @@ export class ComposeDownResponse extends jspb.Message {
export namespace ComposeDownResponse {
export type AsObject = {
projectname: string,
}
}
export class ComposeStacksRequest extends jspb.Message {
getProjectname(): string;
setProjectname(value: string): ComposeStacksRequest;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): ComposeStacksRequest.AsObject;
static toObject(includeInstance: boolean, msg: ComposeStacksRequest): ComposeStacksRequest.AsObject;
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
static serializeBinaryToWriter(message: ComposeStacksRequest, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): ComposeStacksRequest;
static deserializeBinaryFromReader(message: ComposeStacksRequest, reader: jspb.BinaryReader): ComposeStacksRequest;
}
export namespace ComposeStacksRequest {
export type AsObject = {
projectname: string,
}
}
export class ComposeStacksResponse extends jspb.Message {
clearStacksList(): void;
getStacksList(): Array<Stack>;
setStacksList(value: Array<Stack>): ComposeStacksResponse;
addStacks(value?: Stack, index?: number): Stack;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): ComposeStacksResponse.AsObject;
static toObject(includeInstance: boolean, msg: ComposeStacksResponse): ComposeStacksResponse.AsObject;
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
static serializeBinaryToWriter(message: ComposeStacksResponse, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): ComposeStacksResponse;
static deserializeBinaryFromReader(message: ComposeStacksResponse, reader: jspb.BinaryReader): ComposeStacksResponse;
}
export namespace ComposeStacksResponse {
export type AsObject = {
stacksList: Array<Stack.AsObject>,
}
}
export class Stack extends jspb.Message {
getId(): string;
setId(value: string): Stack;
getName(): string;
setName(value: string): Stack;
getStatus(): string;
setStatus(value: string): Stack;
getReason(): string;
setReason(value: string): Stack;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): Stack.AsObject;
static toObject(includeInstance: boolean, msg: Stack): Stack.AsObject;
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
static serializeBinaryToWriter(message: Stack, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): Stack;
static deserializeBinaryFromReader(message: Stack, reader: jspb.BinaryReader): Stack;
}
export namespace Stack {
export type AsObject = {
id: string,
name: string,
status: string,
reason: string,
}
}
export class ComposeServicesRequest extends jspb.Message {
getProjectname(): string;
setProjectname(value: string): ComposeServicesRequest;
getWorkdir(): string;
setWorkdir(value: string): ComposeServicesRequest;
clearFilesList(): void;
getFilesList(): Array<string>;
setFilesList(value: Array<string>): ComposeServicesRequest;
addFiles(value: string, index?: number): string;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): ComposeServicesRequest.AsObject;
static toObject(includeInstance: boolean, msg: ComposeServicesRequest): ComposeServicesRequest.AsObject;
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
static serializeBinaryToWriter(message: ComposeServicesRequest, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): ComposeServicesRequest;
static deserializeBinaryFromReader(message: ComposeServicesRequest, reader: jspb.BinaryReader): ComposeServicesRequest;
}
export namespace ComposeServicesRequest {
export type AsObject = {
projectname: string,
workdir: string,
filesList: Array<string>,
}
}
export class ComposeServicesResponse extends jspb.Message {
clearServicesList(): void;
getServicesList(): Array<Service>;
setServicesList(value: Array<Service>): ComposeServicesResponse;
addServices(value?: Service, index?: number): Service;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): ComposeServicesResponse.AsObject;
static toObject(includeInstance: boolean, msg: ComposeServicesResponse): ComposeServicesResponse.AsObject;
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
static serializeBinaryToWriter(message: ComposeServicesResponse, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): ComposeServicesResponse;
static deserializeBinaryFromReader(message: ComposeServicesResponse, reader: jspb.BinaryReader): ComposeServicesResponse;
}
export namespace ComposeServicesResponse {
export type AsObject = {
servicesList: Array<Service.AsObject>,
}
}
export class Service extends jspb.Message {
getId(): string;
setId(value: string): Service;
getName(): string;
setName(value: string): Service;
getReplicas(): number;
setReplicas(value: number): Service;
getDesired(): number;
setDesired(value: number): Service;
clearPortsList(): void;
getPortsList(): Array<string>;
setPortsList(value: Array<string>): Service;
addPorts(value: string, index?: number): string;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): Service.AsObject;
static toObject(includeInstance: boolean, msg: Service): Service.AsObject;
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
static serializeBinaryToWriter(message: Service, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): Service;
static deserializeBinaryFromReader(message: Service, reader: jspb.BinaryReader): Service;
}
export namespace Service {
export type AsObject = {
id: string,
name: string,
replicas: number,
desired: number,
portsList: Array<string>,
}
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу