main avant ajout de l'execution des scripts bash
This commit is contained in:
parent
fd3bf3f7a8
commit
667ee25133
@ -18,7 +18,10 @@ int DockerModule::prepare()
|
||||
|
||||
int DockerModule::deploy (string serviceUsername)
|
||||
{
|
||||
//go to the right directory
|
||||
cout << "docker module deploy" << endl;
|
||||
/*
|
||||
|
||||
//test if there is a docker compose
|
||||
//pulling images
|
||||
int pulling =BashManager::execute("docker-compose pull")==0;
|
||||
if(pulling==0){
|
||||
@ -28,6 +31,7 @@ int DockerModule::deploy (string serviceUsername)
|
||||
cerr << "Error in DockerModule deploying "<< serviceUsername << endl;
|
||||
return -1;
|
||||
}
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -37,10 +41,22 @@ int removeContainersCreatedByDockerCompose()
|
||||
}
|
||||
|
||||
int removeContainersWithServiceName(string serviceName)
|
||||
{
|
||||
string dockerService=serviceName.replace(serviceName.find('.'),1,"_");
|
||||
string cmd="$(docker ps | grep " + dockerService +" | cut -d ' ' -f 1)";
|
||||
return BashManager::execute(cmd);
|
||||
{
|
||||
//constructing the name of the docker container from the name of the service by replacing . with _
|
||||
size_t pos=serviceName.find('.');
|
||||
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)
|
||||
|
35
src/main.cpp
35
src/main.cpp
@ -34,21 +34,24 @@ int isServiceOnServer(string serviceUsername)
|
||||
|
||||
int createUser(string serviceUsername){
|
||||
//TO DO
|
||||
cout << "create user called" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int createEnv(string serviceUsername){
|
||||
//TO DO
|
||||
cout << "create env called" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int runBashScripts(string serviceUsername){
|
||||
//TO DO
|
||||
cout << "run bash scripts called" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
return 0;
|
||||
}
|
||||
@ -58,26 +61,30 @@ int deployService(string serviceUsername){
|
||||
//TO DO: faire des boucles if cohérentes
|
||||
if (isServiceOnServer(serviceUsername)==0){
|
||||
//bash user creation
|
||||
int userCreated = createUser(serviceUsername);
|
||||
if(int userCreated = createUser(serviceUsername);userCreated!=0){
|
||||
return -1;
|
||||
}
|
||||
//environment variables creation
|
||||
int envCreated = createEnv(serviceUsername);
|
||||
if(int envCreated = createEnv(serviceUsername);envCreated!=0){
|
||||
return -1;
|
||||
}
|
||||
//bash scripts call
|
||||
int bashScriptsRun = runBashScripts(serviceUsername);
|
||||
if(int bashScriptsRun = runBashScripts(serviceUsername);bashScriptsRun!=0){
|
||||
return -1;
|
||||
}
|
||||
//call to the deploy functionality of all modules
|
||||
//the modules themselves determine their course of action depending on the service
|
||||
if (userCreated && envCreated){
|
||||
for(Module * mod_ptr : modules){
|
||||
int modResult = (*mod_ptr).deploy(serviceUsername);
|
||||
if (modResult!=0){
|
||||
cerr << "Error in module " << (*mod_ptr) << " when deploying " << serviceUsername << endl;
|
||||
}
|
||||
for(Module * mod_ptr : modules){
|
||||
int modResult = (*mod_ptr).deploy(serviceUsername);
|
||||
if (modResult!=0){
|
||||
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(){
|
||||
|
Loading…
Reference in New Issue
Block a user