Skip to content
Snippets Groups Projects
Commit f3318470 authored by michael.minelli's avatar michael.minelli
Browse files

Rewrite step 3 and 4 (and add step 5) with the linking of volume with the host container

parent 3e0fc237
No related branches found
No related tags found
No related merge requests found
Pipeline #25630 passed
...@@ -26,34 +26,38 @@ import Config from './config/Config'; ...@@ -26,34 +26,38 @@ import Config from './config/Config';
- Read the dojo enonce file from the enonce repository - Read the dojo enonce file from the enonce repository
- Download immutables files (maybe throw or show an error if the files have been modified ?) - Download immutables files (maybe throw or show an error if the files have been modified ?)
*/ */
console.log(chalk.green('Checking the exercice\'s enonce and his immutables files')); console.log(chalk.green('- Checking the exercice\'s enonce and his immutable files'));
const exerciceEnonce = await DojoBackendManager.getExerciceEnonce(); const exerciceEnonce = await DojoBackendManager.getExerciceEnonce();
if ( !exerciceEnonce ) { if ( !exerciceEnonce ) {
console.error(chalk.red(`Error while getting the exercice's enonce`)); console.error(chalk.red(`X Error while getting the exercice's enonce`));
process.exit(ExerciceCheckerError.EXERCICE_ENONCE_GET_ERROR); process.exit(ExerciceCheckerError.EXERCICE_ENONCE_GET_ERROR);
} }
exerciceEnonce.immutable.forEach(immutableFile => { exerciceEnonce.immutable.forEach(immutableFile => {
const filePath = `${ Config.filesFolder }/${ immutableFile.file_path }`.replace(/\/\//g, '/'); const filePath = `${ Config.folders.project }/${ immutableFile.file_path }`.replace(/\/\//g, '/');
fs.mkdirSync(path.dirname(filePath), { recursive: true }); fs.mkdirSync(path.dirname(filePath), { recursive: true });
fs.writeFileSync(filePath, immutableFile.content, { encoding: 'base64' }); fs.writeFileSync(filePath, immutableFile.content, { encoding: 'base64' });
}); });
/* /*
Step 3 & 4: Step 3 & 4 & 5:
- Get override of docker-compose file (for override the volume by a bind mount to the results folder shared between dind and the host)
- Run docker-compose file - Run docker-compose file
- Wait until the end of the execution of the result container - Get logs from linked services
*/ */
console.log(chalk.green('Run docker compose file')); console.log(chalk.green('- Run docker compose file'));
const changeDirectoryCommand = `cd "${ Config.filesFolder }"`; const dockerComposeOverride = fs.readFileSync(path.join(__dirname, '../assets/docker-compose-override.yml'), 'utf8').replace('{{VOLUME_NAME}}', exerciceEnonce.enonceFile.result.volume).replace('{{MOUNT_PATH}}', Config.folders.resultsExercice);
const dockerComposeCommand = `docker compose --project-name ${ Config.dockerCompose.projectName } --progress plain`; fs.writeFileSync(`${ Config.folders.project }/docker-compose-override.yml`, dockerComposeOverride);
const changeDirectoryCommand = `cd "${ Config.folders.project }"`;
const dockerComposeCommand = `docker compose --project-name ${ Config.dockerCompose.projectName } --progress plain --file docker-compose.yml --file docker-compose-override.yml`;
const containerExitStatus = await new Promise<[ number, string ]>((resolve, reject) => { const containerExitStatus = await new Promise<[ number, string ]>((resolve, reject) => {
let logs = '####################################################### Docker Compose & Main Container Logs #######################################################\n'; let logs = '####################################################### Docker Compose & Main Container Logs #######################################################\n';
const dockerCompose = spawn(`${ dockerComposeCommand } run ${ exerciceEnonce.enonceFile.result.container }`, { const dockerCompose = spawn(`${ dockerComposeCommand } run ${ exerciceEnonce.enonceFile.result.container }`, {
cwd : Config.filesFolder, cwd : Config.folders.project,
shell: true, shell: true,
env : { env : {
'DOCKER_BUILDKIT' : '1', 'DOCKER_BUILDKIT' : '1',
...@@ -77,23 +81,24 @@ import Config from './config/Config'; ...@@ -77,23 +81,24 @@ import Config from './config/Config';
}); });
}); });
if ( containerExitStatus[0] === ExerciceCheckerError.DOCKER_COMPOSE_UP_ERROR ) { if ( containerExitStatus[0] === ExerciceCheckerError.DOCKER_COMPOSE_UP_ERROR ) {
console.error(chalk.red(`Error while running the docker-compose file`)); console.error(chalk.red(`X Error while running the docker compose file`));
process.exit(containerExitStatus[0]); process.exit(containerExitStatus[0]);
} }
fs.writeFileSync(`${ Config.resultsFolder }/dockerComposeLogs.txt`, containerExitStatus[1]); fs.writeFileSync(`${ Config.folders.resultsDojo }/dockerComposeLogs.txt`, containerExitStatus[1]);
console.log(chalk.green('- Acquire logs of linked services'));
try { try {
await execAsync(`${ changeDirectoryCommand };${ dockerComposeCommand } logs --timestamps >> ${ Config.resultsFolder }/dockerComposeLogs.txt`); await execAsync(`${ changeDirectoryCommand };${ dockerComposeCommand } logs --timestamps >> ${ Config.folders.resultsDojo }/dockerComposeLogs.txt`);
} catch ( error ) { } catch ( error ) {
console.error(chalk.red(`Error while getting the docker-compose logs`)); console.error(chalk.red(`X Error while getting the linked services logs`));
process.exit(ExerciceCheckerError.DOCKER_COMPOSE_LOGS_ERROR); process.exit(ExerciceCheckerError.DOCKER_COMPOSE_LOGS_ERROR);
} }
// Step 5: Get the result from the volume
// Step 6: Check content requirements and content size // Step 6: Check content requirements and content size
// Step 7: Upload and show the results // Step 7: Upload and show the results
// Step 8: Exit with container exit code // Step 8: Exit with container exit code
process.exit(containerExitStatus[0]); process.exit(containerExitStatus[0]);
})(); })();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment