@cerema/cadriciel 1.4.1 → 1.4.2
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/cli/global/install.js +96 -24
- package/package.json +1 -1
- package/_install.js +0 -107
package/cli/global/install.js
CHANGED
|
@@ -1,35 +1,107 @@
|
|
|
1
1
|
module.exports = (args) => {
|
|
2
|
-
const
|
|
2
|
+
const chalk = require('chalk-v2');
|
|
3
|
+
const ora = require('ora');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const { spawn } = require('child_process');
|
|
7
|
+
const HOSTS_PATH = '/etc/hosts';
|
|
8
|
+
const MAPPING_ENTRY = '127.0.0.1 keycloak';
|
|
3
9
|
|
|
4
|
-
|
|
10
|
+
function addMapping() {
|
|
5
11
|
try {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
const hostsContent = fs.readFileSync(HOSTS_PATH, 'utf8');
|
|
13
|
+
if (!hostsContent.includes(MAPPING_ENTRY)) {
|
|
14
|
+
fs.appendFileSync(HOSTS_PATH, os.EOL + MAPPING_ENTRY);
|
|
15
|
+
}
|
|
16
|
+
} catch (e) {
|
|
17
|
+
console.error(
|
|
18
|
+
chalk.red.bold(
|
|
19
|
+
"\nVous devez lancer la commande en tant qu'administrateur.\n"
|
|
20
|
+
)
|
|
21
|
+
);
|
|
22
|
+
return process.exit(0);
|
|
11
23
|
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const checkIfCommandExists = (command, callback) => {
|
|
27
|
+
const proc = spawn('which', [command]);
|
|
28
|
+
|
|
29
|
+
let found = false;
|
|
30
|
+
proc.stdout.on('data', (data) => {
|
|
31
|
+
if (data.toString().trim() !== '') {
|
|
32
|
+
found = true;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
proc.on('close', (code) => {
|
|
37
|
+
callback(found);
|
|
38
|
+
});
|
|
12
39
|
};
|
|
13
40
|
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
Docker: 'docker --version',
|
|
19
|
-
Java: 'java -version 2>&1 | head -n 1', // Java version gets printed to stderr
|
|
20
|
-
Maven: 'mvn -v | head -n 1',
|
|
21
|
-
//Liquibase: 'liquibase --version',
|
|
22
|
-
Nodejs: 'node --version',
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const versions = {};
|
|
26
|
-
|
|
27
|
-
for (const [software, command] of Object.entries(softwareChecks)) {
|
|
28
|
-
versions[software] = getCommandOutput(command);
|
|
41
|
+
const installDockerImages = (images, ndx) => {
|
|
42
|
+
if (!ndx) {
|
|
43
|
+
ndx = 0;
|
|
44
|
+
console.log('\n💻 ' + chalk.bold('Installation des dépendances...\n'));
|
|
29
45
|
}
|
|
46
|
+
if (!images[ndx]) return console.log('\n👍 Installation terminée.');
|
|
47
|
+
const image = images[ndx];
|
|
48
|
+
|
|
49
|
+
const response = ora(`Téléchargement de l'image: ${image}`).start();
|
|
50
|
+
const dockerPull = spawn('docker', ['pull', image]);
|
|
51
|
+
|
|
52
|
+
dockerPull.stdout.on('data', (data) => {
|
|
53
|
+
//console.log(data.toString().trim());
|
|
54
|
+
});
|
|
30
55
|
|
|
31
|
-
|
|
56
|
+
dockerPull.stderr.on('data', (data) => {
|
|
57
|
+
response.fail(chalk.red('Le service Docker ne répond pas.'));
|
|
58
|
+
return process.exit(1);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
dockerPull.on('close', (code) => {
|
|
62
|
+
if (code !== 0) {
|
|
63
|
+
response.fail(`Error pulling image ${image}`);
|
|
64
|
+
} else {
|
|
65
|
+
response.succeed(`Image ${image} OK.`);
|
|
66
|
+
installDockerImages(images, ndx + 1);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
32
69
|
};
|
|
33
70
|
|
|
34
|
-
|
|
71
|
+
const setupEnvironment = (images) => {
|
|
72
|
+
checkIfCommandExists('docker', (dockerExists) => {
|
|
73
|
+
if (!dockerExists) {
|
|
74
|
+
console.error(`Docker n'est pas installé.`);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
checkIfCommandExists('git', (gitExists) => {
|
|
79
|
+
if (!gitExists) {
|
|
80
|
+
console.error(`Git n'est pas installé.`);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
installDockerImages(images);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
return {
|
|
89
|
+
info: {
|
|
90
|
+
title: 'install',
|
|
91
|
+
description:
|
|
92
|
+
'Installation des dépendances (La première fois uniquement).)',
|
|
93
|
+
},
|
|
94
|
+
start: () => {
|
|
95
|
+
addMapping();
|
|
96
|
+
const dockerImagesToInstall = [
|
|
97
|
+
'postgres:15',
|
|
98
|
+
'cerema/cadriciel:1.0.0',
|
|
99
|
+
'dpage/pgadmin4',
|
|
100
|
+
'inbucket/inbucket:latest',
|
|
101
|
+
'quay.io/keycloak/keycloak:legacy',
|
|
102
|
+
'liquibase/liquibase',
|
|
103
|
+
];
|
|
104
|
+
setupEnvironment(dockerImagesToInstall);
|
|
105
|
+
},
|
|
106
|
+
};
|
|
35
107
|
};
|
package/package.json
CHANGED
package/_install.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
module.exports = (args) => {
|
|
2
|
-
const chalk = require('chalk-v2');
|
|
3
|
-
const ora = require('ora');
|
|
4
|
-
const os = require('os');
|
|
5
|
-
const fs = require('fs');
|
|
6
|
-
const { spawn } = require('child_process');
|
|
7
|
-
const HOSTS_PATH = '/etc/hosts';
|
|
8
|
-
const MAPPING_ENTRY = '127.0.0.1 keycloak';
|
|
9
|
-
|
|
10
|
-
function addMapping() {
|
|
11
|
-
try {
|
|
12
|
-
const hostsContent = fs.readFileSync(HOSTS_PATH, 'utf8');
|
|
13
|
-
if (!hostsContent.includes(MAPPING_ENTRY)) {
|
|
14
|
-
fs.appendFileSync(HOSTS_PATH, os.EOL + MAPPING_ENTRY);
|
|
15
|
-
}
|
|
16
|
-
} catch (e) {
|
|
17
|
-
console.error(
|
|
18
|
-
chalk.red.bold(
|
|
19
|
-
"\nVous devez lancer la commande en tant qu'administrateur.\n"
|
|
20
|
-
)
|
|
21
|
-
);
|
|
22
|
-
return process.exit(0);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const checkIfCommandExists = (command, callback) => {
|
|
27
|
-
const proc = spawn('which', [command]);
|
|
28
|
-
|
|
29
|
-
let found = false;
|
|
30
|
-
proc.stdout.on('data', (data) => {
|
|
31
|
-
if (data.toString().trim() !== '') {
|
|
32
|
-
found = true;
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
proc.on('close', (code) => {
|
|
37
|
-
callback(found);
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const installDockerImages = (images, ndx) => {
|
|
42
|
-
if (!ndx) {
|
|
43
|
-
ndx = 0;
|
|
44
|
-
console.log('\n💻 ' + chalk.bold('Installation des dépendances...\n'));
|
|
45
|
-
}
|
|
46
|
-
if (!images[ndx]) return console.log('\n👍 Installation terminée.');
|
|
47
|
-
const image = images[ndx];
|
|
48
|
-
|
|
49
|
-
const response = ora(`Téléchargement de l'image: ${image}`).start();
|
|
50
|
-
const dockerPull = spawn('docker', ['pull', image]);
|
|
51
|
-
|
|
52
|
-
dockerPull.stdout.on('data', (data) => {
|
|
53
|
-
//console.log(data.toString().trim());
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
dockerPull.stderr.on('data', (data) => {
|
|
57
|
-
response.fail(chalk.red('Le service Docker ne répond pas.'));
|
|
58
|
-
return process.exit(1);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
dockerPull.on('close', (code) => {
|
|
62
|
-
if (code !== 0) {
|
|
63
|
-
response.fail(`Error pulling image ${image}`);
|
|
64
|
-
} else {
|
|
65
|
-
response.succeed(`Image ${image} OK.`);
|
|
66
|
-
installDockerImages(images, ndx + 1);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const setupEnvironment = (images) => {
|
|
72
|
-
checkIfCommandExists('docker', (dockerExists) => {
|
|
73
|
-
if (!dockerExists) {
|
|
74
|
-
console.error(`Docker n'est pas installé.`);
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
checkIfCommandExists('git', (gitExists) => {
|
|
79
|
-
if (!gitExists) {
|
|
80
|
-
console.error(`Git n'est pas installé.`);
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
installDockerImages(images);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
return {
|
|
89
|
-
info: {
|
|
90
|
-
title: 'install',
|
|
91
|
-
description:
|
|
92
|
-
'Installation des dépendances (La première fois uniquement).)',
|
|
93
|
-
},
|
|
94
|
-
start: () => {
|
|
95
|
-
addMapping();
|
|
96
|
-
const dockerImagesToInstall = [
|
|
97
|
-
'postgres:15',
|
|
98
|
-
'cerema/cadriciel:1.0.0',
|
|
99
|
-
'dpage/pgadmin4',
|
|
100
|
-
'inbucket/inbucket:latest',
|
|
101
|
-
'quay.io/keycloak/keycloak:legacy',
|
|
102
|
-
'liquibase/liquibase',
|
|
103
|
-
];
|
|
104
|
-
setupEnvironment(dockerImagesToInstall);
|
|
105
|
-
},
|
|
106
|
-
};
|
|
107
|
-
};
|