diff --git a/src/BashManager.cpp b/src/BashManager.cpp index 313721a..c02f6af 100644 --- a/src/BashManager.cpp +++ b/src/BashManager.cpp @@ -31,4 +31,4 @@ string BashManager::executeAndReadResult(string command) } pclose(p); return result; -} \ No newline at end of file +} diff --git a/src/BashModule.cpp b/src/BashModule.cpp new file mode 100644 index 0000000..955a3cd --- /dev/null +++ b/src/BashModule.cpp @@ -0,0 +1,70 @@ +// deployer BashModule implementation +// Copyright (C) 2024 Jean-Cloud +// GNU General Public License v3 + +#include +#include +#include +#include +#include "BashModule.h" +#include "BashManager.h" + +using namespace std; + +//destructor inline +BashModule::BashModule() +{ + name="Bash"; +} + +//private methods +int BashModule::executeScript(string serviceUsername) +{ + //this method is called in deploy(), it executes the script deploy.sh if it exists + string deployscript="./services/"+serviceUsername+"/deploy.sh"; + if(filesystem::exists(deployscript)){ + pid_t pid = fork(); + if (pid == -1) { + cerr << "Error when forking." << endl; + return -1; + } else if (pid > 0) { + int status; + waitpid(-1,&status,0); + if(status==-1){ + cerr << "Error when executing " << deployscript << endl; + } + cout << "status vaut " << status << endl; + return status; + } else { + if(execl("/bin/bash", "/bin/bash", "--noediting", "--noprofile", "--norc", deployscript.c_str(), (char *)0)==-1) + { + cerr << "Error in the execl call of " << deployscript << endl; + } + } + } + return 0; +} + +//public methods +int BashModule::prepare() +{ + return 0; +} + +int BashModule::deploy (string serviceUsername) +{ + cout << "deploy in bash module called" << endl; + executeScript(serviceUsername); + return 0; +} + + +int BashModule::remove (string serviceUsername) +{ + return 0; +} + +int BashModule::clean() +{ + return 0; +} diff --git a/src/BashModule.h b/src/BashModule.h new file mode 100644 index 0000000..9280f13 --- /dev/null +++ b/src/BashModule.h @@ -0,0 +1,23 @@ +// deployer BashModule header +// Copyright (C) 2024 Jean-Cloud +// GNU General Public License v3 + +#if !defined(BASHMODULE_H) +#define BASHMODULE_H + +#include "Module.h" + +class BashModule : public Module +{ + public: + BashModule(); + ~BashModule(){} //inline + int prepare (); + int deploy (string serviceUsername); + int remove(string serviceUsername); + int clean (); + private: + int executeScript(string serviceUsername); +}; + +#endif \ No newline at end of file diff --git a/src/Modules.h b/src/Modules.h index dad43b0..67c7176 100644 --- a/src/Modules.h +++ b/src/Modules.h @@ -1,8 +1,9 @@ #include #include -#include "Module.h" #include "DockerModule.h" +#include "BashModule.h" using namespace std; DockerModule dockerModule=DockerModule(); -vector modules={&dockerModule}; \ No newline at end of file +BashModule bashModule=BashModule(); +vector modules={&bashModule}; //&dockerModule \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index dda465d..8d1d981 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,12 +45,6 @@ int createEnv(string serviceUsername){ return 0; } -int runBashScripts(string serviceUsername){ - //TO DO - cout << "run bash scripts called" << endl; - return 0; -} - int deployAll(){ //this method deploys all the services that are on this server cout << "deploying all" < /dev/null && \ -apt-get -y update && \ -apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin CMD ["sh"] diff --git a/testenv/docker-compose.yaml b/testenv/docker-compose.yaml index 6a563cb..d1cd5d6 100644 --- a/testenv/docker-compose.yaml +++ b/testenv/docker-compose.yaml @@ -6,5 +6,7 @@ services: volumes: - .:/usr/src/deployer_test - ./test_hosts:/etc/hosts + - /var/run/docker.sock:/var/run/docker.sock stdin_open: true tty: true + privileged: true diff --git a/testenv/services/test.sh8s.sh/deploy.sh b/testenv/services/test.sh8s.sh/deploy.sh new file mode 100644 index 0000000..4f48e5e --- /dev/null +++ b/testenv/services/test.sh8s.sh/deploy.sh @@ -0,0 +1 @@ +touch done