bash module with deploy.sh implemented, not deploy as yet

This commit is contained in:
eleonore12345 2024-08-09 11:34:42 +02:00
parent d7d7b08c15
commit 4ac02da07c
8 changed files with 100 additions and 30 deletions

70
src/BashModule.cpp Normal file
View File

@ -0,0 +1,70 @@
// deployer BashModule implementation
// Copyright (C) 2024 Jean-Cloud
// GNU General Public License v3
#include <filesystem>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#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;
}

23
src/BashModule.h Normal file
View File

@ -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

View File

@ -1,8 +1,9 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include "Module.h"
#include "DockerModule.h" #include "DockerModule.h"
#include "BashModule.h"
using namespace std; using namespace std;
DockerModule dockerModule=DockerModule(); DockerModule dockerModule=DockerModule();
vector <Module *> modules={&dockerModule}; BashModule bashModule=BashModule();
vector <Module *> modules={&bashModule}; //&dockerModule

View File

@ -45,12 +45,6 @@ int createEnv(string serviceUsername){
return 0; return 0;
} }
int runBashScripts(string serviceUsername){
//TO DO
cout << "run bash scripts called" << endl;
return 0;
}
int deployAll(){ int deployAll(){
//this method deploys all the services that are on this server //this method deploys all the services that are on this server
cout << "deploying all" <<endl; cout << "deploying all" <<endl;
@ -69,10 +63,6 @@ int deployService(string serviceUsername){
if(int envCreated = createEnv(serviceUsername);envCreated!=0){ if(int envCreated = createEnv(serviceUsername);envCreated!=0){
return -1; return -1;
} }
//bash scripts call
if(int bashScriptsRun = runBashScripts(serviceUsername);bashScriptsRun!=0){
return -1;
}
//call to the deploy functionality of all modules //call to the deploy functionality of all modules
//the modules themselves determine their course of action depending on the service //the modules themselves determine their course of action depending on the service
for(Module * mod_ptr : modules){ for(Module * mod_ptr : modules){

View File

@ -1,21 +1,4 @@
FROM ubuntu:22.04 FROM ubuntu:22.04
WORKDIR /usr/src/deployer_test WORKDIR /usr/src/deployer_test
RUN mkdir -p /data/mounted && \
apt-get -y update && apt-get install -y \
ca-certificates \
curl \
gnupg \
lsb-release &&\
apt-get -y update &&\
apt-get -y install ca-certificates curl && \
install -m 0755 -d /etc/apt/keyrings && \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc && \
chmod a+r /etc/apt/keyrings/docker.asc && \
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
tee /etc/apt/sources.list.d/docker.list > /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"] CMD ["sh"]

View File

@ -6,5 +6,7 @@ services:
volumes: volumes:
- .:/usr/src/deployer_test - .:/usr/src/deployer_test
- ./test_hosts:/etc/hosts - ./test_hosts:/etc/hosts
- /var/run/docker.sock:/var/run/docker.sock
stdin_open: true stdin_open: true
tty: true tty: true
privileged: true

View File

@ -0,0 +1 @@
touch done