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';
- Read the dojo enonce file from the enonce repository
- 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();
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);
}
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.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
- Wait until the end of the execution of the result container
- Get logs from linked services
*/
console.log(chalk.green('Run docker compose file'));
const changeDirectoryCommand = `cd "${ Config.filesFolder }"`;
const dockerComposeCommand = `docker compose --project-name ${ Config.dockerCompose.projectName } --progress plain`;
console.log(chalk.green('- Run docker compose file'));
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);
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) => {
let logs = '####################################################### Docker Compose & Main Container Logs #######################################################\n';
const dockerCompose = spawn(`${ dockerComposeCommand } run ${ exerciceEnonce.enonceFile.result.container }`, {
cwd : Config.filesFolder,
cwd : Config.folders.project,
shell: true,
env : {
'DOCKER_BUILDKIT' : '1',
......@@ -77,23 +81,24 @@ import Config from './config/Config';
});
});
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]);
}
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 {
await execAsync(`${ changeDirectoryCommand };${ dockerComposeCommand } logs --timestamps >> ${ Config.resultsFolder }/dockerComposeLogs.txt`);
await execAsync(`${ changeDirectoryCommand };${ dockerComposeCommand } logs --timestamps >> ${ Config.folders.resultsDojo }/dockerComposeLogs.txt`);
} 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);
}
// Step 5: Get the result from the volume
// Step 6: Check content requirements and content size
// Step 7: Upload and show the results
// Step 8: Exit with container exit code
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