forked from IGN-CNIG/API-CNIG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy
executable file
·89 lines (77 loc) · 2.36 KB
/
deploy
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
#!/usr/bin/env node
/**
* @org Guadaltel SA
* @author Emilio Martinez Rivero
* @email ([email protected])
*/
const { spawn } = require('child_process');
const { argv } = require('process');
const processArgs = (args) => {
const options = args.slice(2).reduce((accum, arg) => {
const regex = /(\-){2}([a-zA-Z]+)=([a-zA-Z]+)/;
if (regex.test(arg)) {
const key = arg.match(regex)[2];
const value = arg.match(regex)[3];
accum[key] = value;
}
return accum;
}, {});
args.slice(2).forEach((arg, index, arr) => {
const regex = /(\-){1}([a-zA-Z]+)/;
if (regex.test(arg) && !regex.test(arr[index + 1])) {
const key = arg.match(regex)[2];
options[key] = arr[index + 1];
}
});
return options;
};
const executeCommand = async (command, args, options) => {
return new Promise((resolve) => {
const exec = spawn(command, args, {
...options,
stdio: 'inherit',
});
exec.on('close', (code) => {
resolve(code);
});
});
};
const ARGS_INPUT = processArgs(argv);
const main = async () => {
const code = await executeCommand('mvn', ['clean', 'package', '-P', ARGS_INPUT['profile']], { cwd: './api-ign-parent' });
if (!code) {
try {
const code2 = await executeCommand('mvn', [
'docker:build',
`-DdockerImageName=docker.guadaltel.es/cnig/api-cnig${ARGS_INPUT['tag']}`,
'-DdockerHost=http://docker.guadaltel.es:2375/'
], { cwd: './api-ign-rest' });
const code3 = await executeCommand('mvn', [
'docker:build',
`-DdockerImageName=docker.guadaltel.es/cnig/api-cnig${ARGS_INPUT['tag']}`,
'-DdockerHost=http://docker.guadaltel.es:2375/'
], { cwd: './api-ign-rest' });
const code4 = await executeCommand('sudo', [
'docker',
'build',
`-t`,
`docker.guadaltel.es/cnig/api-cnig:${ARGS_INPUT['tag']}`,
'target/docker'
], { cwd: './api-ign-rest' });
const code5 = await executeCommand('sudo', [
'docker',
'push',
`docker.guadaltel.es/cnig/api-cnig:${ARGS_INPUT['tag']}`,
], { cwd: './api-ign-rest' });
console.info('[SUCCESS] Everything is ok!');
} catch (e) {
console.error('[ERROR] ' + code);
}
} else {
console.error('[ERROR] ' + code);
}
}
console.log(ARGS_INPUT)
if (ARGS_INPUT.tag && ARGS_INPUT.profile) {
main();
}