diff --git a/src/commands/daemon/start.ts b/src/commands/daemon/start.ts index 96a65fe..3552513 100644 --- a/src/commands/daemon/start.ts +++ b/src/commands/daemon/start.ts @@ -1,7 +1,7 @@ import {flags} from '@oclif/command' import Command from '../../docker-command' -import version from '../../version'; +import version from '../../version' import Status, {ServiceStatus} from './status' diff --git a/src/commands/service/newstart.ts b/src/commands/service/newstart.ts new file mode 100644 index 0000000..588ce4c --- /dev/null +++ b/src/commands/service/newstart.ts @@ -0,0 +1,40 @@ +import {flags} from '@oclif/command' + +import Command from '../../service-command' + +export default class ServiceDeployNew extends Command { + static description = 'Start a service instance' + + static flags = { + ...Command.flags, + env: flags.string({ + description: 'set env defined in mesg.yml (configuration.env)', + multiple: true, + helpValue: 'FOO=BAR' + }) + } + + static args = [{ + name: 'SERVICE', + required: true, + description: 'Service\'s sid or hash' + }] + + static hidden = true + + async run(): Promise { + const {args, flags} = this.parse(ServiceDeployNew) + this.spinner.start('Start service') + return new Promise((resolve, reject) => { + this.instanceAPI.Create({serviceHash: args.SERVICE, env: flags.env}, (err, resp) => { + if (err) { + reject(err) + this.spinner.stop(err) + return + } + this.spinner.stop(resp.instance.hash) + resolve(resp.hash) + }) + }) + } +} diff --git a/src/protobuf/api/instance.proto b/src/protobuf/api/instance.proto new file mode 100644 index 0000000..77e699f --- /dev/null +++ b/src/protobuf/api/instance.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; + +import "protobuf/definition/instance.proto"; + +package api; + +service Instance { + rpc Create (CreateInstanceRequest) returns (CreateInstanceResponse) {} +} + +message CreateInstanceRequest { + string serviceHash = 1; // Service's sid or hash. + repeated string env = 2; // Env vars to apply to service's instance on runtime. +} + +message CreateInstanceResponse { + definition.Instance instance = 1; +} diff --git a/src/protobuf/definition/instance.proto b/src/protobuf/definition/instance.proto new file mode 100644 index 0000000..ab1620f --- /dev/null +++ b/src/protobuf/definition/instance.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +package definition; +option go_package = "github.com/mesg-foundation/core/protobuf/definition"; + +// Instance represents service's instance. +message Instance { + string hash = 1; + string serviceHash = 2; +} diff --git a/src/protobuf/definition/service.proto b/src/protobuf/definition/service.proto index 470b1da..ab7109d 100644 --- a/src/protobuf/definition/service.proto +++ b/src/protobuf/definition/service.proto @@ -63,4 +63,5 @@ message Dependency { repeated string ports = 4; // List of ports the container exposes. repeated string args = 6; // Args to pass to the container. string command = 5; // Command to run the container. + repeated string env = 9; // Default env vars to apply to dependency's instance on runtime. } diff --git a/src/root-command.ts b/src/root-command.ts index 674085b..fcdafe2 100644 --- a/src/root-command.ts +++ b/src/root-command.ts @@ -28,6 +28,7 @@ export default abstract class extends Command { private _mesg: Application | null = null private _serviceAPI: any + private _instanceAPI: any get engineEndpoint(): string { const host = process.env.DOCKER_HOST @@ -50,6 +51,13 @@ export default abstract class extends Command { return this._serviceAPI } + get instanceAPI() { + if (!this._instanceAPI) { + this._instanceAPI = this.createClient('Instance', 'api', 'instance.proto', this.engineEndpoint) + } + return this._instanceAPI + } + createClient(serviceName: string, dir: string, file: string, endpoint: string) { const packageDefinition = protoLoader.loadSync(join(__dirname, './protobuf', dir, file), { includeDirs: [__dirname] diff --git a/src/version.ts b/src/version.ts index bbe4bfd..7e3b514 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1,3 +1,3 @@ export default { engine: 'v0.10.1' -} \ No newline at end of file +}