Permalink
Browse files

deploy, cleanup, and serve new extension updates

  • Loading branch information...
1 parent 1ddf026 commit e39fd1b585ea759c219e4ac010e1f16e0acdaeaf @zaach zaach committed Nov 20, 2012
Showing with 58 additions and 23 deletions.
  1. +1 −0 .gitignore
  2. +41 −17 bin/builder
  3. +2 −0 bin/static
  4. +10 −0 lib/views.js
  5. +3 −5 scripts/crxmake.sh
  6. +1 −1 views/index.html
View
@@ -1,2 +1,3 @@
*~
/node_modules
+downloads
View
@@ -20,10 +20,14 @@ var privSigningKeyPath = path.join(process.env['HOME'], '.ssh', 'id_rsa');
var githubRepo = 'git://github.com/mozilla/gombot-chrome';
var devBranch = 'master';
-var downloadFile = 'latest.crx';
var ircChannel = '#tobmog';
+// create the download dir if needed
+if (!fs.existsSync(downloadDir)) {
+ fs.mkdirSync(downloadDir);
+}
+
// a class capable of deploying and emmitting events along the way
function Builder(options) {
events.EventEmitter.call(this);
@@ -51,7 +55,7 @@ util.inherits(Builder, events.EventEmitter);
Builder.prototype._writeSha = function(sha, cb) {
var self = this;
fs.writeFile(path.join(downloadDir, 'ver.txt'), sha, function(err, sha) {
- if (err) self.emit('info', 'could not write last sha');
+ if (err) self.emit('info', 'could not write last sha: ' + err);
if (cb) cb(err);
});
};
@@ -64,7 +68,7 @@ Builder.prototype._getLatestRunningSHA = function(cb) {
});
};
-Builder.prototype._buildNewCode = function(cb) {
+Builder.prototype._buildNewCode = function(sha, cb) {
var self = this;
function splitAndEmit(chunk) {
@@ -79,7 +83,7 @@ Builder.prototype._buildNewCode = function(cb) {
console.log(buildScript);
var crxBuild = spawn(buildScript,
- [ self._codeDir, privSigningKeyPath ],
+ [ self._codeDir, privSigningKeyPath, 'gombot' ],
{ cwd: self._codeDir });
crxBuild.stdout.on('data', splitAndEmit);
@@ -90,6 +94,27 @@ Builder.prototype._buildNewCode = function(cb) {
cb('could not build crx');
return;
}
+
+ cb(null, path.join(self._codeDir, 'gombot.crx'));
+
+ });
+};
+
+Builder.prototype._deployNewCode = function(buildPath, sha, oldSha, cb) {
+ // move new extension into download folder
+ var newPath = path.join(downloadDir, 'gombot-' + sha + '.crx');
+ this.emit('info', 'creating new download: ' + newPath);
+ fs.rename(buildPath, newPath, function(err) {
+ if (err) return cb(err);
+ if (oldSha) {
+ fs.unlink(path.join(downloadDir, 'gombot-' + oldSha + '.crx'),
+ function (err) {
+ // ignore clean up errors
+ cb(null);
+ });
+ } else {
+ cb(null);
+ }
});
};
@@ -109,20 +134,24 @@ Builder.prototype._pullLatest = function(cb) {
});
var startTime = new Date();
- self._buildNewCode(function(err, res) {
+ // build new extension package
+ self._buildNewCode(latest, function(err, buildPath) {
if (err) return cb(err);
- self._writeSha(latest, function(err) {
- // deployment is complete!
- self.emit('deployment_complete', {
- sha: latest,
- time: (new Date() - startTime)
+ self._deployNewCode(buildPath, latest, running, function (err) {
+ if (err) return cb(err);
+ self._writeSha(latest, function(err) {
+ cb(null, latest);
+ // deployment is complete!
+ self.emit('deployment_complete', {
+ sha: latest,
+ time: (new Date() - startTime)
+ });
});
- cb(null, null);
});
});
} else {
self.emit('info', 'up to date');
- cb(null, null);
+ cb(null, latest);
}
});
});
@@ -222,7 +251,6 @@ builder.on('deployment_complete', function(r) {
// always check to see if we should try another deployment after one succeeds to handle
// rapid fire commits
- console.log('from complete');
builder.checkForUpdates();
});
@@ -235,7 +263,6 @@ builder.on('error', function(r) {
// on error, try again in 2 minutes
setTimeout(function () {
- console.log('from error');
builder.checkForUpdates();
}, 2 * 60 * 1000);
});
@@ -244,13 +271,11 @@ builder.on('error', function(r) {
// We check every 15 minutes, in case a cosmic ray hits and github's
// webhooks fail, or other unexpected errors occur
setInterval(function () {
- console.log('from interval');
builder.checkForUpdates();
}, (1000 * 60 * 15));
// check for updates at startup
builder.on('ready', function() {
- console.log('from ready');
builder.checkForUpdates();
});
@@ -259,7 +284,6 @@ var app = express();
var server = http.createServer(app);
var check = function(req, res) {
- console.log('from check');
builder.checkForUpdates();
res.send('ok');
};
View
@@ -15,6 +15,7 @@ var app = express();
var server = http.createServer(app);
var static_root = path.join(__dirname, "..", "public");
+var download_root = path.join(__dirname, "..", "downloads");
var env = new nunjucks.Environment(new nunjucks.FileSystemLoader(path.join(__dirname, '..', 'views')));
env.express(app);
@@ -29,6 +30,7 @@ views.setup(app);
// set up static file serving
app.use(express.static(static_root));
+app.use('/downloads', express.static(download_root));
var bindTo = config.process.static;
server.listen(bindTo.port, bindTo.host, function() {
View
@@ -1,9 +1,19 @@
+const fs = require('fs');
+const path = require('path');
// set up views for static site
function setup(app) {
app.get('/', function(req, res) {
res.render('index.html');
});
+
+ app.get('/downloads/latest', function(req, res) {
+ fs.readFile(path.resolve(__dirname, '..', 'downloads', 'ver.txt'),
+ function(err, sha) {
+ if (err) console.log(err);
+ res.redirect('/downloads/gombot-' + sha + '.crx');
+ });
+ });
}
exports.setup = setup;
View
@@ -3,21 +3,19 @@
# Purpose: Pack a Chromium extension directory into crx format
if test $# -ne 2; then
- echo "Usage: crxmake.sh <extension dir> <pem path>"
+ echo "Usage: crxmake.sh <extension dir> <pem path> [name]"
exit 1
fi
dir=$1
-key=$2 || ~/.ssh/id_rsa
-name=$(basename "$dir")
+key=$HOME/.ssh/id_rsa
+name=$3 || $(basename "$dir")
crx="$name.crx"
pub="$name.pub"
sig="$name.sig"
zip="$name.zip"
trap 'rm -f "$pub" "$sig" "$zip"' EXIT
-echo "oh hai"
-
# zip up the crx dir
cwd=$(pwd -P)
(cd "$dir" && zip -qr -9 -X "$cwd/$zip" .)
View
@@ -3,5 +3,5 @@
{% block page_title %}Gombot{% endblock %}
{% block content %}
-<a href="/downloads/latest.crx">Download Gombot!</a>
+<a href="/downloads/latest">Download Gombot!</a>
{% endblock %}

0 comments on commit e39fd1b

Please sign in to comment.