-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshipitfile.js
79 lines (66 loc) · 3.13 KB
/
shipitfile.js
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
module.exports = function (shipit) {
require('shipit-deploy')(shipit);
var config = require('./config.json');
var pathStr = "PATH='$PATH:/usr/local/bin'";
var currentPath = config.deploy.path + "/current";
shipit.initConfig({
default: {
workspace: 'tmp',
deployTo: config.deploy.path,
repositoryUrl: 'https://github.com/snollygolly/operation-storefront.git',
ignores: ['.git', 'node_modules'],
rsync: ['--del'],
keepReleases: 2,
key: '~/.ssh/id_rsa',
shallowClone: true
},
production: {
servers: config.deploy.username + '@' + config.deploy.hostname
}
});
// this task runs an NPM install remotely to install dependencies
shipit.blTask('install', function () {
return shipit.remote(pathStr + " && cd " + currentPath + " && npm install &> /dev/null");
});
// this task runs an bower install remotely to install dependencies
shipit.blTask('bower_install', function () {
return shipit.remote(pathStr + " && cd " + currentPath + " && bower install &> /dev/null");
});
// this task starts the server in a screen with a name set in the config
shipit.blTask('start_screen', function () {
return shipit.remote(pathStr + " && cd " + currentPath + " && screen -S " + config.deploy.screen + " -d -m npm run production");
});
// this task starts the server directly in the shipit output. use this instead of start_screen if you're having problems
shipit.blTask('start_session', function () {
return shipit.remote(pathStr + " && cd " + currentPath + " && npm start");
});
// this task copies the config.json from your local folder to the current folder
shipit.blTask('install_local_config', function () {
return shipit.remoteCopy('config.json', currentPath);
});
// this task copies the config.json from the remote source's root into the current folder
shipit.blTask('install_remote_config', function () {
return shipit.remote("cd " + config.deploy.path + " && cp config.json " + currentPath);
});
// this task kills any screen with the name set in the config if it's running. phrased as an if to prevent non-0 exit codes
shipit.blTask('kill_screen', function () {
return shipit.remote("if screen -ls | grep -q '" + config.deploy.screen + "'; then screen -S " + config.deploy.screen + " -p 0 -X stuff $'\\003'; fi;");
});
shipit.blTask("pm2-restart", function () {
return shipit.remote(pathStr + " && pm2 restart " + config.deploy.screen);
});
// this task removes the service
shipit.blTask("pm2-delete", function () {
return shipit.remote(pathStr + " && pm2 delete " + config.deploy.screen);
});
// this task creates the service with pm2
shipit.blTask("pm2-create", function () {
return shipit.remote(pathStr + " && cd " + currentPath + " pm2 start index.js --name='" + config.deploy.screen + "'");
});
shipit.on('deployed', function () {
// this series of tasks will result in a good deploy assuming everything is \working
shipit.start( 'kill_screen', 'install', 'install_remote_config', 'start_screen');
// if you're having problems with the deploy being successful, but not actually starting the server, try this:
//shipit.start('kill_screen', 'install', 'install_config', 'start_session');
});
};