diff --git a/src/NginxModule.cpp b/src/NginxModule.cpp index 6b71cc9..32c08cb 100644 --- a/src/NginxModule.cpp +++ b/src/NginxModule.cpp @@ -4,6 +4,7 @@ #include #include +#include "BashManager.h" #include "NginxModule.h" using namespace std; namespace fs=filesystem; @@ -62,21 +63,17 @@ int NginxModule::Deploy (string serviceUsername) //copy the conf from the service directory to the nginx directory string conf="./services/"+serviceUsername+"/nginx_server.conf"; string new_nginx_conf_path=getenv("NEW_NGINX_CONF_PATH"); + //nginx dir + fs::create_directories(new_nginx_conf_path + "/" + serviceUsername); + fs::copy(conf,new_nginx_conf_path+"/"+serviceUsername); + string newConf=new_nginx_conf_path + "/" + serviceUsername + "/nginx_server.conf"; //replace the environment variables with their values - //string cmd="set -a && envsubst "+conf; - - /* - -if [ -f "/docker/$service/nginx_server.conf" ] ; then - section "Copy nginx conf" - run cp "/docker/$service/nginx_server.conf" "$new_nginx_conf_path/$service" - - section "Template nginx conf with vars from '.env' file" - run template.sh "/docker/$service/.env" < "/docker/$service/nginx_server.conf" > "$new_nginx_conf_path/ - (template : bash -c 'set -a && . '"$1"' && envsubst "$(cat '"$1"' | grep -o ^.*= | sed "s/=//" | sed "s/^/$/")"') - $service" -fi*/ + string cmd="envsubst < "+ conf + " > " + newConf; + BashManager::Execute(cmd); + //test new conf + //cmd = "nginx -t -c /etc/nginx/new_nginx.conf && echo $?" + //string res = BashManager return 0; } diff --git a/src/main.cpp b/src/main.cpp index cf26883..e524bc7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -187,7 +187,7 @@ int createEnvService(string serviceUsername) cerr << "Error changing ownership of" << secret_dir << endl; return -1; } - fs::permissions(secret_dir,fs::perms::owner_all|fs::perms::group_read|fs::perms::group_exec|fs::perms::others_exec,fs::perm_options::replace); + fs::permissions(secret_dir,fs::perms::owner_all|fs::perms::group_read|fs::perms::group_exec|fs::perms::others_exec,fs::perm_options::replace); cout << "service " << serviceUsername << " environment created" << endl; return 0; } diff --git a/testenv/Dockerfile b/testenv/Dockerfile index bb6bd52..7a848cf 100644 --- a/testenv/Dockerfile +++ b/testenv/Dockerfile @@ -2,5 +2,6 @@ FROM ubuntu:22.04 WORKDIR /usr/src/deployer_test RUN mkdir -p etc/nginx /etc/nginx/sites-enabled /etc/nginx/new-sites-enabled /data/dnscerts.jean-cloud.org/certs/live/ /etc/letsencrypt/live RUN touch /etc/letsencrypt/live/dummy +#RUN apt-get install gettext-base CMD ["sh"]