Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allowing parameters #387

Merged
merged 3 commits into from

2 participants

@cronopio
Collaborator

Errors with information, validate a little the options, and added the cloud object support to jitsu.start(), also give a located url when deploy with custom options.

@indexzero @mmalecki @AvianFlu

@cronopio
Collaborator

nodejitsu/nodejitsu-api@573d928 This is needed to pass the test failing

@AvianFlu AvianFlu merged commit 5688fe4 into master
@AvianFlu AvianFlu deleted the allowing-parameters branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
129 lib/jitsu/commands/apps.js
@@ -63,13 +63,51 @@ function handleStartError(err, name, callback) {
// 5. Starts the application
//
apps.deploy = function (callback) {
- var dir = process.cwd(), pkg;
+ var dir = process.cwd(),
+ args = utile.args(arguments),
+ cloud = {},
+ pkg;
//
// Allows arbitrary amount of arguments to deploy
//
if (arguments.length) {
- callback = utile.args(arguments).callback;
+ callback = args.callback;
+ }
+
+ //
+ // Allow use provider name and datacenter name without flags (--provider, --datacenter)
+ //
+ if (arguments.length === 2) {
+ jitsu.log.error('Error: No datacenter name specified');
+ jitsu.log.error('Please use a valid datacenter name.');
+
+ return jitsu.apps.endpoints(function (err, endpoints) {
+ if (err) return callback(err);
+
+ if (endpoints) {
+ jitsu.log.info('You can use one of the following providers');
+ Object.keys(endpoints).forEach(function (provider) {
+ var datacenters = endpoints[provider];
+ Object.keys(datacenters).forEach(function (datacenter) {
+ jitsu.log.data('jitsu deploy ' + provider + ' ' + datacenter);
+ });
+ });
+ }
+
+ return callback(new Error(), true);
+ });
+ }
+
+ if (arguments.length === 3) {
+ cloud.provider = args[0];
+ cloud.datacenter = args[1];
+ }
+
+ // Setup of cloud parameters specified using (--)
+ if (jitsu.argv['provider'] || jitsu.argv['datacenter']) {
+ cloud.provider = jitsu.argv['provider'];
+ cloud.datacenter = jitsu.argv['datacenter'];
}
function promptLogin () {
@@ -101,13 +139,46 @@ apps.deploy = function (callback) {
// existing.state is thrown away in check app.
// these closures would need to be rearanged so that this closure can see the result of view..
//
- apps.start(existing.name, function (err) {
+
+ //
+ // Enable custom drone number and memory ram
+ //
+ if (jitsu.argv['drones'] && typeof jitsu.argv['drones'] === 'number') {
+ cloud.drones = jitsu.argv['drones'];
+ } else if (cloud.provider && cloud.datacenter) {
+ // Default drones to 1
+ cloud.drones = 1;
+ }
+
+ if (jitsu.argv['ram'] && typeof jitsu.argv['ram'] === 'number') {
+ if ([1, 256, 512, 1024].indexOf(jitsu.argv['ram']) === -1) {
+ jitsu.log.warn('Invalid value of parameter: --ram, using 256 as default');
+ cloud.ram = 256;
+ } else {
+ cloud.ram = jitsu.argv['ram'];
+ }
+ } else if (cloud.provider && cloud.datacenter) {
+ // Default ram to 256
+ cloud.ram = 256;
+ }
+
+ var next = function next (err) {
if (err) {
return callback(err);
}
jitsu.package.runScript(pkg, 'postdeploy', callback);
- });
+ };
+
+ // Only if all options are correct we pass cloud options
+ if (cloud.provider && cloud.datacenter && cloud.drones && cloud.ram) {
+ jitsu.log.info('Deploying application in cloud with:')
+ jitsu.inspect.putObject(cloud);
+ apps.start(existing.name, cloud, next);
+ } else {
+ apps.start(existing.name, next);
+ }
+
//}
//else {
// apps.start(existing.name, callback);
@@ -574,7 +645,7 @@ apps.destroy.usage = [
// Starts the application specified by `name`. If no name is supplied
// this will start the application in the current directory.
//
-apps.start = function (name, callback) {
+apps.start = function (name, cloud, callback) {
//
// Allows arbitrary amount of arguments
@@ -583,26 +654,66 @@ apps.start = function (name, callback) {
var args = utile.args(arguments);
callback = args.callback;
name = args[0] || null;
+ cloud = args[1] || null;
+ }
+
+ // Little check when call jitsu start directly
+ if (typeof cloud === 'string') {
+ cloud = { provider: cloud };
+ if (args[2]) {
+ cloud.datacenter = args[2];
+ } else {
+ jitsu.log.error('Error: No datacenter name specified');
+ jitsu.log.error('Please use a valid datacenter name.');
+ return callback(new Error(), true)
+ }
}
function executeStart() {
jitsu.log.info('Starting app ' + name.magenta);
- jitsu.apps.start(name, function (err) {
+ var showInfo = function showInfo (err, config) {
if (err) {
return handleStartError(err, name, callback);
}
- jitsu.apps.view(name, function (err, app) {
+ async.series({
+ //
+ // 1. Fetch the endpoints so that we can properly
+ // tell the user what datacenter they are in later.
+ //
+ endpoints: function getEndpoints(next) {
+ jitsu.apps.endpoints(next);
+ },
+ //
+ // 2. Get app information to show the proper subdomain.
+ //
+ app: function start(next) {
+ jitsu.apps.view(name, next);
+ }
+ }, function (err, result) {
if (err) {
return callback(err);
}
+ var endpoints = result.endpoints,
+ tld = (config && config.provider && config.datacenter)
+ ? result.endpoints[config.provider][config.datacenter]
+ : 'api.jit.su',
+ subdomain = result.app.subdomain;
+
jitsu.log.info('App ' + name.magenta + ' is now started');
- jitsu.log.info(('http://' + app.subdomain + '.jit.su').magenta + ' on Port ' + '80'.magenta);
+ jitsu.log.info(('http://' + subdomain + tld.replace('api', '')).magenta + ' on Port ' + '80'.magenta);
callback();
});
- });
+ }
+
+ if (cloud) {
+ return jitsu.apps.start(name, [cloud], showInfo);
+ } else {
+ return jitsu.apps.start(name, showInfo);
+ }
+
}
if (!name) {
View
2  package.json
@@ -30,7 +30,7 @@
"fstream-npm": "0.1.1",
"ladder": "0.0.0",
"npm": "1.1.59",
- "nodejitsu-api": "0.4.1",
+ "nodejitsu-api": "0.4.2",
"opener": "1.3.x",
"pkginfo": "0.2.3",
"progress": "0.1.0",
View
9 test/commands/apps-test.js
@@ -42,13 +42,13 @@ function shouldAcceptAllCloudOptions(suite, command) {
'--drones 2 --ram 512'
];
- if (command === 'deploy') {
+ if (/^deploy/.test(command)) {
combinations.push('--provider joyent');
combinations.push('--datacenter us-east-1');
combinations.push('--provider joyent --datacenter us-east-1');
}
- var setupFn = (command === 'deploy') ? setupDeploy : setupCloud;
+ var setupFn = (/^deploy/.test(command)) ? setupDeploy : setupCloud;
combinations.forEach(function (argv) {
var drones = /--drones\s(\d{1})/.exec(argv),
@@ -875,4 +875,9 @@ shouldAcceptAllCloudOptions(
'deploy'
);
+shouldAcceptAllCloudOptions(
+ suite,
+ 'deploy joyent us-east-1'
+);
+
suite.export(module);
View
2  test/commands/snapshots-test.js
@@ -103,6 +103,8 @@ vows.describe('jitsu/commands/snapshots').addBatch({
.reply(200, '', { 'x-powered-by': 'Nodejitsu' })
.post('/apps/tester/application2/start', {})
.reply(200, '', { 'x-powered-by': 'Nodejitsu' })
+ .get('/endpoints')
+ .reply(200, endpoints, { 'x-powered-by': 'Nodejitsu' })
.get('/apps/tester/application2', '')
.reply(200, { app: {
subdomain: "tester.application2"
Something went wrong with that request. Please try again.