Skip to content

Commit

Permalink
move deploy upload into node, instead of calling curl
Browse files Browse the repository at this point in the history
  • Loading branch information
matt debergalis committed Dec 3, 2011
1 parent 1d4f97d commit e81b908
Showing 1 changed file with 47 additions and 37 deletions.
84 changes: 47 additions & 37 deletions app/skybreak/skybreak.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,50 +389,60 @@ Commands.push({
process.exit(1);
}

process.stdout.write('Deploying to ' + url.hostname + ' ...\n');
process.stdout.write('Deploying to ' + url.hostname + '. Bundling ... ');

var app_dir = path.resolve(require_project("bundle"));
var build_dir = path.join(app_dir, '.skybreak/local/build_tar');
var bundle_path = path.join(build_dir, 'bundle');
var bundle_opts = { skip_dev_bundle: true };
require('../lib/bundler.js').bundle(app_dir, bundle_path, bundle_opts);

var cp = require('child_process');
// curl -# progress meter, -f exit nonzero if HTTP 403, -F form data.
// XXX exec won't let us buffer the output.
cp.exec('tar czf - bundle | curl -f -# --data-binary @- http://deploy.skybreakplatform.com/deploy/' + url.hostname,
{cwd: build_dir},
function (error, stdout, stderr) {
files.rm_recursive(build_dir);

process.stdout.write(stdout);
process.stderr.write(stderr);

if (error !== null) {
// XXX better error reporting
process.stderr.write("couldn't deploy\n");
process.exit(1);
}

process.stdout.write('Done. Now serving at ' + url.hostname + '\n');

if (!url.hostname.match('skybreakplatform.com')) {
var dns = require('dns');
dns.resolve(url.hostname, 'CNAME', function (err, cnames) {
if (err || cnames[0] !== 'origin.skybreakplatform.com') {
dns.resolve(url.hostname, 'A', function (err, addresses) {
if (err || addresses[0] !== '107.22.210.133') {
process.stdout.write('-------------\n');
process.stdout.write("You've deployed to a custom domain.\n");
process.stdout.write("Please be sure to CNAME your hostname to origin.skybreakplatform.com,\n");
process.stdout.write("or set an A record to 107.22.210.133.\n");
process.stdout.write('-------------\n');
}
});
}
});
}
});
process.stdout.write('uploading ... ');

var spawn = require('child_process').spawn;

var tar = spawn('tar', ['czf', '-', 'bundle'], {cwd: build_dir});

var deploy_req_opts = {
method: 'POST',
host: 'deploy.skybreakplatform.com',
path: '/deploy/' + url.hostname
};

var http = require('http');
var deploy_req = http.request(deploy_req_opts, function (deploy_res) {
deploy_res.on('end', function () {
process.stdout.write('done.\n');
process.stdout.write('Now serving at ' + url.hostname + '\n');

files.rm_recursive(build_dir);

if (!url.hostname.match('skybreakplatform.com')) {
var dns = require('dns');
dns.resolve(url.hostname, 'CNAME', function (err, cnames) {
if (err || cnames[0] !== 'origin.skybreakplatform.com') {
dns.resolve(url.hostname, 'A', function (err, addresses) {
if (err || addresses[0] !== '107.22.210.133') {
process.stdout.write('-------------\n');
process.stdout.write("You've deployed to a custom domain.\n");
process.stdout.write("Please be sure to CNAME your hostname to origin.skybreakplatform.com,\n");
process.stdout.write("or set an A record to 107.22.210.133.\n");
process.stdout.write('-------------\n');
}
});
}
});
}
});
});

tar.stdout.on('data', function (data) {
deploy_req.write(data);
});

tar.on('exit', function (code) {
deploy_req.end();
});
}
});

Expand Down

0 comments on commit e81b908

Please sign in to comment.