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;
}
int DockerModule::clean ()
int removeContainersCreatedByDockerCompose()
{
return BashManager::execute("docker-compose down --rmi all --remove-orphans");
}
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);
}
int DockerModule::remove (Service service)
{
//remove unwanted containers
removeContainersCreatedByDockerCompose();
removeContainersWithServiceName(service.getUsername());
return 0;
}
int DockerModule::clean()
{
BashManager::execute("docker-compose down --rmi all --remove-orphans");
/*
if ! "$deploy" ; then
section "Remove stray containers"
while read container ; do
[ -z "$container" ] && continue || true
echo "Removing $container"
run docker rm "$container"
done <<< "$(docker ps | grep "$docker_service" | cut -d ' ' -f 1)"
fi
*/
return 0;
}

View File

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

View File

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