Compare commits
No commits in common. "20a144eea151815f2023c2b2caaa5b0b235a0fe6" and "d81176ffa6bacba6c2ed9dbd405bccd9ec5bfcea" have entirely different histories.
20a144eea1
...
d81176ffa6
BIN
bin/deployer
BIN
bin/deployer
Binary file not shown.
@ -1,49 +0,0 @@
|
|||||||
// 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;
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
// 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
|
|
12
src/Makefile
12
src/Makefile
@ -2,15 +2,15 @@ ECHO = @echo
|
|||||||
GCC = g++
|
GCC = g++
|
||||||
RM = @rm -f
|
RM = @rm -f
|
||||||
CCFLAGS = -c -O3 -g -std=c++11 -pedantic -Wall
|
CCFLAGS = -c -O3 -g -std=c++11 -pedantic -Wall
|
||||||
|
OBJETS = $(SRC:.cpp=.o)
|
||||||
SRC = $(wildcard *.cpp)
|
SRC = $(wildcard *.cpp)
|
||||||
BIN = ../bin
|
|
||||||
EXE = deployer
|
EXE = deployer
|
||||||
OBJECTS = $(patsubst %.cpp,$(BIN)/%.o,$(SRC))
|
BIN = ../bin
|
||||||
|
OBJETS_DIR = $(OBJETS:%=$(BIN)/%)
|
||||||
|
EXE_DIR = $(EXE:%=$(BIN)/%)
|
||||||
LIBRARIES =
|
LIBRARIES =
|
||||||
|
|
||||||
$(EXE) : $(OBJECTS)
|
$(EXE_DIR) : $(OBJETS_DIR)
|
||||||
$(ECHO) "objects $(OBJECTS) exe $(EXE) "
|
|
||||||
|
|
||||||
$(ECHO) "-Linking $(EXE)-"
|
$(ECHO) "-Linking $(EXE)-"
|
||||||
$(GCC) -o $@ $^ $(LIBRARIES)
|
$(GCC) -o $@ $^ $(LIBRARIES)
|
||||||
|
|
||||||
@ -21,4 +21,4 @@ $(BIN)/%.o:%.cpp
|
|||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
$(ECHO) "-Cleaning-"
|
$(ECHO) "-Cleaning-"
|
||||||
$(RM) $(OBJECTS) $(EXE)
|
$(RM) $(OBJETS) $(EXE)
|
@ -2,35 +2,9 @@
|
|||||||
// Copyright (C) 2024 Jean-Cloud
|
// Copyright (C) 2024 Jean-Cloud
|
||||||
// GNU General Public License v3
|
// GNU General Public License v3
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include "Module.h"
|
#include "Module.h"
|
||||||
|
|
||||||
//constructor inline
|
Module::Module(char * serv):service(serv){}
|
||||||
//destructor, could not be inline because pure virtual
|
|
||||||
Module::~Module(){}
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
18
src/Module.h
18
src/Module.h
@ -6,18 +6,16 @@
|
|||||||
#define MODULE_H
|
#define MODULE_H
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "Service.h"
|
|
||||||
|
|
||||||
class Module
|
class Module
|
||||||
{
|
{
|
||||||
public:
|
protected:
|
||||||
Module(){};
|
Module(char * serv);
|
||||||
//=0 means pure virtual method, making Module a pure virtual class
|
virtual ~Module();
|
||||||
virtual ~Module()=0; //make protected to ensure it is not used externally?
|
|
||||||
virtual int prepare ()=0;
|
private:
|
||||||
virtual int deploy (Service service)=0;
|
bool activated; //true if the service requires this module
|
||||||
virtual int clean ()=0;
|
char * service;
|
||||||
//protected: commented for test purposes
|
|
||||||
virtual int isserviceOnServer();
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
@ -1,31 +0,0 @@
|
|||||||
//deployer Service implementation
|
|
||||||
// Copyright (C) 2024 Jean-Cloud
|
|
||||||
// GNU General Public License v3
|
|
||||||
|
|
||||||
#include "Service.h"
|
|
||||||
|
|
||||||
//constructor and destructor defined inline
|
|
||||||
|
|
||||||
//public methods
|
|
||||||
int Service::getUserID () const
|
|
||||||
{
|
|
||||||
return userID;
|
|
||||||
}
|
|
||||||
string Service::getUsername() const
|
|
||||||
{
|
|
||||||
return username;
|
|
||||||
}
|
|
||||||
list<string> Service::getServers() const
|
|
||||||
{
|
|
||||||
return servers;
|
|
||||||
}
|
|
||||||
|
|
||||||
//operator << override
|
|
||||||
ostream & operator << (ostream & out, const Service & s)
|
|
||||||
{
|
|
||||||
out << "userID: " << s.userID << endl << "username: " << s.username << endl << "servers: ";
|
|
||||||
for (string server : s.servers){
|
|
||||||
out << server << " " << endl;
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
//deployer Service header
|
|
||||||
// Copyright (C) 2024 Jean-Cloud
|
|
||||||
// GNU General Public License v3
|
|
||||||
|
|
||||||
#if !defined(SERVICE_H)
|
|
||||||
#define SERVICE_H
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
#include <string>
|
|
||||||
#include <list>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
class Service {
|
|
||||||
public:
|
|
||||||
Service(int aUserID, string aUsername, list <string> aServers):userID(aUserID),username(aUsername),servers(aServers){}
|
|
||||||
~Service(){}
|
|
||||||
int getUserID () const;
|
|
||||||
string getUsername() const;
|
|
||||||
list<string> getServers() const;
|
|
||||||
friend ostream & operator<<(ostream & out, const Service & s);
|
|
||||||
private:
|
|
||||||
int userID;
|
|
||||||
string username;
|
|
||||||
list <string> servers;
|
|
||||||
};
|
|
||||||
#endif
|
|
@ -9,59 +9,18 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include "Services.h"
|
#include "Services.h"
|
||||||
|
|
||||||
//constructor
|
|
||||||
Services::Services(string ServicesCSV)
|
Services::Services(string ServicesCSV)
|
||||||
{
|
{
|
||||||
services=readServicesFromCSV(ServicesCSV);
|
services=readServicesFromCSV(ServicesCSV);
|
||||||
}
|
}
|
||||||
//destructor
|
|
||||||
Services::~Services(){}
|
Services::~Services(){}
|
||||||
|
|
||||||
//public methods
|
|
||||||
vector<Service> Services::getServices()const
|
|
||||||
{
|
|
||||||
return services;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Service* Services::findByUsername(string aUsername) const
|
vector <serviceData> Services::readServicesFromCSV (string CSV) const
|
||||||
{
|
|
||||||
for (const Service & service : services){
|
|
||||||
if (service.getUsername().compare(aUsername)==0){
|
|
||||||
return &service;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Service * Services::findByID(int aUserID) const
|
|
||||||
{
|
|
||||||
for (const Service & service : services){
|
|
||||||
if (service.getUserID()==aUserID){
|
|
||||||
return &service;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
list<const Service*> Services::findByServer(string aServer) const
|
|
||||||
{
|
|
||||||
list<const Service*> result;
|
|
||||||
for (const Service & service : services){
|
|
||||||
for (string server : service.getServers()){
|
|
||||||
if(server.compare(aServer)==0){
|
|
||||||
result.push_back(&service);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//private methods
|
|
||||||
vector <Service> Services::readServicesFromCSV (string CSV) const
|
|
||||||
{
|
{
|
||||||
//this method extracts the list of uid|username|servers from the services.csv file
|
//this method extracts the list of uid|username|servers from the services.csv file
|
||||||
//and returns them in a vector <Service>, with Service a structure defined in the header
|
//and returns them in a vector <serviceData>, with serviceData a structure defined in the header
|
||||||
vector <Service> result;
|
vector <serviceData> result;
|
||||||
ifstream streamServices(CSV);
|
ifstream streamServices(CSV);
|
||||||
if (!streamServices){
|
if (!streamServices){
|
||||||
cout << "Invalid services.csv file." << endl;
|
cout << "Invalid services.csv file." << endl;
|
||||||
@ -70,8 +29,8 @@ vector <Service> Services::readServicesFromCSV (string CSV) const
|
|||||||
string tmpUserID; //used before converting to int
|
string tmpUserID; //used before converting to int
|
||||||
int userID;
|
int userID;
|
||||||
string username;
|
string username;
|
||||||
string server;
|
string serveur;
|
||||||
list <string> servers;
|
list <string> serveurs;
|
||||||
while(getline(streamServices,line)){
|
while(getline(streamServices,line)){
|
||||||
if (line.empty() || line[0] == '#') { //not taking comments and empty lines into account
|
if (line.empty() || line[0] == '#') { //not taking comments and empty lines into account
|
||||||
continue;
|
continue;
|
||||||
@ -80,13 +39,12 @@ vector <Service> Services::readServicesFromCSV (string CSV) const
|
|||||||
getline(streamLine,tmpUserID,';'); //extracting the userID
|
getline(streamLine,tmpUserID,';'); //extracting the userID
|
||||||
userID=stoi(tmpUserID);
|
userID=stoi(tmpUserID);
|
||||||
getline(streamLine,username,';'); //extracting the username
|
getline(streamLine,username,';'); //extracting the username
|
||||||
while(getline(streamLine,server,';')){ //extracting the server(s)
|
while(getline(streamLine,serveur,';')){ //extracting the server(s)
|
||||||
servers.push_back(server);
|
serveurs.push_back(serveur);
|
||||||
}
|
}
|
||||||
Service entry = {userID,username,servers};
|
serviceData entry = {userID,username,serveurs};
|
||||||
result.push_back(entry);
|
result.push_back(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,23 +9,24 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "Service.h"
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
struct serviceData {
|
||||||
|
int userID;
|
||||||
|
string username;
|
||||||
|
list <string> serveurs;
|
||||||
|
};
|
||||||
|
|
||||||
class Services
|
class Services
|
||||||
//extracts the list of uid|username|service from the services.csv file
|
//extracts the list of uid|username|service from the services.csv file
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Services(string servicesCSV="../src/services.csv");
|
Services(string servicesCSV="../src/services.csv");
|
||||||
vector<Service> getServices() const;
|
|
||||||
const Service * findByUsername(string aUsername) const;
|
|
||||||
const Service * findByID(int aUserID) const;
|
|
||||||
list<const Service*> findByServer(string aServer) const;
|
|
||||||
~Services();
|
~Services();
|
||||||
private:
|
private:
|
||||||
vector <Service> readServicesFromCSV (string CSV) const;
|
vector <serviceData> readServicesFromCSV (string CSV) const;
|
||||||
vector <Service> services;
|
vector <serviceData> services;
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
BIN
src/deployer
BIN
src/deployer
Binary file not shown.
@ -7,13 +7,12 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include "Services.h"
|
#include "Services.h"
|
||||||
#include "DockerModule.h"
|
#include "Module.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
bool action_deploy=false;
|
bool action_deploy=false;
|
||||||
bool action_remove=false;
|
bool action_remove=false;
|
||||||
bool all=false;
|
bool all=false;
|
||||||
//list<Module> modules;
|
|
||||||
|
|
||||||
void help()
|
void help()
|
||||||
{
|
{
|
||||||
@ -37,9 +36,8 @@ int main(int argc, char *argv[])
|
|||||||
cout << "Invalid argument. \n" << endl;
|
cout << "Invalid argument. \n" << endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
Services myServices=Services("../src/services.csv");
|
||||||
|
|
||||||
DockerModule dmodule;
|
|
||||||
dmodule.isserviceOnServer();
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user