-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshipitfile.js
96 lines (83 loc) · 2.44 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
module.exports = shipit => {
require('shipit-deploy')(shipit)
const appName = 'xpression-dev'
shipit.initConfig({
default: {
deployTo: '/srv/xpression',
branch: 'main',
repositoryUrl: 'https://github.com/MindyTai/xpression.git',
shared: {
overwrite: true,
dirs: ['node_modules']
},
keepReleases: 5,
deleteOnRollback: false
},
production: {
servers: [
{
host: `${appName}`,
user: 'ubuntu'
}
],
workspace: '/srv/xpression'
},
})
shipit.on('updated', async () => {
shipit.start('copy-config');
});
shipit.on('published', () => {
shipit.start('pm2-server',);
});
shipit.on('deployed', () => {
shipit.start('app-server');
});
const path = require('path');
const ecosystemFilePath = path.join(
shipit.config.deployTo,
'shared',
'ecosystem.config.js'
);
shipit.blTask('copy-config', async () => {
const fs = require('fs');
const ecosystem = `
module.exports = {
apps: [
{
name: '${appName}',
script: '${shipit.releasePath}/src/index.js',
watch: true,
autorestart: true,
restart_delay: 1000,
env_development: {
NODE_ENV: 'development'
},
env_production: {
PORT: 3000,
NODE_ENV: 'production'
}
}
]
};`;
fs.writeFileSync('ecosystem.config.js', ecosystem, function(err) {
if (err) throw err;
console.log('File created successfully.');
});
await shipit.copyToRemote('ecosystem.config.js', ecosystemFilePath);
});
shipit.blTask('app-server', async () => {
const processName = 'xpression';
let cmd = `
cd /srv/app-env/${processName} &&
cd ${shipit.releasePath} &&
sudo npm install
`;
await shipit.remote(cmd);
});
shipit.blTask('pm2-server', async () => {
await shipit.remote(`pm2 delete -s ${appName} || :`);
await shipit.remote(
`pm2 start ${ecosystemFilePath} --env production --watch true`
);
});
};