refactored deploy for new deployment workflow

This commit is contained in:
Ritchie Martori
2012-11-26 09:38:42 -08:00
parent 8ab4b2db60
commit 473dbd8bb7
2 changed files with 133 additions and 41 deletions

View File

@@ -60,11 +60,18 @@ Deployment.prototype.sanitize = function (name) {
Deployment.prototype.package = function (tarball, callback) {
function filter(info) {
if(info.depth === 2 && info.parent.basename === '.dpd') {
if(info.basename === 'keys.json') {
return true;
} else {
return false;
}
}
if(
info.type === 'Directory'
&& info.depth === 1
&& info.basename === 'data'
|| info.basename === '.dpd'
) {
return false;
}
@@ -87,9 +94,8 @@ Deployment.prototype.publish = function (url, tar, key, callback) {
if(res.statusCode >= 400) return callback(new Error(body));
callback();
}
// persist deployment data
this.setConfig(this.subdomain + '.' + this.remote, this);
var deployment = this;
fs
.createReadStream(tar)
@@ -98,9 +104,21 @@ Deployment.prototype.publish = function (url, tar, key, callback) {
headers: {
'X-Remote-Key': key,
'X-App-User': this.user,
'X-App-Session': this.sid,
'X-App-Subdomain': this.subdomain
}
}, done));
}, function (err, res, body) {
if(err) return console.error(err);
if(res.statusCode !== 200) {
deployment.setConfig('sid', undefined);
deployment.setConfig('user', undefined);
delete deployment.sid;
delete deployment.user;
}
deployment.setConfig(deployment.subdomain + '.' + deployment.remote, deployment);
done.apply(this, arguments);
}));
};
Deployment.prototype.getConfig = function(key) {
@@ -121,5 +139,46 @@ Deployment.prototype.setConfig = function(key, val) {
cur[key] = val;
fs.writeFileSync(this.path + '/.dpd/deployments.json', JSON.stringify(cur));
fs.writeFileSync(this.path + '/.dpd/deployments.json', JSON.stringify(cur, null, ' '));
};
Deployment.prototype.authenticate = function (credentials, fn) {
var deployment = this;
if(typeof credentials == 'function') {
fn = credentials;
credentials = undefined;
}
if(credentials) {
var options = {
url: 'http://api.deploydapp.com:3000/users/login',
json: credentials,
method: 'POST'
};
request(options, function (err, res, session) {
if(err) return fn(err);
var sid = session && session.id;
if(sid) {
deployment.setConfig('sid', sid);
deployment.setConfig('user', credentials.username);
deployment.sid = sid;
deployment.user = credentials.username;
fn(true);
} else {
fn(false);
}
});
} else {
var sid = deployment.getConfig('sid');
var user = deployment.getConfig('user');
deployment.sid = sid;
deployment.user = user;
if(sid) {
fn(true);
} else {
fn(false);
}
}
};