-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
494 additions
and
8 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
LeoPlatform/cli | ||
=================== | ||
|
||
Leo CLI | ||
|
||
A Nodejs interface to interact with the Leo SDK and AWS | ||
|
||
Documentation: https://docs.leoplatform.io | ||
|
||
How to install the Leo SDK | ||
=================================== | ||
|
||
Pre-Requisites | ||
-------------- | ||
1. Install the aws-cli toolkit - Instructions for this are found at http://docs.aws.amazon.com/cli/latest/userguide/installing.html | ||
2. Configure the aws-cli tools - Instructions are found at http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html | ||
3. Install node - https://nodejs.org/en/ | ||
|
||
Install SDK | ||
----------- | ||
1. Install using npm. In your project folder run the following command. | ||
|
||
``` | ||
npm install leo-cli -g | ||
``` | ||
|
||
How to use the Leo SDK | ||
=================================== | ||
|
||
Create a System | ||
--------------- | ||
|
||
``` | ||
leo-cli create system MySystem | ||
``` | ||
|
||
Create a Microservice | ||
--------------- | ||
Inside a system directory | ||
|
||
``` | ||
leo-cli create microservice MyService | ||
``` | ||
|
||
|
||
Build Bots & Apis | ||
----------------- | ||
Inside a microservice directory | ||
|
||
``` | ||
leo-cli create load MyLoadBot | ||
leo-cli create enrich MyEnrichBot | ||
leo-cli create offload MyOffloadBot | ||
leo-cli create bot MyBot | ||
leo-cli create cron MyCronBot | ||
``` | ||
|
||
Testing Bots & Apis | ||
------------------- | ||
Inside the bot or resource directory | ||
|
||
``` | ||
leo-cli test . | ||
``` | ||
|
||
Runing Bots | ||
----------- | ||
Inside the bot or resource directory | ||
|
||
``` | ||
leo-cli run . | ||
``` | ||
|
||
Deploying Microservices, Bots, & Apis | ||
------------------------------------- | ||
|
||
``` | ||
leo-cli publish . | ||
``` | ||
|
||
options | ||
* --region awsRegion Sets the AWS Region. default: us-west-2 | ||
* --filter idGlobExp Filters the lambdas deployed by the given glob expression. default: * | ||
* --force botId|all Forces a bot to build event if version are the same (Must be included in --filter expression). default: false | ||
* --run awsStackName Runs the generated cloudformation.json against the AWS Stack 'awsStackName'. If the stack doesn't exist, it will be crated | ||
* --build Builds the cloudformation and lambdas but doesn't publish them to s3 | ||
* --public Makes the s3 publish folder public | ||
|
||
Version of the build using the microservice/bot/api package.json file. If a bot/api is forced to be built and has the same version number the current timestamp will be appended to he version | ||
|
||
Deploy Examples | ||
--------------- | ||
|
||
Publish a Microservice with all new/updated bots & apis | ||
|
||
``` | ||
cd /MySystem/MyService | ||
leo-cli publish . | ||
``` | ||
|
||
|
||
Publish a Microservice and force all bots & apis to build | ||
|
||
``` | ||
cd /MySystem/MyService | ||
leo-cli publish . | ||
``` | ||
|
||
|
||
Publish a single bot in a Microservice | ||
|
||
``` | ||
cd /MySystem/MyService/Bot1 | ||
leo-cli publish . | ||
``` | ||
|
||
|
||
Publish a single bot or resource in a Microservice | ||
|
||
``` | ||
cd /MySystem/MyService/Bot1 | ||
leo-cli publish . | ||
``` | ||
|
||
``` | ||
cd /MySystem/MyService | ||
leo-cli publish . --filter Bot1 | ||
``` | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
#!/usr/bin/env node | ||
|
||
var fs = require('fs'); | ||
var path = require('path'); | ||
var program = require('commander'); | ||
var colors = require('colors'); | ||
|
||
program | ||
.version('0.0.2') | ||
.arguments('<type> <dir>') | ||
.usage('<type> <dir> [options]') | ||
.action(function (type, dir) { | ||
var pkgname = null; | ||
let declaredType = type = type.toLowerCase(); | ||
|
||
|
||
var parentType = findFirstPackageValue(process.cwd(), [], "type"); | ||
|
||
let roots = { | ||
bot: new RegExp("bots[/\\\\]"), | ||
load: new RegExp("bots[/\\\\]"), | ||
enrich: new RegExp("bots[/\\\\]"), | ||
offload: new RegExp("bots[/\\\\]"), | ||
resource: new RegExp("apis[/\\\\]"), | ||
}; | ||
|
||
if (['system', 'microservice', 'resource', 'load', 'enrich', 'offload'].indexOf(type) === -1) { | ||
type = "bot"; | ||
} | ||
let prefix = "./"; | ||
|
||
if (roots[type] && !path.resolve(dir).match(roots[type])) { | ||
prefix = roots[type] || ""; | ||
} | ||
|
||
if (!fs.existsSync(prefix)) { | ||
fs.mkdirSync(prefix); | ||
} | ||
if (!fs.existsSync(prefix + dir)) { | ||
if (type == "microservice") { | ||
|
||
if (parentType != "system") { | ||
console.log(`Type ${type} must be within a system package`); | ||
process.exit(1); | ||
} | ||
|
||
copyDirectorySync(__dirname + "/templates/microservice", prefix + dir, { | ||
'____DIRNAME____': dir | ||
}); | ||
} else if (type == "system") { | ||
copyDirectorySync(__dirname + "/templates/system", prefix + dir, { | ||
'____DIRNAME____': dir | ||
}); | ||
} else { | ||
if (parentType != "microservice" && parentType != "system") { | ||
console.log(`Type ${type} must be within a system or microservice package`); | ||
process.exit(1); | ||
} | ||
|
||
copyDirectorySync(__dirname + `/templates/${type}`, prefix + dir, { | ||
'____DIRNAME____': dir, | ||
'____BOTNAME____': dir, | ||
'____BOTTYPE____': declaredType | ||
}); | ||
} | ||
|
||
process.chdir(prefix + dir); | ||
console.log("done"); | ||
|
||
} else { | ||
console.log("Directory already exists"); | ||
} | ||
}) | ||
.parse(process.argv); | ||
|
||
if (!process.argv.slice(2).length) { | ||
program.outputHelp(colors.red); | ||
} | ||
|
||
function copyDirectorySync(src, dest, replacements) { | ||
var stats = fs.statSync(src); | ||
if (stats.isDirectory()) { | ||
fs.mkdirSync(dest); | ||
fs.readdirSync(src).forEach(function (entry) { | ||
copyDirectorySync(path.join(src, entry), path.join(dest, entry), replacements); | ||
}); | ||
} else { | ||
var fileText = fs.readFileSync(src).toString('utf8'); | ||
for (var replaceVar in replacements) { | ||
fileText = fileText.replace(new RegExp(replaceVar, 'g'), replacements[replaceVar]); | ||
} | ||
|
||
fs.writeFileSync(dest, fileText); | ||
} | ||
} | ||
|
||
function findParentFiles(dir, filename) { | ||
var paths = []; | ||
do { | ||
paths.push(dir); | ||
|
||
var lastDir = dir; | ||
dir = path.resolve(dir, "../"); | ||
} while (dir != lastDir); | ||
|
||
var matches = []; | ||
paths.forEach(function (dir) { | ||
var file = path.resolve(dir, filename); | ||
if (fs.existsSync(file)) { | ||
|
||
matches.push(file); | ||
} | ||
}); | ||
|
||
return matches; | ||
} | ||
|
||
function findFirstPackageValue(dir, types, field, reverse) { | ||
if (!Array.isArray(types)) { | ||
types = [types]; | ||
} | ||
var paths = findParentFiles(dir, "package.json"); | ||
if (reverse) { | ||
paths.reverse(); | ||
} | ||
for (var i = 0; i < paths.length; i++) { | ||
var file = paths[i]; | ||
var pkg = require(file); | ||
if (pkg && pkg.config && pkg.config.leo && (types.length === 0 || types.indexOf(pkg.config.leo.type) !== -1)) { | ||
return pkg.config.leo[field]; | ||
} | ||
} | ||
return null; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env node | ||
|
||
require("./leo-cli-test"); |
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 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 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
"use strict"; | ||
|
||
var leo = require("leo-sdk"); | ||
exports.handler = function (event, context, callback) { | ||
// Do work | ||
callback(); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "____DIRNAME____", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"scripts": { | ||
"test": "leo-cli test . " | ||
}, | ||
"config": { | ||
"leo": { | ||
"type": "____BOTTYPE____", | ||
"memory": 128, | ||
"timeout": 10, | ||
"role": "ApiRole", | ||
"env": {}, | ||
"cron": { | ||
"settings": {}, | ||
"time": "0 */1 * * * * " | ||
} | ||
} | ||
}, | ||
"dependencies": { | ||
"leo-sdk": "^1.0.41" | ||
} | ||
} |
Oops, something went wrong.