Skip to content

Commit

Permalink
Version 1.0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
zirkerc committed Jan 5, 2018
1 parent f680a12 commit 7db918b
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 4 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,16 @@ leo-cli publish . --filter MyBot


Deploying a Microservices to AWS
-------------------------------------
-------------------------------------

The deploy command can only be run after a microservice has been published. You must be inside a microservice directory to deploy.

The second parameter is the name of the AWS Stack for the microservice.

```
cd /MySystem/MyService
leo-cli deploy . TestMyService
leo-cli deploy . StageMyService
leo-cli deploy . ProdMyService
```

73 changes: 73 additions & 0 deletions leo-cli-deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env node

var path = require('path');
var program = require('commander');
var colors = require('colors');
var buildConfig = require("./lib/build-config").build;
var cloudformation = require("./lib/cloud-formation.js");
var aws = require("aws-sdk");
var fs = require("fs");

program
.version('0.0.1')
.option("--region [region]", "Region to run cloudformation")
.option("--url [url]", "s3 url to cloudformation.json")
.usage('<dir> <stack> [options]')
.action(function (dir, stack) {
let rootDir = path.resolve(process.cwd(), dir);
let configure = buildConfig(rootDir);
if (configure.type !== "microservice" && configure._meta.microserviceDir) {
rootDir = configure._meta.microserviceDir;
configure = buildConfig(rootDir);
}

program.region = program.region || (configure.regions || [])[0] || "us-west-2";

if (stack && typeof stack === "string") {
cloudformation.getBuckets([program.region], {}, (err, buckets) => {
const cloudFormationFile = path.resolve(path.resolve(dir, "cloudformation.json"));
const microservice = JSON.parse(fs.readFileSync(path.resolve(path.resolve(dir, "package.json"))));

if (!fs.existsSync(cloudFormationFile)) {
console.log("cloudformation.json file doesn't exist.\nRun the command 'leo-cli publish .'")
process.exit();
}
let version = microservice.version;
let s3region = program.region == "us-east-1" ? "" : "-" + program.region;
let bucket = {
region: program.region,
url: program.url || `https://s3${s3region}.amazonaws.com/${buckets[0].bucket}/${microservice.name}/${version}/`,
cloudFormation: JSON.parse(fs.readFileSync(cloudFormationFile))
};
let url = bucket.url + "cloudformation.json"
let updateStart = Date.now();
console.log(`\n---------------Updating stack "${stack}"---------------`);
console.log(`url: ${url}`);
let progress = setInterval(() => {
process.stdout.write(".")
}, 2000);
cloudformation.run(stack, program.region, url, {
Parameters: Object.keys(bucket.cloudFormation.Parameters || {}).map(key => {
return {
ParameterKey: key,
UsePreviousValue: true
}
})
}).then(data => {
clearInterval(progress);
console.log(` Update Complete ${Date.now() - updateStart}`);
}).catch(err => {
clearInterval(progress);
console.log(" Update Error:", err);
});
});
} else {
console.log("parameter 'stack' is required");
}

})
.parse(process.argv);

if (!process.argv.slice(2).length) {
program.outputHelp(colors.red);
}
2 changes: 2 additions & 0 deletions leo-cli-publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ program
.option("--build", "Only build")
.option("--public", "Make published version public")
.option("--run [stack]", "Run the published cloudformation")
.option("--deploy [stack]", "Deploys the published cloudformation")
.option("--patch [stack]", "Stack to get original cloudformation")
.option("--region [region]", "Region to run cloudformation")
.option("--force [bots]", "Force bots to publish")
Expand All @@ -23,6 +24,7 @@ program
let env = program.env || "dev";
// console.log(env)
let rootDir = path.resolve(process.cwd(), dir);
program.run = program.run || program.deploy;

let configure = buildConfig(rootDir);

Expand Down
1 change: 1 addition & 0 deletions leo-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var configure = require("./package.json");
program
.version(configure.version)
.command('publish [directory]', "Publish your project to S3")
.command('deploy [directory] [stack]', "Deploy your microservice to AWS")
.command('test [directory]', "Test your lambda")
.command('run [directory]', "Run your lambda")
.command('create [type] [directory]', "Create a new leo system, bot, resource, or microservice")
Expand Down
11 changes: 9 additions & 2 deletions lib/cloud-formation.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,8 @@ module.exports = {
}
});
});
}
},
getBuckets: getBuckets
};

function getBuckets(regions, opts, callback) {
Expand Down Expand Up @@ -519,14 +520,20 @@ function createStack(name, template, region, opts, done) {
opts = {};
}

var overridePrompts = {
"leosdk": "Leo Bus Stack Name: ",
"leoauth": "Leo Auth Stack Name: "
};

var parameterValues;
if (opts.Parameters) {
let prompt = require("prompt-sync")();
console.log("\n");
parameterValues = opts.Parameters.map(param => {
let p = overridePrompts[param.ParameterKey] || `Stack Parameter "${param.ParameterKey}": `;
return {
ParameterKey: param.ParameterKey,
ParameterValue: prompt(`Stack Parameter "${param.ParameterKey}"? `)
ParameterValue: prompt(p)
}
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "leo-cli",
"version": "1.0.12",
"version": "1.0.13",
"description": "",
"main": "index.js",
"directories": {
Expand Down

0 comments on commit 7db918b

Please sign in to comment.