docker ne s'installe pas dans le conteneur docker de test

This commit is contained in:
eleonore12345 2024-08-08 16:20:41 +02:00
parent 278bcec45f
commit d7d7b08c15
11 changed files with 91 additions and 11 deletions

View File

@ -2,6 +2,7 @@
// Copyright (C) 2024 Jean-Cloud
// GNU General Public License v3
#include <filesystem>
#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;
}
}

View File

@ -16,6 +16,5 @@ class DockerModule : public Module
int deploy (string serviceUsername);
int remove(string serviceUsername);
int clean ();
string name;
};
#endif

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
services:
deployer_test:
image: "ubuntu:latest"
image: "ubuntu:22.04"
build: .
container_name: deployer_test_container
volumes:

View File

@ -0,0 +1 @@
GIT_SOURCE_REPO=https://git.jean-cloud.net/adrian/velov

View File

@ -0,0 +1,3 @@
#!/bin/bash
set -euo pipefail
git_update.sh -r -d "$HTTP_DIR" "$GIT_SOURCE_REPO"

View File

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

25
testenv/services/test.sh8s.sh/nginx_server.conf Normal file → Executable file
View File

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

View File

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