Comparing version 0.1.4 to 0.1.5
{ | ||
"name": "burn-it", | ||
"description": "", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Daniel Kang", |
@@ -15,3 +15,4 @@ 'use strict'; | ||
print = require('../print'), | ||
chalk = require('chalk'); | ||
chalk = require('chalk'), | ||
_ = require('lodash'); | ||
@@ -57,9 +58,6 @@ const packerBaseConfig = require(path.join(__dirname, '../resources', 'packer.json')); | ||
CreateImage.prototype.getBaseImageId = async(function* (baseImage) { | ||
CreateImage.prototype.getBaseImage = async(function* (baseImage, isName) { | ||
const self = this; | ||
if(/^ami-.+$/.test(baseImage)) { | ||
const image = yield self.ec2.getImage(baseImage); | ||
return image ? image.ImageId : null; | ||
} else { | ||
if(isName) { | ||
const baseImageNameAndVersion = naming.getNameAndVersion(baseImage); | ||
@@ -69,8 +67,14 @@ console.assert(baseImageNameAndVersion, 'Invalid base image name: ' + baseImage); | ||
const images = yield self.ec2.getImagesByBurnNameAndVersion(baseImageNameAndVersion[0], baseImageNameAndVersion[1]); | ||
const latestImage = images.slice(-1)[0]; | ||
return latestImage ? latestImage.ImageId : null; | ||
images.reverse(); | ||
return _.find(images, function(image) { | ||
return image.tags[naming.getImageNameTagKey()] === baseImage; | ||
}) || null; | ||
} else { | ||
console.assert(/^ami-.+$/.test(baseImage), 'Invalid base image ID: ' + baseImage); | ||
return (yield self.ec2.getImage(baseImage)) || null; | ||
} | ||
}); | ||
CreateImage.prototype.buildPackerConfig = async(function* () { | ||
CreateImage.prototype.buildPackerConfig = async(function* (baseImageId) { | ||
const self = this; | ||
@@ -84,2 +88,4 @@ | ||
if(baseImageId) { packerConfig.builders[0].source_ami = baseImageId; } | ||
yield P.each(self.components, async(function* (expr) { | ||
@@ -109,6 +115,2 @@ const component = createComponent(expr); | ||
const baseImageId = yield self.getBaseImageId(self.argv.baseImageId || self.argv.baseImage); | ||
console.assert(baseImageId, 'Cannot find the base image: ' + (self.argv.baseImageId || self.argv.baseImage)); | ||
packerConfig.builders[0].source_ami = baseImageId; | ||
packerConfig.builders[0].ami_name = self.imageName + '-' + self.imageVersion + '-x86_64-' + String(Date.now()) + '-ebs'; | ||
@@ -138,7 +140,18 @@ packerConfig.builders[0].access_key = self.awsAccessKey; | ||
const createImage = new CreateImage(imageName, imageVersion, argv._.slice(2), argv); | ||
const packerConfig = yield createImage.buildPackerConfig(); | ||
let baseImageId = null; | ||
if(argv.baseImageId || argv.baseImage) { | ||
print(chalk.bgGreen('Finding Base AMI...')); | ||
const baseImage = yield createImage.getBaseImage(argv.baseImageId || argv.baseImage, !argv.baseImageId) | ||
console.assert(baseImage, 'Cannot find the base image: ' + (argv.baseImageId || argv.baseImage)); | ||
print(chalk.gray(' > '), | ||
chalk.gray(baseImage.Name), ' ', chalk.white(baseImage.ImageId), ' ', chalk.cyan(baseImage.State)); | ||
print(); | ||
baseImageId = baseImage.ImageId; | ||
} | ||
const packerConfig = yield createImage.buildPackerConfig(baseImageId); | ||
print(chalk.bgGreen('Starting Packer build...')); | ||
print(); | ||
const packerExitCode = yield runPacker(packerConfig); | ||
@@ -154,3 +167,6 @@ if(packerExitCode) { return packerExitCode; } | ||
print(chalk.gray(' > '), chalk.green(newImage.ImageId)); | ||
print(chalk.gray(' > '), | ||
chalk.green(newImage.tags[naming.getImageNameTagKey()]), | ||
chalk.yellow('@' + newImage.tags[naming.getImageVersionTagKey()]), ' ', | ||
chalk.gray(newImage.Name), ' ', chalk.white(newImage.ImageId), ' ', chalk.cyan(newImage.State)); | ||
}); |
@@ -32,3 +32,3 @@ { | ||
"B": { | ||
"alias": "base-image-id", "type": "string", "default": "ami-bd58c98d", | ||
"alias": "base-image-id", "type": "string", | ||
"describe": "Base image AMI ID" | ||
@@ -35,0 +35,0 @@ }, |
29498
589