bash module with deploy.sh implemented, not deploy as yet
This commit is contained in:
parent
d7d7b08c15
commit
4ac02da07c
@ -31,4 +31,4 @@ string BashManager::executeAndReadResult(string command)
|
||||
}
|
||||
pclose(p);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
70
src/BashModule.cpp
Normal file
70
src/BashModule.cpp
Normal 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
23
src/BashModule.h
Normal 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
|
@ -1,8 +1,9 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "Module.h"
|
||||
#include "DockerModule.h"
|
||||
#include "BashModule.h"
|
||||
|
||||
using namespace std;
|
||||
DockerModule dockerModule=DockerModule();
|
||||
vector <Module *> modules={&dockerModule};
|
||||
BashModule bashModule=BashModule();
|
||||
vector <Module *> modules={&bashModule}; //&dockerModule
|
10
src/main.cpp
10
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" <<endl;
|
||||
@ -69,10 +63,6 @@ int deployService(string serviceUsername){
|
||||
if(int envCreated = createEnv(serviceUsername);envCreated!=0){
|
||||
return -1;
|
||||
}
|
||||
//bash scripts call
|
||||
if(int bashScriptsRun = runBashScripts(serviceUsername);bashScriptsRun!=0){
|
||||
return -1;
|
||||
}
|
||||
//call to the deploy functionality of all modules
|
||||
//the modules themselves determine their course of action depending on the service
|
||||
for(Module * mod_ptr : modules){
|
||||
|
@ -1,21 +1,4 @@
|
||||
FROM ubuntu:22.04
|
||||
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"]
|
||||
|
||||
|
@ -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
|
||||
|
1
testenv/services/test.sh8s.sh/deploy.sh
Normal file
1
testenv/services/test.sh8s.sh/deploy.sh
Normal file
@ -0,0 +1 @@
|
||||
touch done
|
Loading…
Reference in New Issue
Block a user