Skip to content
This repository has been archived by the owner on Nov 14, 2019. It is now read-only.

implement new service start command #45

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/commands/daemon/start.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
40 changes: 40 additions & 0 deletions src/commands/service/newstart.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {flags} from '@oclif/command'

import Command from '../../service-command'

export default class ServiceDeployNew extends Command {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be named differently, ServiceStartNew, InstanceCreate...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when previous start cmd removed, this one will get its name. there is no reason to perfect the name of this temp cmd

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<string> {
const {args, flags} = this.parse(ServiceDeployNew)
this.spinner.start('Start service')
return new Promise<string>((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)
})
})
}
}
18 changes: 18 additions & 0 deletions src/protobuf/api/instance.proto
Original file line number Diff line number Diff line change
@@ -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;
}
10 changes: 10 additions & 0 deletions src/protobuf/definition/instance.proto
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions src/protobuf/definition/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
8 changes: 8 additions & 0 deletions src/root-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default {
engine: 'v0.10.1'
}
}