-
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
6 changed files
with
99 additions
and
4 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
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,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); | ||
} |
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