@cerema/cadriciel 1.6.1-beta → 1.6.4
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/assets/docker/.env +27 -0
- package/cli/assets/docker/docker-compose.yml +209 -0
- package/cli/assets/docker/init-db/01-create-keycloak-db.sql +1 -0
- package/cli/assets/docker/init-db/02-cadriciel.sql +3604 -0
- package/cli/global/doctor.js +213 -81
- package/cli/global/init.js +34 -237
- package/cli/global/install.js +99 -20
- package/cli.js +426 -428
- package/package.json +4 -3
- /package/cli/{global → _old}/load.js +0 -0
- /package/cli/{global → _old}/login.js +0 -0
- /package/cli/{global → _old}/logout.js +0 -0
package/cli/global/install.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
module.exports = (args) => {
|
|
2
2
|
const chalk = require('chalk-v2');
|
|
3
3
|
const ora = require('ora');
|
|
4
|
-
const os = require('os');
|
|
5
4
|
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const YAML = require('yaml');
|
|
6
7
|
const { spawn } = require('child_process');
|
|
7
8
|
|
|
8
9
|
const checkIfCommandExists = (command, callback) => {
|
|
@@ -20,34 +21,94 @@ module.exports = (args) => {
|
|
|
20
21
|
});
|
|
21
22
|
};
|
|
22
23
|
|
|
24
|
+
const findDockerComposeFile = () => {
|
|
25
|
+
let currentPath = process.cwd();
|
|
26
|
+
const rootPath = path.parse(currentPath).root;
|
|
27
|
+
|
|
28
|
+
while (true) {
|
|
29
|
+
const composeCandidate = path.join(
|
|
30
|
+
currentPath,
|
|
31
|
+
'docker',
|
|
32
|
+
'docker-compose.yml'
|
|
33
|
+
);
|
|
34
|
+
if (fs.existsSync(composeCandidate)) {
|
|
35
|
+
return composeCandidate;
|
|
36
|
+
}
|
|
37
|
+
if (currentPath === rootPath) break;
|
|
38
|
+
currentPath = path.dirname(currentPath);
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const extractImagesFromCompose = (composeFile) => {
|
|
44
|
+
if (!composeFile) return [];
|
|
45
|
+
try {
|
|
46
|
+
const doc = YAML.parse(fs.readFileSync(composeFile, 'utf8'));
|
|
47
|
+
if (!doc || typeof doc !== 'object' || !doc.services) return [];
|
|
48
|
+
const imageMap = new Map();
|
|
49
|
+
Object.values(doc.services).forEach((service) => {
|
|
50
|
+
if (service && typeof service === 'object' && service.image) {
|
|
51
|
+
const platform =
|
|
52
|
+
typeof service.platform === 'string'
|
|
53
|
+
? service.platform.trim()
|
|
54
|
+
: null;
|
|
55
|
+
const key = `${service.image}__${platform || ''}`;
|
|
56
|
+
if (!imageMap.has(key)) {
|
|
57
|
+
imageMap.set(key, { image: service.image, platform });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return Array.from(imageMap.values());
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.error(
|
|
64
|
+
chalk.red(
|
|
65
|
+
`Impossible de lire docker-compose.yml (${error.message || error})`
|
|
66
|
+
)
|
|
67
|
+
);
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
23
72
|
const installDockerImages = (images, ndx) => {
|
|
24
73
|
if (!ndx) {
|
|
25
74
|
ndx = 0;
|
|
26
75
|
console.log('\n💻 ' + chalk.bold('Installation des dépendances...\n'));
|
|
27
76
|
}
|
|
28
77
|
if (!images[ndx]) return console.log('\n👍 Installation terminée.');
|
|
29
|
-
const
|
|
78
|
+
const imageEntry = images[ndx];
|
|
79
|
+
const label = imageEntry.platform
|
|
80
|
+
? `${imageEntry.image} (${imageEntry.platform})`
|
|
81
|
+
: imageEntry.image;
|
|
30
82
|
|
|
31
|
-
const response = ora(`Téléchargement de l'image: ${
|
|
32
|
-
const
|
|
83
|
+
const response = ora(`Téléchargement de l'image: ${label}`).start();
|
|
84
|
+
const args = ['pull'];
|
|
85
|
+
if (imageEntry.platform) {
|
|
86
|
+
args.push('--platform', imageEntry.platform);
|
|
87
|
+
}
|
|
88
|
+
args.push(imageEntry.image);
|
|
33
89
|
|
|
34
|
-
dockerPull
|
|
35
|
-
|
|
36
|
-
|
|
90
|
+
const dockerPull = spawn('docker', args, { shell: true });
|
|
91
|
+
let stderrOutput = '';
|
|
92
|
+
|
|
93
|
+
dockerPull.stdout.on('data', () => { });
|
|
37
94
|
|
|
38
95
|
dockerPull.stderr.on('data', (data) => {
|
|
39
|
-
|
|
40
|
-
response.fail(chalk.red('Le service Docker ne répond pas.'));
|
|
41
|
-
return process.exit(1);
|
|
96
|
+
stderrOutput += data.toString();
|
|
42
97
|
});
|
|
43
98
|
|
|
44
99
|
dockerPull.on('close', (code) => {
|
|
45
100
|
if (code !== 0) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
101
|
+
const details = stderrOutput.trim();
|
|
102
|
+
response.fail(
|
|
103
|
+
details
|
|
104
|
+
? `Échec du téléchargement (${label}) : ${details}`
|
|
105
|
+
: `Échec du téléchargement (${label}) (code ${code})`
|
|
106
|
+
);
|
|
107
|
+
process.exitCode = 1;
|
|
108
|
+
return;
|
|
50
109
|
}
|
|
110
|
+
response.succeed(`Image ${label} OK.`);
|
|
111
|
+
installDockerImages(images, ndx + 1);
|
|
51
112
|
});
|
|
52
113
|
};
|
|
53
114
|
|
|
@@ -76,12 +137,30 @@ module.exports = (args) => {
|
|
|
76
137
|
description: 'Installation des images Docker',
|
|
77
138
|
},
|
|
78
139
|
start: () => {
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
140
|
+
const composeFile = findDockerComposeFile();
|
|
141
|
+
if (!composeFile) {
|
|
142
|
+
console.error(
|
|
143
|
+
chalk.red(
|
|
144
|
+
"docker/docker-compose.yml introuvable. Exécutez la commande depuis la racine de votre projet cadriciel."
|
|
145
|
+
)
|
|
146
|
+
);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const dockerImagesToInstall = extractImagesFromCompose(composeFile);
|
|
150
|
+
if (!dockerImagesToInstall.length) {
|
|
151
|
+
console.log(
|
|
152
|
+
chalk.yellow(
|
|
153
|
+
'Aucune image Docker détectée dans docker/docker-compose.yml.'
|
|
154
|
+
)
|
|
155
|
+
);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const detectedList = dockerImagesToInstall
|
|
159
|
+
.map((img) =>
|
|
160
|
+
img.platform ? `${img.image} (${img.platform})` : img.image
|
|
161
|
+
)
|
|
162
|
+
.join(', ');
|
|
163
|
+
console.log(chalk.gray(`Images détectées: ${detectedList}`));
|
|
85
164
|
setupEnvironment(dockerImagesToInstall);
|
|
86
165
|
},
|
|
87
166
|
};
|