diff --git a/src/DockerModule.cpp b/src/DockerModule.cpp index e99ca92..dbb475b 100644 --- a/src/DockerModule.cpp +++ b/src/DockerModule.cpp @@ -2,6 +2,7 @@ // Copyright (C) 2024 Jean-Cloud // GNU General Public License v3 +#include #include "DockerModule.h" #include "BashManager.h" @@ -19,19 +20,26 @@ int DockerModule::prepare() int DockerModule::deploy (string serviceUsername) { cout << "docker module deploy" << endl; - /* - //test if there is a docker compose + //test if there is a docker-compose.yml or docker-compose.yaml + string docker_compose="./services/"+serviceUsername+"/docker-compose.yml"; + if(!(filesystem::exists(docker_compose))){ + docker_compose="./services/"+serviceUsername+"/docker-compose.yaml"; + if(!(filesystem::exists(docker_compose))){ + cout << "No docker-compose for this service." << endl; + return 0; + } + } //pulling images int pulling =BashManager::execute("docker-compose pull")==0; if(pulling==0){ //starting service int starting=BashManager::execute("docker-compose up -d --remove-orphans"); }else{ - cerr << "Error in DockerModule deploying "<< serviceUsername << endl; + cerr << "Error in "<< name << "deploying "<< serviceUsername << endl; return -1; } - */ return 0; + } int removeContainersCreatedByDockerCompose() @@ -69,4 +77,4 @@ int DockerModule::remove (string serviceUsername) int DockerModule::clean() { return 0; -} \ No newline at end of file +} diff --git a/src/DockerModule.h b/src/DockerModule.h index 4aac63c..944b2f0 100644 --- a/src/DockerModule.h +++ b/src/DockerModule.h @@ -16,6 +16,5 @@ class DockerModule : public Module int deploy (string serviceUsername); int remove(string serviceUsername); int clean (); - string name; }; #endif \ No newline at end of file diff --git a/src/Makefile b/src/Makefile index d107cbd..191c354 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,4 +1,5 @@ ECHO = @echo +CP=@cp GCC = g++ RM = @rm -f CCFLAGS = -c -O3 -g -std=c++20 -pedantic -Wall @@ -11,6 +12,7 @@ LIBRARIES = -lstdc++fs $(EXE) : $(OBJECTS) $(ECHO) "-Linking $(EXE)-" $(GCC) -o $@ $^ $(LIBRARIES) + $(CP) $(EXE) ../testenv $(BIN)/%.o:%.cpp $(ECHO) "-Compilation $<- " diff --git a/src/main.cpp b/src/main.cpp index 04bb835..dda465d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,7 +24,7 @@ int isServiceOnServer(string serviceUsername) { string cmd ="getent hosts " +serviceUsername; string result = BashManager::executeAndReadResult(cmd); - if(result.find("::1")!=string::npos){ //if result contains "::1" + if(result.find("::1")!=string::npos){ //if result contains "::1" which is the notation for loopback in IpV6 cout << "service on server" << endl; return 0; } @@ -78,7 +78,7 @@ int deployService(string serviceUsername){ for(Module * mod_ptr : modules){ int modResult = (*mod_ptr).deploy(serviceUsername); if (modResult!=0){ - cerr << "Error in module " << (*mod_ptr) << " when deploying " << serviceUsername << endl; + cerr << "Error in " << (*mod_ptr) << " when deploying " << serviceUsername << endl; } } return 0; diff --git a/testenv/Dockerfile b/testenv/Dockerfile index b98344f..2cf6f30 100644 --- a/testenv/Dockerfile +++ b/testenv/Dockerfile @@ -1,4 +1,21 @@ -FROM ubuntu:latest +FROM ubuntu:22.04 WORKDIR /usr/src/deployer_test -CMD ["bash"] +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"] diff --git a/testenv/docker-compose.yaml b/testenv/docker-compose.yaml index 317baa7..6a563cb 100644 --- a/testenv/docker-compose.yaml +++ b/testenv/docker-compose.yaml @@ -1,6 +1,6 @@ services: deployer_test: - image: "ubuntu:latest" + image: "ubuntu:22.04" build: . container_name: deployer_test_container volumes: diff --git a/testenv/services/test.sh8s.sh/.env b/testenv/services/test.sh8s.sh/.env new file mode 100644 index 0000000..356f9a9 --- /dev/null +++ b/testenv/services/test.sh8s.sh/.env @@ -0,0 +1 @@ +GIT_SOURCE_REPO=https://git.jean-cloud.net/adrian/velov diff --git a/testenv/services/test.sh8s.sh/deploy_user.sh b/testenv/services/test.sh8s.sh/deploy_user.sh new file mode 100755 index 0000000..4fa8124 --- /dev/null +++ b/testenv/services/test.sh8s.sh/deploy_user.sh @@ -0,0 +1,3 @@ +#!/bin/bash +set -euo pipefail +git_update.sh -r -d "$HTTP_DIR" "$GIT_SOURCE_REPO" diff --git a/testenv/services/test.sh8s.sh/docker-compose.yml b/testenv/services/test.sh8s.sh/docker-compose.yml new file mode 100755 index 0000000..77a3f0f --- /dev/null +++ b/testenv/services/test.sh8s.sh/docker-compose.yml @@ -0,0 +1,22 @@ +version: '3' +services: + app: + image: php:7.2-fpm-alpine + volumes: + - $HTTP_DIR:/usr/src/app + restart: unless-stopped + networks: + default: + ipv4_address: $NET.100 + deploy: + resources: + limits: + cpus: '0.50' + memory: 100M + +networks: + default: + ipam: + config: + - subnet: $NET.0/24 + diff --git a/testenv/services/test.sh8s.sh/nginx_server.conf b/testenv/services/test.sh8s.sh/nginx_server.conf old mode 100644 new mode 100755 index e69de29..28d01f8 --- a/testenv/services/test.sh8s.sh/nginx_server.conf +++ b/testenv/services/test.sh8s.sh/nginx_server.conf @@ -0,0 +1,25 @@ +server { + listen 443 ssl http2; + listen [::]:443 ssl http2; + ssl_certificate $JC_CERT/fullchain.pem; + ssl_certificate_key $JC_CERT/privkey.pem; + server_name velov.jean-cloud.net www.velov.jean-cloud.net; + root $HTTP_DIR; + + index index.php; + + location / { + try_files $uri $uri/ =404; + } + + location ~ \.php$ { + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass $NET.100:9000; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME /usr/src/app/$fastcgi_script_name; + #fastcgi_param SCRIPT_FILENAME /usr/src/app/index.php; + fastcgi_param PATH_INFO $fastcgi_path_info; + } +} + diff --git a/testenv/test_hosts b/testenv/test_hosts index 8356928..2dffbe2 100644 --- a/testenv/test_hosts +++ b/testenv/test_hosts @@ -1,7 +1,10 @@ 127.0.0.1 localhost 127.0.1.1 example.net example +127.0.0.1 test.sh8s.sh # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback +::1 test.sh8s.sh ff02::1 ip6-allnodes ff02::2 ip6-allrouters +