forked from jamesshore/object_playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.jakefile
83 lines (67 loc) · 2.74 KB
/
deploy.jakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) 2012 Titanium I.T. LLC. All rights reserved. See LICENSE.txt for details.
/*global desc, task, jake, fail, complete */
var PRODUCTION_HOST = "[email protected]";
var PRODUCTION_DIR = "/home/public";
var INTEGRATION_BRANCH = "integration";
var GIT_HEAD = "HEAD";
var DEPLOY_COMMAND = "rsync --recursive --keep-dirlinks --perms --times --delete --delete-excluded --human-readable --progress --exclude=.DS_Store --include=.* src/* " + PRODUCTION_HOST + ":" + PRODUCTION_DIR + "/";
var sh = require("./build/util/sh.js");
var build_command = require("./build/util/build_command.js");
(function() {
"use strict";
task("default", function() {
console.log("This Jakefile deploys the application. Use -T option to see targets.\n");
});
desc("Integrate master branch and deploy to production");
task("latest", ["integrate"], function() {
deploy(INTEGRATION_BRANCH, complete);
}, {async: true});
desc("Deploy git HEAD to production (use to manually fix release)")
task("head", ["build", "git"], function() {
deploy(GIT_HEAD, complete);
}, {async: true});
// Ensure that Git status is clean
task("git", function() {
run("git status --porcelain", function(stdout) {
if (stdout[0]) fail("Cannot deploy until all files checked into git (or added to .gitignore).");
complete();
});
}, {async: true});
// Run integrate script
task("integrate", function() {
run(build_command.integrate(), complete, "Cannot deploy until integration succeeds.");
}, {async: true});
// Make sure build is clean
task("build", function() {
run(build_command(), complete, "Cannot deploy until build passes.");
}, {async: true});
function deploy(commitToTag, complete) {
sh.run(DEPLOY_COMMAND, onSuccess, onFailure);
function onSuccess() {
tagCommit();
console.log("\n\nDEPLOY SUCCEEDED");
}
function onFailure() {
console.log("\n\nDEPLOY FAILED");
}
function tagCommit(tagRoot) {
var deployedAt = new Date();
var tagMessage = "Application successfully deployed at " + deployedAt.toUTCString() + "\nLocal time: " + deployedAt.toLocaleString();
var tagCommand = "git tag -a '" + tagName(deployedAt) + "' -m '" + tagMessage + "' " + commitToTag;
sh.run(tagCommand, complete, function() {
fail("Application deployed and online, but failed to tag repository.");
});
}
function tagName(date) {
var humanReadableDate = date.getFullYear() + "." + (date.getMonth() + 1) + "." + date.getDate() + "-";
var timestamp = date.getTime();
return "deploy-" + humanReadableDate + timestamp;
}
}
function run(command, callback, errorMessage) {
errorMessage = errorMessage || "shell command exited with error code";
sh.run(command, callback, function() {
fail(errorMessage);
});
}
}());