Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make bootstrapping more generic, add `santa image`

  • Loading branch information...
commit 391e16013499982fa4470a9aa6390aa01ca09b60 1 parent 85a9d58
@mmalecki authored
View
37 lib/bootstrapper/bootstrap.js
@@ -1,5 +1,4 @@
var path = require('path');
-var animal = require('animal-id');
var pkgcloud = require('pkgcloud');
var Bootstrapper = require('pkgcloud-bootstrapper');
var santa = require('../../');
@@ -7,7 +6,7 @@ var inspect = require('../utils/inspect');
var image = require('./image.js');
module.exports = function bootstrap(options, callback) {
- var client = pkgcloud.compute.createClient(options.compute);
+ var client = options.compute;
var bootstrapper = new Bootstrapper({
compute: client,
@@ -18,12 +17,6 @@ module.exports = function bootstrap(options, callback) {
});
var name = options.name;
- if (!name && options.app) {
- name = options.app.name + '-' + options.app.version + '-' + animal.getId();
- }
- else {
- name = animal.getUuid();
- }
client.listKeys(function (err, keys) {
if (err) {
@@ -35,15 +28,10 @@ module.exports = function bootstrap(options, callback) {
'cd package'
];
- if (options.image) {
- commands.push('scripts/install');
- }
- else if (options.start) {
- commands.push('scripts/configure', 'scripts/start');
- }
- else {
- commands.push('scripts/install', 'scripts/configure', 'scripts/start');
- }
+ var scripts = options.scripts || ['install', 'configure', 'start'];
+ Array.prototype.push.apply(commands, scripts.map(function (script) {
+ return 'scripts/' + script;
+ }));
var createOptions = {
name: name,
@@ -85,20 +73,7 @@ module.exports = function bootstrap(options, callback) {
ee.on('complete', function (server) {
santa.log.info('Server creation complete');
inspect.server(server);
-
- if (options.image) {
- santa.log.info('Imaging the server');
- image({
- name: name,
- server: server,
- compute: client
- }, function (err, image) {
- santa.log.info('Image created');
- inspect.image(image);
- });
- }
+ callback(null, server);
});
-
- callback(null, ee);
});
};
View
21 lib/bootstrapper/image.js
@@ -0,0 +1,21 @@
+var async = require('async');
+var uuid = require('node-uuid');
+
+module.exports = function image(options, callback) {
+ var client = options.compute;
+ var server = options.server;
+ var name = options.name;
+ var image;
+
+ santa.log.info('Imaging the server');
+ async.waterfall([
+ client.shutdownServer.bind(client, server),
+ function createImage(next) {
+ client.createImage({
+ server: server,
+ name: name,
+ }, next);
+ },
+ client.destroyServer.bind(client, server)
+ ], callback);
+};
View
8 lib/commands/deploy.js
@@ -1,6 +1,7 @@
var path = require('path');
var santa = require('../..');
var async = require('async');
+var animal = require('animal-id');
var readPackageJson = require('read-package-json');
var build = require('../bootstrapper/build.js');
var bootstrap = require('../bootstrapper/bootstrap.js');
@@ -13,7 +14,7 @@ module.exports = function (callback) {
async.parallel({
build: async.apply(build, { path: cwd }),
- readPackage: async.apply(readPackageJson, path.join(cwd, 'package.json'))
+ package: async.apply(readPackageJson, path.join(cwd, 'package.json'))
}, function (err, results) {
var output, options;
@@ -25,10 +26,9 @@ module.exports = function (callback) {
santa.log.info('Application build to ' + results.build);
options = {
- compute: santa.config.get('provider'),
+ compute: santa.pkgcloud,
package: results.build,
- app: results.readPackage,
- image: santa.argv.image
+ name: [ results.package.name, results.package.version, animal.getId() ].join('-')
};
bootstrap(options, function (err, ee) {
View
43 lib/commands/image.js
@@ -0,0 +1,43 @@
+var path = require('path');
+var santa = require('../..');
+var async = require('async');
+var readPackageJson = require('read-package-json');
+var build = require('../bootstrapper/build.js');
+var bootstrap = require('../bootstrapper/bootstrap.js');
+
+module.exports = function (callback) {
+ santa.log.info('Imaging application...');
+ santa.log.info('Building application...');
+
+ var cwd = process.cwd();
+
+ async.parallel({
+ build: async.apply(build, { path: cwd }),
+ readPackage: async.apply(readPackageJson, path.join(cwd, 'package.json'))
+ }, function (err, results) {
+ var output, options;
+
+ if (err) {
+ bender.log.error('Build failed');
+ return callback(err);
+ }
+
+ santa.log.info('Application build to ' + results.build);
+
+ options = {
+ compute: santa.pkgcloud,
+ package: results.build,
+ name: results.app
+ image: santa.argv.image
+ };
+
+ image(options, function (err, ee) {
+ if (err) {
+ santa.log.error('Error while preparing server creation');
+ return callback(err);
+ }
+
+ ee.on('error', callback);
+ });
+ });
+};
View
3  package.json
@@ -12,7 +12,8 @@
"tar": "~0.1.19",
"fstream": "~0.1.25",
"fstream-npm": "~0.1.6",
- "read-package-json": "~1.1.4"
+ "read-package-json": "~1.1.4",
+ "node-uuid": "~1.4.1"
},
"main": "./lib/santa.js",
"bin": {
Please sign in to comment.
Something went wrong with that request. Please try again.