-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
125 lines (119 loc) · 3.29 KB
/
Gruntfile.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
watch: {
lambda: {
files: [
'infrastructure/lambda/**/fn/index.*',
'infrastructure/lambda/*/lib/*helpers*',
'infrastructure/lambda/js/*/fn/package.json',
'infrastructure/lambda.tf',
'infrastructure/lambda/terraform/*/main.tf',
],
tasks: ['deploy'],
},
terraform: {
files: [
'**/*.tf'
],
tasks: ['shell:formatTf']
},
},
env: {
dev: {
src: '.env',
},
},
shell: {
dockerWatch: {
command: () => {
return 'watch -n 1 docker ps -a';
},
},
formatTf: {
command: () => {
return 'terraform fmt .'
}
},
infraUp: {
command: () => {
return (
'cd ./infrastructure && terraform -v ' +
'&& terraform init -input=false ' +
'&& terraform apply -auto-approve -input=false'
);
},
},
lambdaUp: {
command: () => {
return (
'cd ./infrastructure && terraform -v ' +
'&& terraform init -input=false ' +
'&& terraform apply -auto-approve -input=false ' +
'-target=module.tasks_validator -target=module.email_executer' // Keep up to date
);
},
},
localstackUp: {
command: () => {
return 'TMPDIR=/private$TMPDIR docker-compose up -d localstack';
},
},
stackDown: {
command: () => {
return 'docker-compose down && if [[ $(docker ps -aq) ]]; then docker rm -f $(docker ps -aq); fi';
},
},
stackUp: {
command: () => {
return 'TMPDIR=/private$TMPDIR docker-compose up';
},
},
},
});
/**** Register Tasks ****/
/* TLT (Top Level Tasks) */
grunt.registerTask('start', ['cleanup', 'build', 'shell:stackUp']);
grunt.registerTask('deploy', ['env:dev', 'shell:infraUp']);
grunt.registerTask('cleanup', ['del-tf-state', 'shell:stackDown']);
grunt.registerTask('docker', ['shell:dockerWatch']);
/* STs Secondary Tasks */
grunt.registerTask('build', [
'shell:localstackUp',
'wait:5000', // Not functionally essential but keeps error logs clean
'deploy',
]);
grunt.registerTask(
'del-tf-state',
'Delete terraform state files',
function() {
DATA_FP = 'data';
TF_STATE_FP = 'infrastructure/terraform.tfstate';
TF_STATE_BACKUP_FP = `${TF_STATE_FP}.backup`;
const delFile = function(filePath) {
if (grunt.file.exists(filePath)) {
grunt.log.write(`Deleting file ${filePath}...`);
grunt.file.delete(filePath);
grunt.log.ok();
}
};
delFile(TF_STATE_FP);
delFile(TF_STATE_BACKUP_FP);
delFile(DATA_FP);
}
);
grunt.registerTask('wait', 'Blocking wait before next task is run', function(
ms
) {
var done = this.async();
grunt.log.write('Going to sleep...');
setTimeout(function() {
grunt.log.write('waking up...').ok();
done();
}, ms);
});
/**** Grunt plugins ****/
grunt.loadNpmTasks('grunt-env');
grunt.loadNpmTasks('grunt-contrib-watch');
};