Last active
April 16, 2016 18:37
-
-
Save jgensler8/5e0a2f9152ade575a6719282d583271e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var microlib = require('microlib'); | |
var name = microlib.defaultName(); | |
module.exports = { | |
name: microlib.builder() | |
.setName(name) | |
.setScheduleStrategy(microlib.COLOCATE_STRATEGY) | |
.setFunction(function(services, args) { | |
return args[1] + args[0]; | |
}) | |
.build() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is here for reference | |
FROM node | |
COPY ./microlib-current-app.js / | |
ENTRYPOINT node ./microlib-current-app.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var jayson = require(__dirname + '/../..'); | |
// create an array of injected services | |
var services = [ | |
{% for injectedService in injectedServices %} | |
jayson.client.http({ | |
port: microlib.lookupOrCreate({{ injectedService.name }}) | |
}), | |
{% endfor %} | |
]; | |
// create the current service | |
var server = jayson.server({ | |
{{ microlib_service_name }} : function(args, callback) { | |
var result = ({{ microlib_function }})(services, args); | |
callback(null, result ); | |
} | |
}); | |
server.http().listen( os.environ.MICROLIB_SERVICE_PORT ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var path = require('path'); | |
var util = require('util'); | |
var swig = require('swig'); | |
var dockerfile = require('dockerfile'); | |
var microserviceTemplate = swig.compileFile('./micolib-template.js'); | |
module.exports = { | |
builder: MicroserviceBuilder, | |
defaultName: function(){ return path.basename(__filename); } | |
}; | |
var Microservice = function(context){ | |
// template node service | |
var service = microserivceTemplate.render(context); | |
// somehow save it to a file | |
var savedFileName = "./local-rendered-file.js"; | |
var renderedTemplateFileName = util.format("%s.js", context.name); | |
var renderedTemplateFileDestination = util.format("/%s", renderedTemplateFileName); | |
// create the dockerfile | |
var entrypoint = util.format("node %s", renderedTemplateFileDestination); | |
dockerfile | |
.name(context.name) | |
.rem(context.name) | |
.version('1.0.0') | |
.dockerVersion('1.10.3') | |
.maintainer('you <[email protected]>') | |
.from('node') | |
.section('copy templated application') | |
// is there a COPY? | |
.add(savedFileName, renderedTemplateFileDestination) | |
.section('runtime') | |
.entrypoint(entrypoint) | |
.export(); | |
return { | |
run: run | |
} | |
} | |
var MicroserviceBuilder = function(){ | |
return { | |
microlib_service_name: "microlib_default_name", | |
microlib_injected_services: [], | |
injectService: injectService, | |
build: build, | |
setFunction: setFunction, | |
setName: setName | |
}; | |
} | |
function setName(service_name) { | |
this.microlib_service_name = service_name; | |
return this; | |
} | |
function setFunction(service_function) { | |
this.microlib_service_function = service_function; | |
return this; | |
} | |
function injectService(injectedServiceName) { | |
this.injectedServices.push({ | |
name: injectedServiceName | |
}) | |
return this; | |
} | |
function build() { | |
return new Microservice(this); | |
} | |
function run() { | |
// I am not sure if we guarentee that the service is built | |
// docker build -t this.microlib_service_name . | |
// docker start -e MICROLIB_SERVICE_PORT = RANDOM_PORT this.microlib_service_name | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment