Skip to content

Commit

Permalink
fix: use user setup folder path (#1710)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
vansangpfiev and sangjanai authored Nov 20, 2024
1 parent 027002f commit f5c3b02
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 45 deletions.
72 changes: 36 additions & 36 deletions .github/workflows/cortex-cpp-quality-gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 18 additions & 1 deletion engine/cli/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down
17 changes: 17 additions & 0 deletions engine/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 6 additions & 8 deletions engine/utils/file_manager_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -192,20 +195,15 @@ inline cpp::result<void, std::string> 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(
Expand Down

0 comments on commit f5c3b02

Please sign in to comment.