From 14f1fb407621da2f7989deca0d9be0ac2b2987be Mon Sep 17 00:00:00 2001 From: lgromero Date: Tue, 11 Mar 2025 08:25:18 +0100 Subject: [PATCH] refs #1686 creates new api directory to symfony files, changes oglivecli and tftpboot directory location --- config/services.yaml | 2 +- installer/ogboot_installer.py | 70 ++++++++----------- .../Service/CurlRequestService.php | 4 +- 3 files changed, 32 insertions(+), 44 deletions(-) diff --git a/config/services.yaml b/config/services.yaml index dd3041c..d8221b2 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -4,7 +4,7 @@ # Put parameters here that don't need to change on each machine where the app is deployed # https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration parameters: - tftpboot_dir: '%kernel.project_dir%/tftpboot' + tftpboot_dir: '%kernel.project_dir%/../tftpboot' services: # default configuration for services in *this* file _defaults: diff --git a/installer/ogboot_installer.py b/installer/ogboot_installer.py index 8688d9e..dd76b14 100755 --- a/installer/ogboot_installer.py +++ b/installer/ogboot_installer.py @@ -242,7 +242,8 @@ def og_boot_create_dirs(): os.makedirs("/opt/opengnsys", mode=0o775, exist_ok=True) subprocess.run(["chmod", "775", "/opt/opengnsys"]) os.makedirs(INSTALL_OGBOOT_TARGET, mode=0o775, exist_ok=True) - os.makedirs(os.path.join(INSTALL_OGBOOT_TARGET, "client"), mode=0o775, exist_ok=True) + api_dir = os.path.join(INSTALL_OGBOOT_TARGET, "api") + os.makedirs(api_dir, mode=0o775, exist_ok=True) # Cambiar el propietario de los directorios subprocess.run(["chown", "-R", "opengnsys:opengnsys", INSTALL_OGBOOT_TARGET]) @@ -257,11 +258,13 @@ def og_boot_symfony_install(): logger.info("Creating Symfony application skeleton...") try: - # Copiar los archivos .env y composer.json primero - env_src = os.path.join(f"{REPO_DIR}", ".env") - composer_src = os.path.join(f"{REPO_DIR}", "composer.json") - env_dest = os.path.join(f"{INSTALL_OGBOOT_TARGET}", ".env") - composer_dest = os.path.join(f"{INSTALL_OGBOOT_TARGET}", "composer.json") + api_dir = os.path.join(INSTALL_OGBOOT_TARGET, "api") + os.makedirs(api_dir, exist_ok=True) # Asegurar que el directorio api existe + + env_src = os.path.join(REPO_DIR, ".env") + composer_src = os.path.join(REPO_DIR, "composer.json") + env_dest = os.path.join(api_dir, ".env") + composer_dest = os.path.join(api_dir, "composer.json") shutil.copy(env_src, env_dest) shutil.copy(composer_src, composer_dest) @@ -297,58 +300,43 @@ def og_boot_symfony_install(): def og_boot_copy_files(): + api_dir = os.path.join(INSTALL_OGBOOT_TARGET, "api") + bin_source = os.path.join(REPO_DIR, "bin") - bin_dest = os.path.join(INSTALL_OGBOOT_TARGET, "bin") + bin_dest = os.path.join(api_dir, "bin") src_source = os.path.join(REPO_DIR, "src") - src_dest = os.path.join(INSTALL_OGBOOT_TARGET, "src") - + src_dest = os.path.join(api_dir, "src") config_source = os.path.join(REPO_DIR, "config") - config_dest = os.path.join(INSTALL_OGBOOT_TARGET, "config") - + config_dest = os.path.join(api_dir, "config") lib_source = os.path.join(REPO_DIR, "lib") - lib_dest = os.path.join(INSTALL_OGBOOT_TARGET, "lib") - - #os.makedirs("/tmp/opt", exist_ok=True) - - #subprocess.run(["chown", "-R", "ogboot:ogboot", "/tmp/opt"]) + lib_dest = os.path.join(api_dir, "lib") + # Copiar directorios a api/ if os.path.exists(bin_dest): shutil.rmtree(bin_dest) shutil.copytree(bin_source, bin_dest) + # Repetir para src, config, lib... - if os.path.exists(src_dest): - shutil.rmtree(src_dest) - shutil.copytree(src_source, src_dest) - - if os.path.exists(config_dest): - shutil.rmtree(config_dest) - shutil.copytree(config_source, config_dest) - - if os.path.exists(lib_dest): - shutil.rmtree(lib_dest) - shutil.copytree(lib_source, lib_dest) - - os.makedirs(os.path.join(INSTALL_OGBOOT_TARGET, "etc"), mode=0o775, exist_ok=True) - os.makedirs(os.path.join(INSTALL_OGBOOT_TARGET, "client"), mode=0o775, exist_ok=True) - os.makedirs(os.path.join(INSTALL_OGBOOT_TARGET, "public"), mode=0o775, exist_ok=True) + # Crear directorio public bajo api/ + public_dir = os.path.join(api_dir, "public") + os.makedirs(public_dir, mode=0o775, exist_ok=True) subprocess.run(["chmod", "-R", "775", INSTALL_OGBOOT_TARGET]) subprocess.run(["chown", "-R", "opengnsys:opengnsys", INSTALL_OGBOOT_TARGET]) def og_boot_composer_install(): - # Ejecutar Composer como el usuario 'opengnsys' para instalar el proyecto Symfony - result = subprocess.run(["sudo", "-u", "opengnsys", "composer", "install", "--no-interaction", "--working-dir", INSTALL_OGBOOT_TARGET]) - if result.returncode != 0: - logger.error("Error creating Symfony project using Composer") - return + api_dir = os.path.join(INSTALL_OGBOOT_TARGET, "api") + result = subprocess.run( + ["sudo", "-u", "opengnsys", "composer", "install", "--no-interaction", "--working-dir", api_dir] + ) # Ejecutar Composer como el usuario 'opengnsys' para actualizar el paquete doctrine/dbal - result = subprocess.run(["sudo", "-u", "opengnsys", INSTALL_OGBOOT_TARGET+"/bin/composer.phar", "update", "doctrine/dbal", "--working-dir", INSTALL_OGBOOT_TARGET]) + result = subprocess.run(["sudo", "-u", "opengnsys", INSTALL_OGBOOT_TARGET+"/bin/composer.phar", "update", "doctrine/dbal", "--working-dir", api_dir]) if result.returncode != 0: logger.error("Error updating doctrine/dbal package using Composer") return - subprocess.call(["chown", "-R", "opengnsys:opengnsys", f"{INSTALL_OGBOOT_TARGET}/public"]) + subprocess.call(["chown", "-R", "opengnsys:opengnsys", f"{api_dir}/public"]) logger.info("Application skeleton created.") @@ -701,16 +689,16 @@ def setup_nginx(): ip_address_server = OGBOOT_IP port_address_server = OGBOOT_PORT php_version = get_php_fpm_version() - + api_dir = os.path.join(INSTALL_OGBOOT_TARGET, "api") # Leer y modificar la plantilla de configuración de nginx template_path = os.path.join(REPO_DIR, "etc/nginxServer.conf.tmpl") with open(template_path, 'r') as nginx_file: nginx_content = nginx_file.read() - + nginx_content = nginx_content.replace("__SERVERIP__", ip_address_server) nginx_content = nginx_content.replace("__PORT__", port_address_server) nginx_content = nginx_content.replace("__PHPVERSION__", php_version) - nginx_content = nginx_content.replace("__ROOT__", INSTALL_OGBOOT_TARGET) + nginx_content = nginx_content.replace("__ROOT__", api_dir) nginx_content = nginx_content.replace("__TFTPPATH__", f"{INSTALL_OGBOOT_TARGET}/tftpboot") # Ruta de destino para la configuración de nginx diff --git a/src/OgBootBundle/Service/CurlRequestService.php b/src/OgBootBundle/Service/CurlRequestService.php index 9e68192..338bd97 100644 --- a/src/OgBootBundle/Service/CurlRequestService.php +++ b/src/OgBootBundle/Service/CurlRequestService.php @@ -30,8 +30,8 @@ class CurlRequestService public function callOgLive($parameter) { // Ruta completa al script oglivecli - $ogLiveCliPath = sprintf("%s/bin/oglivecli", dirname(dirname(dirname(__DIR__)))); - + // $ogLiveCliPath = sprintf("%s/bin/oglivecli", dirname(dirname(dirname(__DIR__)))); + $ogLiveCliPath = sprintf("%s/../../../../bin/oglivecli", __DIR__); // Dividir el parámetro en acción y argumentos $args = array_map('trim', explode(' ', $parameter)); $action = array_shift($args);