diff --git a/src/DockerModule.cpp b/src/DockerModule.cpp index 8985be2..c69133b 100644 --- a/src/DockerModule.cpp +++ b/src/DockerModule.cpp @@ -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) diff --git a/src/main.cpp b/src/main.cpp index f7844b2..786d816 100644 --- a/src/main.cpp +++ b/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" <