Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use user setup folder path #1710

Merged
merged 4 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading