@cerema/cadriciel 1.4.0-a → 1.4.1
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/_install.js +107 -0
- package/bun.lockb +0 -0
- package/cli/global/doc.js +1 -2
- package/cli/global/install.js +24 -96
- package/package.json +1 -1
package/_install.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
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
|
+
};
|
package/bun.lockb
ADDED
|
Binary file
|
package/cli/global/doc.js
CHANGED
|
@@ -6,8 +6,7 @@ module.exports = (args) => {
|
|
|
6
6
|
description: `Documentation du cadriciel`,
|
|
7
7
|
},
|
|
8
8
|
start: async () => {
|
|
9
|
-
var url =
|
|
10
|
-
'https://omneedia.notion.site/omneedia/Cadriciel-Springboot-c54392db030347e7b3579ea383752347';
|
|
9
|
+
var url = 'https://docs.k8-dev.cerema.fr/';
|
|
11
10
|
var start =
|
|
12
11
|
process.platform == 'darwin'
|
|
13
12
|
? 'open'
|
package/cli/global/install.js
CHANGED
|
@@ -1,107 +1,35 @@
|
|
|
1
1
|
module.exports = (args) => {
|
|
2
|
-
const
|
|
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';
|
|
2
|
+
const { execSync } = require('child_process');
|
|
9
3
|
|
|
10
|
-
|
|
4
|
+
const getCommandOutput = (command) => {
|
|
11
5
|
try {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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);
|
|
6
|
+
const output = execSync(command, { encoding: 'utf-8' });
|
|
7
|
+
return output.trim(); // Remove new line and trailing space
|
|
8
|
+
} catch (error) {
|
|
9
|
+
// If there's an error (like the command not found), we'll assume it's not installed
|
|
10
|
+
return 'Not installed';
|
|
23
11
|
}
|
|
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
12
|
};
|
|
40
13
|
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
14
|
+
const getSoftwareVersions = () => {
|
|
15
|
+
const softwareChecks = {
|
|
16
|
+
Homebrew: 'brew -v',
|
|
17
|
+
Git: 'git --version',
|
|
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);
|
|
45
29
|
}
|
|
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
30
|
|
|
56
|
-
|
|
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
|
-
});
|
|
31
|
+
return versions;
|
|
69
32
|
};
|
|
70
33
|
|
|
71
|
-
|
|
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
|
-
};
|
|
34
|
+
//console.log(getSoftwareVersions());
|
|
107
35
|
};
|