dockermodule created, module with isServiceOnServer in writing
This commit is contained in:
parent
45320747b5
commit
20a144eea1
BIN
bin/deployer
BIN
bin/deployer
Binary file not shown.
49
src/DockerModule.cpp
Normal file
49
src/DockerModule.cpp
Normal file
@ -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;
|
||||
}
|
20
src/DockerModule.h
Normal file
20
src/DockerModule.h
Normal file
@ -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
|
@ -2,8 +2,35 @@
|
||||
// Copyright (C) 2024 Jean-Cloud
|
||||
// GNU General Public License v3
|
||||
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
16
src/Module.h
16
src/Module.h
@ -6,16 +6,18 @@
|
||||
#define MODULE_H
|
||||
|
||||
#include <iostream>
|
||||
#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
|
@ -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<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: ";
|
||||
|
BIN
src/deployer
Executable file
BIN
src/deployer
Executable file
Binary file not shown.
14
src/main.cpp
14
src/main.cpp
@ -7,12 +7,13 @@
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include "Services.h"
|
||||
#include "Module.h"
|
||||
#include "DockerModule.h"
|
||||
using namespace std;
|
||||
|
||||
bool action_deploy=false;
|
||||
bool action_remove=false;
|
||||
bool all=false;
|
||||
//list<Module> 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"<<endl;
|
||||
}else{
|
||||
cout << "service found" << endl;
|
||||
cout << *ptr_myService << endl;
|
||||
}
|
||||
|
||||
DockerModule dmodule;
|
||||
dmodule.isserviceOnServer();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user