From f5c3b028904ed817588559643f243fc2a11105cb Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Wed, 20 Nov 2024 11:22:58 +0700 Subject: [PATCH] fix: use user setup folder path (#1710) * fix: use user setup folder path * chore: disable docker test * fix: override data folder path if it is configured * fix: CI --------- Co-authored-by: vansangpfiev --- .github/workflows/cortex-cpp-quality-gate.yml | 72 +++++++++---------- engine/cli/main.cc | 19 ++++- engine/main.cc | 17 +++++ engine/utils/file_manager_utils.h | 14 ++-- 4 files changed, 77 insertions(+), 45 deletions(-) diff --git a/.github/workflows/cortex-cpp-quality-gate.yml b/.github/workflows/cortex-cpp-quality-gate.yml index 3c9eea724..85050581a 100644 --- a/.github/workflows/cortex-cpp-quality-gate.yml +++ b/.github/workflows/cortex-cpp-quality-gate.yml @@ -188,40 +188,40 @@ jobs: AWS_SECRET_ACCESS_KEY: "${{ secrets.MINIO_SECRET_ACCESS_KEY }}" AWS_DEFAULT_REGION: "${{ secrets.MINIO_REGION }}" - build-docker-and-test: - runs-on: ubuntu-latest - steps: - - name: Getting the repo - uses: actions/checkout@v3 - with: - submodules: 'recursive' - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 + # build-docker-and-test: + # runs-on: ubuntu-latest + # steps: + # - name: Getting the repo + # uses: actions/checkout@v3 + # with: + # submodules: 'recursive' + + # - name: Set up QEMU + # uses: docker/setup-qemu-action@v3 + + # - name: Set up Docker Buildx + # uses: docker/setup-buildx-action@v3 - - name: Run Docker - run: | - docker build -t menloltd/cortex:test -f docker/Dockerfile . - docker run -it -d -p 3928:39281 --name cortex menloltd/cortex:test - - - name: use python - uses: actions/setup-python@v5 - with: - python-version: "3.10" - - - name: Run e2e tests - run: | - cd engine - python -m pip install --upgrade pip - python -m pip install -r e2e-test/requirements.txt - pytest e2e-test/test_api_docker.py - - - name: Run Docker - continue-on-error: true - if: always() - run: | - docker stop cortex - docker rm cortex + # - name: Run Docker + # run: | + # docker build -t menloltd/cortex:test -f docker/Dockerfile . + # docker run -it -d -p 3928:39281 --name cortex menloltd/cortex:test + + # - name: use python + # uses: actions/setup-python@v5 + # with: + # python-version: "3.10" + + # - name: Run e2e tests + # run: | + # cd engine + # python -m pip install --upgrade pip + # python -m pip install -r e2e-test/requirements.txt + # pytest e2e-test/test_api_docker.py + + # - name: Run Docker + # continue-on-error: true + # if: always() + # run: | + # docker stop cortex + # docker rm cortex diff --git a/engine/cli/main.cc b/engine/cli/main.cc index ed3b1680f..49cdf4be9 100644 --- a/engine/cli/main.cc +++ b/engine/cli/main.cc @@ -97,6 +97,23 @@ int main(int argc, char* argv[]) { if (result.has_error()) { CTL_ERR("Error creating config file: " << result.error()); } + namespace fmu = file_manager_utils; + // Override data folder path if it is configured and changed + if (!fmu::cortex_data_folder_path.empty()) { + auto cfg = file_manager_utils::GetCortexConfig(); + if (cfg.dataFolderPath != fmu::cortex_data_folder_path || + cfg.logFolderPath != fmu::cortex_data_folder_path) { + cfg.dataFolderPath = fmu::cortex_data_folder_path; + cfg.logFolderPath = fmu::cortex_data_folder_path; + auto config_path = file_manager_utils::GetConfigurationPath(); + auto result = + config_yaml_utils::CortexConfigMgr::GetInstance().DumpYamlConfig( + cfg, config_path.string()); + if (result.has_error()) { + CTL_ERR("Error update " << config_path.string() << result.error()); + } + } + } } RemoveBinaryTempFileIfExists(); @@ -164,7 +181,7 @@ int main(int argc, char* argv[]) { t1.detach(); } - trantor::FileLogger async_file_logger; + static trantor::FileLogger async_file_logger; SetupLogger(async_file_logger, verbose); if (should_install_server) { diff --git a/engine/main.cc b/engine/main.cc index 56f66154e..4b95785bb 100644 --- a/engine/main.cc +++ b/engine/main.cc @@ -225,6 +225,23 @@ int main(int argc, char* argv[]) { if (result.has_error()) { LOG_ERROR << "Error creating config file: " << result.error(); } + namespace fmu = file_manager_utils; + // Override data folder path if it is configured and changed + if (!fmu::cortex_data_folder_path.empty()) { + auto cfg = file_manager_utils::GetCortexConfig(); + if (cfg.dataFolderPath != fmu::cortex_data_folder_path || + cfg.logFolderPath != fmu::cortex_data_folder_path) { + cfg.dataFolderPath = fmu::cortex_data_folder_path; + cfg.logFolderPath = fmu::cortex_data_folder_path; + auto config_path = file_manager_utils::GetConfigurationPath(); + auto result = + config_yaml_utils::CortexConfigMgr::GetInstance().DumpYamlConfig( + cfg, config_path.string()); + if (result.has_error()) { + CTL_ERR("Error update " << config_path.string() << result.error()); + } + } + } } // Delete temporary file if it exists diff --git a/engine/utils/file_manager_utils.h b/engine/utils/file_manager_utils.h index e8b69869e..399afcfa6 100644 --- a/engine/utils/file_manager_utils.h +++ b/engine/utils/file_manager_utils.h @@ -156,7 +156,10 @@ inline config_yaml_utils::CortexConfig GetDefaultConfig() { auto config_path = GetConfigurationPath(); auto default_data_folder_name = GetDefaultDataFolderName(); auto default_data_folder_path = - file_manager_utils::GetHomeDirectoryPath() / default_data_folder_name; + cortex_data_folder_path.empty() + ? file_manager_utils::GetHomeDirectoryPath() / + default_data_folder_name + : std::filesystem::path(cortex_data_folder_path); return config_yaml_utils::CortexConfig{ .logFolderPath = default_data_folder_path.string(), @@ -192,20 +195,15 @@ inline cpp::result CreateConfigFileIfNotExist() { return {}; } - auto default_data_folder_name = GetDefaultDataFolderName(); - CLI_LOG("Config file not found. Creating one at " + config_path.string()); auto config = GetDefaultConfig(); CLI_LOG("Default data folder path: " + config.dataFolderPath); - return cyu::CortexConfigMgr::GetInstance().DumpYamlConfig(config, - config_path.string()); + return cyu::CortexConfigMgr::GetInstance().DumpYamlConfig( + config, config_path.string()); } inline config_yaml_utils::CortexConfig GetCortexConfig() { auto config_path = GetConfigurationPath(); - auto default_data_folder_name = GetDefaultDataFolderName(); - auto default_data_folder_path = - file_manager_utils::GetHomeDirectoryPath() / default_data_folder_name; auto default_cfg = GetDefaultConfig(); return config_yaml_utils::CortexConfigMgr::GetInstance().FromYaml(