main avant ajout de l'execution des scripts bash

This commit is contained in:
eleonore12345 2024-08-07 14:33:15 +02:00
parent fd3bf3f7a8
commit 667ee25133
2 changed files with 42 additions and 19 deletions

View File

@ -18,7 +18,10 @@ int DockerModule::prepare()
int DockerModule::deploy (string serviceUsername) int DockerModule::deploy (string serviceUsername)
{ {
//go to the right directory cout << "docker module deploy" << endl;
/*
//test if there is a docker compose
//pulling images //pulling images
int pulling =BashManager::execute("docker-compose pull")==0; int pulling =BashManager::execute("docker-compose pull")==0;
if(pulling==0){ if(pulling==0){
@ -28,6 +31,7 @@ int DockerModule::deploy (string serviceUsername)
cerr << "Error in DockerModule deploying "<< serviceUsername << endl; cerr << "Error in DockerModule deploying "<< serviceUsername << endl;
return -1; return -1;
} }
*/
return 0; return 0;
} }
@ -37,10 +41,22 @@ int removeContainersCreatedByDockerCompose()
} }
int removeContainersWithServiceName(string serviceName) int removeContainersWithServiceName(string serviceName)
{ {
string dockerService=serviceName.replace(serviceName.find('.'),1,"_"); //constructing the name of the docker container from the name of the service by replacing . with _
string cmd="$(docker ps | grep " + dockerService +" | cut -d ' ' -f 1)"; size_t pos=serviceName.find('.');
return BashManager::execute(cmd); if (pos==string::npos){
cerr << "Error. Service name should contain a ." << endl;
return -1;
}else {
string dockerService=serviceName;
dockerService=dockerService.substr(0,pos)+dockerService.substr(pos+1);
//removing containers with the name of the service
string cmd="while read container ; do \
[ -z \"$container\" ] && continue || true ; \
docker rm \"$container\" ; \
done <<< \"$(docker ps | grep '" + dockerService + "' | cut -d ' ' -f 1)\"";
return BashManager::execute(cmd);
}
} }
int DockerModule::remove (string serviceUsername) int DockerModule::remove (string serviceUsername)

View File

@ -34,21 +34,24 @@ int isServiceOnServer(string serviceUsername)
int createUser(string serviceUsername){ int createUser(string serviceUsername){
//TO DO //TO DO
cout << "create user called" << endl;
return 0; return 0;
} }
int createEnv(string serviceUsername){ int createEnv(string serviceUsername){
//TO DO //TO DO
cout << "create env called" << endl;
return 0; return 0;
} }
int runBashScripts(string serviceUsername){ int runBashScripts(string serviceUsername){
//TO DO //TO DO
cout << "run bash scripts called" << endl;
return 0; return 0;
} }
int deployAll(){ int deployAll(){
//this methods deploys all the services that are on this server //this method deploys all the services that are on this server
cout << "deploying all" <<endl; cout << "deploying all" <<endl;
return 0; return 0;
} }
@ -58,26 +61,30 @@ int deployService(string serviceUsername){
//TO DO: faire des boucles if cohérentes //TO DO: faire des boucles if cohérentes
if (isServiceOnServer(serviceUsername)==0){ if (isServiceOnServer(serviceUsername)==0){
//bash user creation //bash user creation
int userCreated = createUser(serviceUsername); if(int userCreated = createUser(serviceUsername);userCreated!=0){
return -1;
}
//environment variables creation //environment variables creation
int envCreated = createEnv(serviceUsername); if(int envCreated = createEnv(serviceUsername);envCreated!=0){
return -1;
}
//bash scripts call //bash scripts call
int bashScriptsRun = runBashScripts(serviceUsername); if(int bashScriptsRun = runBashScripts(serviceUsername);bashScriptsRun!=0){
return -1;
}
//call to the deploy functionality of all modules //call to the deploy functionality of all modules
//the modules themselves determine their course of action depending on the service //the modules themselves determine their course of action depending on the service
if (userCreated && envCreated){ for(Module * mod_ptr : modules){
for(Module * mod_ptr : modules){ int modResult = (*mod_ptr).deploy(serviceUsername);
int modResult = (*mod_ptr).deploy(serviceUsername); if (modResult!=0){
if (modResult!=0){ cerr << "Error in module " << (*mod_ptr) << " when deploying " << serviceUsername << endl;
cerr << "Error in module " << (*mod_ptr) << " when deploying " << serviceUsername << endl;
}
} }
return 0;
}else{
cerr << "Error creating user and environment of "<<serviceUsername << endl;
} }
return 0;
cerr << "Error creating user and environment of "<<serviceUsername << endl;
} }
return 0;
} }
int removeAll(){ int removeAll(){