diff --git a/bin/deployer b/bin/deployer index 4804c9d..e9887d3 100755 Binary files a/bin/deployer and b/bin/deployer differ diff --git a/src/DockerModule.cpp b/src/DockerModule.cpp new file mode 100644 index 0000000..38d61b9 --- /dev/null +++ b/src/DockerModule.cpp @@ -0,0 +1,49 @@ +// deployer DockerModule implementation +// Copyright (C) 2024 Jean-Cloud +// GNU General Public License v3 + +#include "DockerModule.h" + +//constructor and destructor inline + +//public methods +int DockerModule::prepare() +{ + return 0; + //nothing to do ? +} + +int DockerModule::deploy (Service service) +{ + return 0; + /* bash script for inspo + isServiceOnServer(); +docker_service="$(echo "$service" | tr '.' '_')" + +## deploy + + + if $deploy ; then + section "Logging to registry" + # XXX Login to docker registry + + section "Pulling images" + docker-compose pull + if [ "$?" -ne 0 ] ; then + echo "PULL FAILED" + fi + + section "Starting service" + run docker-compose up -d --remove-orphans + [ "$?" -ne 0 ] && echo "Erreur docker compose" && returncode=1 + else + section "Removing containers" + run docker-compose down --rmi all --remove-orphans + fi +fi +*/ +} +int DockerModule::clean () +{ + return 0; +} \ No newline at end of file diff --git a/src/DockerModule.h b/src/DockerModule.h new file mode 100644 index 0000000..dea6ee3 --- /dev/null +++ b/src/DockerModule.h @@ -0,0 +1,20 @@ +// deployer DockerModule header +// Copyright (C) 2024 Jean-Cloud +// GNU General Public License v3 + +#if !defined(DOCKERMODULE_H) +#define DOCKERMODULE_H + +#include "Module.h" + +class DockerModule : public Module +{ + public: + DockerModule(){} //inline + ~DockerModule(){} //inline + int prepare (); + int deploy (Service service); + int clean (); +}; + +#endif \ No newline at end of file diff --git a/src/Module.cpp b/src/Module.cpp index 6f90997..1c36094 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -2,8 +2,35 @@ // Copyright (C) 2024 Jean-Cloud // GNU General Public License v3 +#include +#include #include "Module.h" +//constructor inline +//destructor, could not be inline because pure virtual Module::~Module(){} +//protected methods (unprotected for tests purposes) +int Module::isserviceOnServer() +//this method tests if a certain service is on the current server +//it uses the bash command dig, thanks to a pipe to a separate bash process +{ + FILE *p; + char result [100]; + + p = popen("ls -la","r"); //just to test that popen works + if( p == NULL) + { + cout << "Unable to verify if the service is on the server, bash process opening error." << endl; + return -1; + } + while(fgets(result,100,p)!=NULL){ + //if several lines, copy result somewhere to save it + cout << result << endl; + } + pclose(p); + return 0; +} + + diff --git a/src/Module.h b/src/Module.h index 0fc1e9e..5a1c653 100644 --- a/src/Module.h +++ b/src/Module.h @@ -6,16 +6,18 @@ #define MODULE_H #include +#include "Service.h" class Module { - protected: + public: Module(){}; - virtual ~Module()=0; - - private: - bool activated; //true if the service requires this module - char * service; - + //=0 means pure virtual method, making Module a pure virtual class + virtual ~Module()=0; //make protected to ensure it is not used externally? + virtual int prepare ()=0; + virtual int deploy (Service service)=0; + virtual int clean ()=0; + //protected: commented for test purposes + virtual int isserviceOnServer(); }; #endif \ No newline at end of file diff --git a/src/Service.cpp b/src/Service.cpp index 309516d..7f3c3fd 100644 --- a/src/Service.cpp +++ b/src/Service.cpp @@ -4,6 +4,9 @@ #include "Service.h" +//constructor and destructor defined inline + +//public methods int Service::getUserID () const { return userID; @@ -17,6 +20,7 @@ list Service::getServers() const return servers; } +//operator << override ostream & operator << (ostream & out, const Service & s) { out << "userID: " << s.userID << endl << "username: " << s.username << endl << "servers: "; diff --git a/src/deployer b/src/deployer new file mode 100755 index 0000000..c127462 Binary files /dev/null and b/src/deployer differ diff --git a/src/main.cpp b/src/main.cpp index 9256ffb..f5c9824 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,12 +7,13 @@ #include #include #include "Services.h" -#include "Module.h" +#include "DockerModule.h" using namespace std; bool action_deploy=false; bool action_remove=false; bool all=false; +//list modules; void help() { @@ -36,14 +37,9 @@ int main(int argc, char *argv[]) cout << "Invalid argument. \n" << endl; exit(1); } - Services myServices=Services("../src/services.csv"); - const Service * ptr_myService=myServices.findByID(1); - if (ptr_myService==nullptr){ - cout<< "service not found"<