@cerema/cadriciel 1.1.4 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cmd/install.js +83 -0
- package/package.json +1 -1
package/cmd/install.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
module.exports = function (program) {
|
|
2
|
+
const chalk = require('chalk-v2');
|
|
3
|
+
const ora = require('ora');
|
|
4
|
+
const { spawn } = require('child_process');
|
|
5
|
+
const init = async (str, options) => {
|
|
6
|
+
const checkIfCommandExists = (command, callback) => {
|
|
7
|
+
const proc = spawn('which', [command]);
|
|
8
|
+
|
|
9
|
+
let found = false;
|
|
10
|
+
proc.stdout.on('data', (data) => {
|
|
11
|
+
if (data.toString().trim() !== '') {
|
|
12
|
+
found = true;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
proc.on('close', (code) => {
|
|
17
|
+
callback(found);
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const installDockerImages = (images, ndx) => {
|
|
22
|
+
if (!ndx) {
|
|
23
|
+
ndx = 0;
|
|
24
|
+
console.log('\n💻 ' + chalk.bold('Installation des dépendances...\n'));
|
|
25
|
+
}
|
|
26
|
+
if (!images[ndx]) return console.log('\n👍 Installation terminée.');
|
|
27
|
+
const image = images[ndx];
|
|
28
|
+
|
|
29
|
+
const response = ora(`Téléchargement de l'image: ${image}`).start();
|
|
30
|
+
const dockerPull = spawn('docker', ['pull', image]);
|
|
31
|
+
|
|
32
|
+
dockerPull.stdout.on('data', (data) => {
|
|
33
|
+
//console.log(data.toString().trim());
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
dockerPull.stderr.on('data', (data) => {
|
|
37
|
+
response.fail(chalk.red('Le service Docker ne répond pas.'));
|
|
38
|
+
return process.exit(1);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
dockerPull.on('close', (code) => {
|
|
42
|
+
if (code !== 0) {
|
|
43
|
+
response.fail(`Error pulling image ${image}`);
|
|
44
|
+
} else {
|
|
45
|
+
response.succeed(`Image ${image} OK.`);
|
|
46
|
+
installDockerImages(images, ndx + 1);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const setupEnvironment = (images) => {
|
|
52
|
+
checkIfCommandExists('docker', (dockerExists) => {
|
|
53
|
+
if (!dockerExists) {
|
|
54
|
+
console.error(`Docker n'est pas installé.`);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
checkIfCommandExists('git', (gitExists) => {
|
|
59
|
+
if (!gitExists) {
|
|
60
|
+
console.error(`Git n'est pas installé.`);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
installDockerImages(images);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
const dockerImagesToInstall = [
|
|
69
|
+
'postgres:15',
|
|
70
|
+
'cerema/cadriciel:1.0.0',
|
|
71
|
+
'dpage/pgadmin4',
|
|
72
|
+
'inbucket/inbucket:latest',
|
|
73
|
+
'quay.io/keycloak/keycloak:legacy',
|
|
74
|
+
'liquibase/liquibase',
|
|
75
|
+
];
|
|
76
|
+
setupEnvironment(dockerImagesToInstall);
|
|
77
|
+
};
|
|
78
|
+
/** command line init */
|
|
79
|
+
program
|
|
80
|
+
.command('install')
|
|
81
|
+
.description('Installation des dépendances')
|
|
82
|
+
.action(init);
|
|
83
|
+
};
|