dockermodule avance

This commit is contained in:
eleonore12345 2024-08-06 18:05:33 +02:00
parent 88ae1628d1
commit b6a0db351c
4 changed files with 26 additions and 14 deletions

View File

@ -28,18 +28,28 @@ int DockerModule::deploy (Service service)
return 0; return 0;
} }
int DockerModule::clean ()
int removeContainersCreatedByDockerCompose()
{ {
BashManager::execute("docker-compose down --rmi all --remove-orphans"); return BashManager::execute("docker-compose down --rmi all --remove-orphans");
/* }
if ! "$deploy" ; then
section "Remove stray containers" int removeContainersWithServiceName(string serviceName)
while read container ; do {
[ -z "$container" ] && continue || true string dockerService=serviceName.replace(serviceName.find('.'),1,"_");
echo "Removing $container" string cmd="$(docker ps | grep " + dockerService +" | cut -d ' ' -f 1)";
run docker rm "$container" return BashManager::execute(cmd);
done <<< "$(docker ps | grep "$docker_service" | cut -d ' ' -f 1)" }
fi
*/ int DockerModule::remove (Service service)
{
//remove unwanted containers
removeContainersCreatedByDockerCompose();
removeContainersWithServiceName(service.getUsername());
return 0; return 0;
} }
int DockerModule::clean()
{
return 0;
}

View File

@ -14,6 +14,7 @@ class DockerModule : public Module
~DockerModule(){} //inline ~DockerModule(){} //inline
int prepare (); int prepare ();
int deploy (Service service); int deploy (Service service);
int remove(Service service);
int clean (); int clean ();
}; };

View File

@ -16,6 +16,7 @@ class Module
virtual ~Module()=0; //make protected to ensure it is not used externally? virtual ~Module()=0; //make protected to ensure it is not used externally?
virtual int prepare ()=0; virtual int prepare ()=0;
virtual int deploy (Service service)=0; virtual int deploy (Service service)=0;
virtual int remove(Service service)=0;
virtual int clean ()=0; virtual int clean ()=0;
}; };
#endif #endif

View File

@ -3,4 +3,4 @@
using namespace std; using namespace std;
vector < string > modules = {"DockerModule"}; vector < string > modules = {"DockerModule"};