-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathshipitfile.js
More file actions
82 lines (71 loc) · 2.88 KB
/
shipitfile.js
File metadata and controls
82 lines (71 loc) · 2.88 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// This shipitfile handles deployment of local files defined in `dirToCopy`.
// `grunt build` has to run before initiating this shipitfile which expects
// the final built files in `dist` directory.
//
// If deployed in AWS, set the `USE_PRIVATE_DNS` environment variable to a
// truthy value to deploy using internal IP addresses instead of external IPs
const process = require('process');
const USE_PRIVATE_DNS = process.env.CL_USE_PRIVATE_DNS ? true : false;
module.exports = function (shipit, tasks, cometaws) {
var cometAws = new cometaws.CometAws({
env: shipit.environment,
region: 'eu-west-1'
});
var cometDeployer = new cometaws.CometDeployer(cometAws, shipit);
cometDeployer.tags = [{
Key: 'Role',
Value: 'cl-web'
}];
if (!USE_PRIVATE_DNS) {
cometDeployer.usePrivateDns = false;
}
var config = {
default: {
repositoryUrl: 'git@github.com:cometcult/lunch-button.git',
workspace: '/tmp/lunch-button-www-shipit',
dirToCopy: 'dist',
ignores: ['.git'],
keepReleases: 5,
deleteOnRollback: false
},
development: {
deployTo: '/srv/development/lunch-button-www',
branch: 'develop'
},
production: {
deployTo: '/srv/production/lunch-button-www',
branch: 'master'
}
};
return cometDeployer.configureShipit(shipit, config).then( config => {
require('shipit-deploy')(shipit);
shipit.task('cl:deploy', ['deploy']);
shipit.blTask('cl:deploy-pr', () => {
var prNumber = process.env.PR;
var deployTo = `/srv/prs/lunch-button-www/pr${process.env.PR}`;
// rsync changes to a PR directory
return shipit.remote(`mkdir -p ${deployTo}`)
.then( () => shipit.remoteCopy(`${shipit.config.dirToCopy}/`, deployTo, {
'rsync': '--del'
}))
.then( () => shipit.start('cl:nginx:reload'));
});
shipit.blTask('cl:copy-local-dist', () => {
var destinationDirectory = `${shipit.config.workspace}/${shipit.config.dirToCopy}`;
return shipit.local(`rm -rf ${destinationDirectory}`).then( () => {
return shipit.local(`cp -rp ${shipit.config.dirToCopy} ${destinationDirectory}`);
});
});
shipit.task('cl:nginx:reload', () => {
return shipit.remote('sudo service nginx configtest && sudo service nginx reload');
});
shipit.on('fetched', () => {
shipit.start('cl:copy-local-dist');
});
shipit.on('published', () => {
shipit.start('cl:nginx:reload');
});
var serverList = config.servers.join(', ');
console.log(`Configuring tasks for [${shipit.environment}] environment on servers [${serverList}]`);
});
};