mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
Adds image validation + download
This commit is contained in:
parent
1a7be0ad79
commit
8eab2d3a05
2 changed files with 43 additions and 0 deletions
|
|
@ -31,6 +31,7 @@ services:
|
|||
EMAIL_PSW: 'vvml wmfr dkzb vjzb'
|
||||
JWT_SECRET: haQdgd2jp09qb897GeBZyJetC8ECSpbFJe
|
||||
FRONTEND_URL: "http://localhost:5173"
|
||||
#QUIZROOM_IMAGE: ghcr.io/ets-cfuhrman-pfe/evaluetonsavoir-quizroom:latest
|
||||
depends_on:
|
||||
- mongo
|
||||
networks:
|
||||
|
|
|
|||
|
|
@ -46,10 +46,52 @@ class DockerRoomProvider extends BaseRoomProvider {
|
|||
}
|
||||
}
|
||||
|
||||
async checkAndPullImage(imageName) {
|
||||
try {
|
||||
const images = await this.docker.listImages({ all: true });
|
||||
//console.log('Images disponibles:', images.map(img => ({
|
||||
// RepoTags: img.RepoTags || [],
|
||||
// Id: img.Id
|
||||
//})));
|
||||
|
||||
const imageExists = images.some(img => {
|
||||
const tags = img.RepoTags || [];
|
||||
return tags.includes(imageName) ||
|
||||
tags.includes(`${imageName}:latest`) ||
|
||||
img.Id.includes(imageName);
|
||||
});
|
||||
|
||||
if (!imageExists) {
|
||||
console.log(`L'image ${imageName} n'a pas été trouvée localement, tentative de téléchargement...`);
|
||||
try {
|
||||
await this.docker.pull(imageName);
|
||||
console.log(`L'image ${imageName} a été téléchargée avec succès`);
|
||||
} catch (pullError) {
|
||||
const localImages = await this.docker.listImages({ all: true });
|
||||
const foundLocally = localImages.some(img =>
|
||||
(img.RepoTags || []).includes(imageName) ||
|
||||
(img.RepoTags || []).includes(`${imageName}:latest`)
|
||||
);
|
||||
|
||||
if (!foundLocally) {
|
||||
throw new Error(`Impossible de trouver ou de télécharger l'image ${imageName}: ${pullError.message}`);
|
||||
} else {
|
||||
console.log(`L'image ${imageName} a été trouvée localement après vérification supplémentaire`);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log(`L'image ${imageName} a été trouvée localement`);
|
||||
}
|
||||
} catch (error) {
|
||||
throw new Error(`Une erreur est survenue lors de la vérification/téléchargement de l'image ${imageName}: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
async createRoom(roomId, options) {
|
||||
const container_name = `room_${roomId}`;
|
||||
|
||||
try {
|
||||
await this.checkAndPullImage(this.quiz_docker_image);
|
||||
const containerConfig = {
|
||||
Image: this.quiz_docker_image,
|
||||
name: container_name,
|
||||
|
|
|
|||
Loading…
Reference in a new issue