-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshipitfile.js
More file actions
61 lines (58 loc) · 1.73 KB
/
shipitfile.js
File metadata and controls
61 lines (58 loc) · 1.73 KB
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
const { deploy } = require('./config/production.json');
const shipitDeploy = require('shipit-deploy');
const workdir = '/home/musicroom/api';
let port = '';
module.exports = shipit => {
shipitDeploy(shipit);
shipit.initConfig({
default: {
workspace: '/tmp/github-monitor',
deployTo: '~/api',
repositoryUrl: 'git@gitlab.com:music-room/mr-api.git',
ignores: [
'.git',
'node_modules',
'test'
],
rsync: ['--del'],
branch: 'master',
keepReleases: 2,
key: '/tmp/key',
shallowClone: true,
},
production: { servers: `${deploy.name}@${deploy.url}` }
});
shipit.blTask('get port', () => {
const initialPort = 8080;
const getPort = `cat .balancing || echo ${initialPort}`;
const cmd = newPort => `echo ${newPort} > .balancing`;
return shipit.remote(getPort, {cwd: workdir})
.then(res => {
port = res[0].stdout.slice(0, -1);
port = initialPort + (port - initialPort + 1) % 2;
console.log(res[0].stdout);
console.log(port);
shipit.remote(cmd(port), {cwd: workdir})
});
});
shipit.task('export port', () => {
return shipit.remote('export MR_API_PORT=$(cat .balancing)', {cwd: workdir})
});
shipit.blTask('start new docker', () => {
return shipit.remote(`ls && export MR_API_PORT=${port} && ./script/prod.sh`, {cwd: `${workdir}/current`});
});
shipit.blTask('waiting', () => {
return shipit.remote('sleep 10');
});
shipit.blTask('kill old dockers', () => {
return shipit.remote('docker system prune -f');
});
shipit.task('balance', () => {
shipit.start(
'get port',
'start new docker',
'waiting',
'kill old dockers'
)
});
};