From dcaefabc6c336e18b19f90de77a00fe4616b175a Mon Sep 17 00:00:00 2001 From: ekatek Date: Thu, 16 Oct 2014 12:31:59 -0700 Subject: [PATCH] cleaning up some of the get-machine stuff --- tools/commands-packages.js | 11 +--- tools/commands.js | 105 ++++++++++++++++++++----------------- tools/isopack.js | 9 ++++ 3 files changed, 68 insertions(+), 57 deletions(-) diff --git a/tools/commands-packages.js b/tools/commands-packages.js index 2356334e43..285c5effbf 100644 --- a/tools/commands-packages.js +++ b/tools/commands-packages.js @@ -254,10 +254,7 @@ main.registerCommand({ }; // We have initialized everything, so perform the publish oepration. - var allArchs = compileResult.isopack.buildArchitectures().split('+'); - var binary = !!(_.any(allArchs, function (arch) { - return arch.match(/^os\./); - })); + var binary = compileResult.isopack.platformSpecific(); var ec; // XXX maybe combine with messages? try { messages = buildmessage.capture({ @@ -910,11 +907,7 @@ main.registerCommand({ messages = buildmessage.capture({ title: "Publishing package " + name }, function () { - var allArchs = - prebuilt.compileResult.isopack.buildArchitectures().split('+'); - var binary = !!(_.any(allArchs, function (arch) { - return arch.match(/^os\./); - })); + var binary = prebuilt.compileResult.isopack.platformSpecific(); var opts = { new: !catalog.official.getPackage(name), diff --git a/tools/commands.js b/tools/commands.js index 5c4acb4ad1..23319ae492 100644 --- a/tools/commands.js +++ b/tools/commands.js @@ -36,9 +36,10 @@ var DEFAULT_PORT = '3000'; // Valid architectures that Meteor officially supports. var VALID_ARCHITECTURES = { - "os.osx.x86_64" : true, + "os.osx.x86_64": true, "os.linux.x86_64": true, - "os.linux.x86_32" : true }; + "os.linux.x86_32": true +}; // Given a site name passed on the command line (eg, 'mysite'), return // a fully-qualified hostname ('mysite.meteor.com'). @@ -66,6 +67,15 @@ var hostedWithGalaxy = function (site) { return !! require('./deploy-galaxy.js').discoverGalaxy(site); }; +// Display a message showing valid Meteor architectures. +var showInvalidArchMsg = function (arch) { + Console.info("Invalid architecture: " + arch); + Console.info("The following are valid Meteor architectures:"); + _.each(_.keys(VALID_ARCHITECTURES), function (va) { + Console.info(" " + va); + }); +}; + /////////////////////////////////////////////////////////////////////////////// // options that act like commands /////////////////////////////////////////////////////////////////////////////// @@ -638,10 +648,8 @@ var buildCommand = function (options) { // architectures. See archinfo.js for more information on what the // architectures are, what they mean, et cetera. if (options.architecture && - !VALID_ARCHITECTURES[options.architecture]) { - Console.stderr.write("Invalid architecture: " + options.architecture + "\n"); - Console.stderr.write( - "Please use one of the following: " + _.keys(VALID_ARCHITECTURES) + "\n"); + !_.has(VALID_ARCHITECTURES, options.architecture)) { + showInvalidArchMsg(options.architecture); return 1; } @@ -1877,23 +1885,19 @@ main.registerCommand({ verbose: { type: Boolean, short: "v", required: false }, // By default, we give you a machine for 5 minutes. You can request up to // 15. (MDG can reserve machines for longer than that.) - length: { type: Number, required: false } + minutes: { type: Number, required: false } } }, function (options) { // Check that we are asking for a valid architecture. var arch = options.args[0]; - if (!VALID_ARCHITECTURES[arch]){ - Console.info("Invalid architecture: " + arch); - Console.info("The following are valid Meteor architectures:"); - _.each(_.keys(VALID_ARCHITECTURES), function (va) { - Console.info(" " + va); - }); + if (!_.has(VALID_ARCHITECTURES, arch)){ + showInvalidArchMsg(arch); return 1; } - // Set the length. We will check validity on the server. - var length = options.length || 5; + // Set the minutes. We will check validity on the server. + var minutes = options.minutes || 5; // In verbose mode, we let you know what is going on. var maybeLog = function (string) { @@ -1908,7 +1912,7 @@ main.registerCommand({ config.getBuildFarmUrl(), config.getBuildFarmDomain(), "build-farm"); - } catch (err) { + } catch (err) { authClient.handlerConnectionError(err, "build farm"); return 1; } @@ -1921,29 +1925,13 @@ main.registerCommand({ // host: what you login into // port: port you should use // hostKey: RSA key to compare for safety. - var ret = conn.call('createBuildServer', arch, length); + var ret = conn.call('createBuildServer', arch, minutes); } catch (err) { authClient.handlerConnectionError(err, "build farm"); return 1; } conn.close(); - var child_process = require('child_process'); - - // Record the SSH Key in a temporary file on disk and give it the permissions - // that ssh-agent requires it to have. - var idpath = "/tmp/key-" + utils.randomToken(); - fs.writeFileSync(idpath, ret.sshKey, 'utf8'); - child_process.exec("chmod 400 " + idpath, - function (error, stdout, stderr) { - maybeLog(stdout); - if (error !== null) { - maybeLog("ERROR from chmod: " + stderr); - Console.error('cannot set permissions on SSH key: ' + error); - process.exit(1); - } - }); - // Possibly, the user asked us to return a JSON of the data and is going to process it // themselves. In that case, let's do that and exit. if (options.json) { @@ -1958,35 +1946,56 @@ main.registerCommand({ return 0; } + // Record the SSH Key in a temporary file on disk and give it the permissions + // that ssh-agent requires it to have. + var idpath = "/tmp/meteor-key-" + utils.randomToken(); + maybeLog("Writing ssh key to " + idpath); + fs.writeFileSync(idpath, ret.sshKey, {encoding: 'utf8', mode: 400}); + // Add the known host key to a custom known hosts file. - var hostpath = "/tmp/host-" + utils.randomToken(); + var hostpath = "/tmp/meteor-host-" + utils.randomToken(); var addendum = ret.host + " " + ret.hostKey; + maybeLog("Writing host key to " + hostpath); fs.writeFileSync(hostpath, addendum, 'utf8'); // Finally, connect to the machine. var login = ret.username + "@" + ret.host; var maybeVerbose = options.verbose ? "-v" : "-q"; - maybeLog( - "Connecting: ssh " + login + - " -i " + idpath + - " -p " + ret.port + - " -oUserKnownHostsFile=" + hostpath + - " " + maybeVerbose); - var future = new Future; - var sshCommand = child_process.spawn( - "ssh", - [login, + var connOptions = [ + login, "-i" + idpath, "-p" + ret.port, "-oUserKnownHostsFile=" + hostpath, - maybeVerbose], + maybeVerbose]; + + var printOptions = _.reduce(connOptions, + function (x, y) { + return x + " " + y; + }); + maybeLog("Connecting: ssh " + printOptions); + + var child_process = require('child_process'); + var future = new Future; + var sshCommand = child_process.spawn( + "ssh", connOptions, { stdio: 'inherit' }); // Redirect spawn stdio to process - sshCommand.on('exit', function (code) { - future.return(code); + sshCommand.on('exit', function (code, signal) { + if (signal) { + // XXX: We should process the signal in some way, but I am not sure we + // care right now. + future.return(1); + } else { + future.return(code); + } }); - return future.wait(); + var sshEnd = future.wait(); + maybeLog("Removing hostkey at " + hostpath); + fs.unlinkSync(hostpath); + maybeLog("Removing sshkey at " + idpath); + fs.unlinkSync(idpath); + return sshEnd; }); diff --git a/tools/isopack.js b/tools/isopack.js index 603feab45c..2ff2bd6eb8 100644 --- a/tools/isopack.js +++ b/tools/isopack.js @@ -366,6 +366,15 @@ _.extend(Isopack.prototype, { return self.architectures().join('+'); }, + // Returns true if we think that this isopack is platform specific (contains + // binary builds) + platformSpecific: function () { + var self = this; + return _.any(self.architectures(), function (arch) { + return arch.match(/^os\./); + }); + }, + tarballName: function () { var self = this; return self.name + '-' + self.version + '-' + self.buildArchitectures();