-
Notifications
You must be signed in to change notification settings - Fork 4
/
shipitfile.js
69 lines (58 loc) · 1.87 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
module.exports = function (shipit) {
require('./tools/shipit-deploy')(shipit);
const host = process.env.SSH_HOST;
const user = process.env.SSH_USER;
if(!host || !user) throw new Error('SSH_HOST & SSH_USER env variables has to be set in your system')
shipit.initConfig({
default: {
workspace: './dist',
keepReleases: 10,
deleteOnRollback: false,
copy: '-rf',
rsync: '--del',
ignores: ['node_modules']
},
next: {
deployTo: `/home/${user}/test`,
servers: `${user}@${host}`
},
prod: {
deployTo: `/home/${user}/prod`,
servers: `${user}@${host}`
}
});
/**
* run npm install after uploading files
*/
shipit.on('updated', () => shipit.start('npm:install'));
shipit.blTask('npm:install', async function() {
// symlink .env to api app folder
const deployTo = this.config.deployTo;
const releaseDir = `${this.releasePath}`;
await shipit.remote(`ln -s ${deployTo}/.env ${releaseDir}/apps/api/.env`);
await shipit.remote(`ln -s ${deployTo}/.env ${releaseDir}/apps/web/server/.env`);
// npm install
await shipit.remote(`cd ${shipit.releasePath} && npm install --production`);
})
/**
* reload pm2 processes after successful deployment
*/
shipit.on('deployed', () => shipit.start('pm2:reload'));
shipit.blTask('pm2:reload', async function () {
const deployTo = this.config.deployTo;
await shipit.remote(`pm2 startOrGracefulReload ${deployTo}/pm2.json`);
});
shipit.blTask('rollback', [
'rollback:init',
'deploy:publish',
'deploy:clean',
'rollback:finish',
'pm2:reload',
])
// currentPath: '/home/[user]/test/current',
// releasesPath: '/home/[user]/test/releases',
// workspace: './dist',
// previousRelease: '20190310213226',
// releaseDirname: '20190312085435',
// releasePath: '/home/[user]/test/releases/20190312085435'
};