this.events.emit('step','REQUIREMENTS_CHECKING','Please wait while we are checking requirements...');
this.newStep('REQUIREMENTS_CHECKING','Please wait while we are checking requirements...');
// Check requirements
this.events.emit('subStep','DOCKER_RUNNING','Checking if Docker daemon is running');
this.newSubStep('DOCKER_RUNNING','Checking if Docker daemon is running');
try{
awaitexecAsync(`docker ps`);
}catch (error){
emitError('DOCKER_RUNNING',`Docker daemon isn't running`,'REQUIREMENTS_CHECKING',`Some requirements are not satisfied.`,AssignmentCheckerError.DOCKER_DAEMON_NOT_RUNNING);
this.emitError(`Docker daemon isn't running`,`Some requirements are not satisfied.`,AssignmentCheckerError.DOCKER_DAEMON_NOT_RUNNING);
return;
}
this.events.emit('endSubStep','DOCKER_RUNNING','Docker daemon is running',false);
this.endSubStep('Docker daemon is running',false);
// Check if required files exists
this.events.emit('subStep','REQUIRED_FILES_EXISTS','Checking if required files exists');
this.newSubStep('REQUIRED_FILES_EXISTS','Checking if required files exists');
emitError('REQUIRED_FILES_EXISTS',`The exercise folder is missing the following files: ${missingFiles.map((file:[string,boolean])=>file[0]).join(', ')}`,'REQUIREMENTS_CHECKING','Some requirements are not satisfied',AssignmentCheckerError.REQUIRED_FILES_MISSING);
this.emitError(`The exercise folder is missing the following files: ${missingFiles.map((file:[string,boolean])=>file[0]).join(', ')}`,'Some requirements are not satisfied',AssignmentCheckerError.REQUIRED_FILES_MISSING);
emitError('ASSIGNMENT_FILE_SCHEMA_VALIDATION',`dojo_assignment.json file schema is invalid.\nHere are the errors:\n${JSON5.stringify(validationResults.errors)}`,'ASSIGNMENT_FILE_VALIDATION','dojo_assignment.json file is invalid',AssignmentCheckerError.ASSIGNMENT_FILE_SCHEMA_ERROR);
this.emitError(`dojo_assignment.json file schema is invalid.\nHere are the errors:\n${JSON5.stringify(validationResults.errors)}`,'dojo_assignment.json file is invalid',AssignmentCheckerError.ASSIGNMENT_FILE_SCHEMA_ERROR);
return;
}
assignmentFile=validationResults.results!;
this.events.emit('endSubStep','ASSIGNMENT_FILE_SCHEMA_VALIDATION','dojo_assignment.json file schema is valid',false);
this.endSubStep('dojo_assignment.json file schema is valid',false);
// Immutable files validation (Check if exists and if the given type is correct)
emitError('ASSIGNMENT_FILE_IMMUTABLES_VALIDATION',`Immutable path not found: ${immutable.path}`,'ASSIGNMENT_FILE_VALIDATION','dojo_assignment.json file is invalid',AssignmentCheckerError.IMMUTABLE_PATH_NOT_FOUND);
this.emitError(`Immutable path not found: ${immutable.path}`,'dojo_assignment.json file is invalid',AssignmentCheckerError.IMMUTABLE_PATH_NOT_FOUND);
emitError('ASSIGNMENT_FILE_IMMUTABLES_VALIDATION',`Immutable (${immutable.path}) is declared as a file but is a directory.`,'ASSIGNMENT_FILE_VALIDATION','dojo_assignment.json file is invalid',AssignmentCheckerError.IMMUTABLE_PATH_IS_NOT_DIRECTORY);
this.emitError(`Immutable (${immutable.path}) is declared as a file but is a directory.`,'dojo_assignment.json file is invalid',AssignmentCheckerError.IMMUTABLE_PATH_IS_NOT_DIRECTORY);
emitError('ASSIGNMENT_FILE_IMMUTABLES_VALIDATION',`Immutable (${immutable.path}) is declared as a directory but is a file.`,'ASSIGNMENT_FILE_VALIDATION','dojo_assignment.json file is invalid',AssignmentCheckerError.IMMUTABLE_PATH_IS_DIRECTORY);
this.emitError(`Immutable (${immutable.path}) is declared as a directory but is a file.`,'dojo_assignment.json file is invalid',AssignmentCheckerError.IMMUTABLE_PATH_IS_DIRECTORY);
return;
}
}
this.events.emit('endSubStep','ASSIGNMENT_FILE_IMMUTABLES_VALIDATION','Immutable files are valid',false);
this.endSubStep('Immutable files are valid',false);
this.events.emit('endStep','ASSIGNMENT_FILE_VALIDATION','dojo_assignment.json file is valid',false);
this.endStep('dojo_assignment.json file is valid',false);
}
...
...
@@ -142,15 +171,15 @@ class AssignmentValidator {
- Validation of the containers and volumes named in dojo_assignment.json
*/
{
this.events.emit('step','DOCKER_COMPOSE_VALIDATION','Please wait while we are validating docker compose file...');
this.newStep('DOCKER_COMPOSE_VALIDATION','Please wait while we are validating docker compose file...');
emitError('DOCKER_COMPOSE_STRUCTURE_VALIDATION',`Docker compose file yaml structure is invalid.`,'DOCKER_COMPOSE_VALIDATION','Docker compose file is invalid',AssignmentCheckerError.COMPOSE_FILE_YAML_ERROR);
this.emitError(`Docker compose file yaml structure is invalid.`,'Docker compose file is invalid',AssignmentCheckerError.COMPOSE_FILE_YAML_ERROR);
return;
}
...
...
@@ -166,26 +195,26 @@ class AssignmentValidator {
});
});
}catch (error){
emitError('DOCKER_COMPOSE_STRUCTURE_VALIDATION',`Docker compose file structure is invalid.`,'DOCKER_COMPOSE_VALIDATION','Docker compose file is invalid',AssignmentCheckerError.COMPOSE_FILE_SCHEMA_ERROR);
this.emitError(`Docker compose file structure is invalid.`,'Docker compose file is invalid',AssignmentCheckerError.COMPOSE_FILE_SCHEMA_ERROR);
return;
}
this.events.emit('endSubStep','DOCKER_COMPOSE_STRUCTURE_VALIDATION','Docker compose file structure is valid',false);
this.endSubStep('Docker compose file structure is valid',false);
// Validation of the containers and volumes named in dojo_assignment.json
if (!(assignmentFile.result.containerindockerComposeFile!.services)){
emitError('DOCKER_COMPOSE_CONTENT_VALIDATION',`Container specified in ${ClientsSharedConfig.assignment.filename} is missing from compose file.`,'DOCKER_COMPOSE_VALIDATION','Docker compose file is invalid',AssignmentCheckerError.COMPOSE_FILE_CONTAINER_MISSING);
this.emitError(`Container specified in ${ClientsSharedConfig.assignment.filename} is missing from compose file.`,'Docker compose file is invalid',AssignmentCheckerError.COMPOSE_FILE_CONTAINER_MISSING);
return;
}
if (assignmentFile.result.volume&&(!dockerComposeFile!.volumes||!(assignmentFile.result.volumeindockerComposeFile!.volumes))){
emitError('DOCKER_COMPOSE_CONTENT_VALIDATION',`Volume specified in ${ClientsSharedConfig.assignment.filename} is missing from compose file.`,'DOCKER_COMPOSE_VALIDATION','Docker compose file is invalid',AssignmentCheckerError.COMPOSE_FILE_VOLUME_MISSING);
this.emitError(`Volume specified in ${ClientsSharedConfig.assignment.filename} is missing from compose file.`,'Docker compose file is invalid',AssignmentCheckerError.COMPOSE_FILE_VOLUME_MISSING);
return;
}
this.events.emit('endSubStep','DOCKER_COMPOSE_CONTENT_VALIDATION','Docker compose file content is valid',false);
this.endSubStep('Docker compose file content is valid',false);
this.events.emit('endStep','DOCKER_COMPOSE_VALIDATION','Docker compose file is valid',false);
this.endStep('Docker compose file is valid',false);
emitError('DOCKERFILE_VALIDATION',`Dockerfiles not found: ${filesNotFound.join(', ')}`,'DOCKERFILE_VALIDATION','Dockerfiles are invalid',AssignmentCheckerError.DOCKERFILE_NOT_FOUND);
this.emitError(`Dockerfiles not found: ${filesNotFound.join(', ')}`,'Dockerfiles are invalid',AssignmentCheckerError.DOCKERFILE_NOT_FOUND);
return;
}
this.events.emit('endSubStep','DOCKER_COMPOSE_CONTENT_VALIDATION','Docker compose file content is valid',false);
this.endSubStep('Docker compose file content is valid',false);
this.events.emit('endStep','DOCKERFILE_VALIDATION','Dockerfiles are valid',false);
this.endStep('Dockerfiles are valid',false);
}
...
...
@@ -217,7 +246,7 @@ class AssignmentValidator {
- Make a run of the assignment (If the return code is 0, the assignment is not valid because it means that there no need of modification for succeed the exercise)
*/
{
this.events.emit('step','ASSIGNMENT_RUN','Please wait while we are running the assignment...');
this.newStep('ASSIGNMENT_RUN','Please wait while we are running the assignment...');