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

Commit

Permalink
implement new service start command
Browse files Browse the repository at this point in the history
under temporary service:start name.
  • Loading branch information
ilgooz committed Jun 4, 2019
1 parent 2376157 commit af545f2
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/commands/service/newstart.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {flags} from '@oclif/command'
import Command from '../../service-command'

export default class ServiceDeployNew extends Command {
static description = 'Start a service'

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({id: args.SERVICE, env: flags.env}, (err, resp) => {
if (err) {
reject(err)
this.spinner.stop(err)
return
}
this.spinner.stop(`${resp.sid} (${resp.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";

package api;

service Instance {
rpc Create (CreateInstanceRequest) returns (CreateInstanceResponse) {}
}

message CreateInstanceRequest {
string id = 1; // Service's sid or hash.
repeated string env = 2; // Env vars to apply to service's instance on runtime.
}

message CreateInstanceResponse {
string sid = 1; // Service's id.
string hash = 2; // Service's instance hash.
string serviceHash = 3; // Service's bare hash.
}
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.
}
9 changes: 9 additions & 0 deletions src/root-command.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import {Command, flags} from '@oclif/command'
import {join} from 'path'
import * as grpc from 'grpc'
Expand Down Expand Up @@ -29,6 +30,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 +52,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), {
Expand Down

0 comments on commit af545f2

Please sign in to comment.