Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
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
8 changes: 5 additions & 3 deletions engine/commands/cortex_upd_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ bool CortexUpdCmd::GetStableAndBeta(const std::string& v) {

// Replace binary file
auto executable_path = file_manager_utils::GetExecutableFolderContainerPath();
auto src = executable_path / "cortex" / kCortexBinary / GetCortexBinary();
auto src = std::filesystem::temp_directory_path() / "cortex" / kCortexBinary /
GetCortexBinary();
auto dst = executable_path / GetCortexBinary();
return ReplaceBinaryInflight(src, dst);
}
Expand All @@ -159,7 +160,7 @@ bool CortexUpdCmd::GetNightly(const std::string& v) {
std::ostringstream release_path;
release_path << "cortex/" << version << "/" << system_info.os << "-"
<< system_info.arch << "/" << kNightlyFileName;
CTL_INF("Engine release path: " << kNightlyHost << release_path.str());
CTL_INF("Engine release path: " << kNightlyHost << "/" << release_path.str());

auto download_task = DownloadTask{.id = "cortex",
.type = DownloadType::Cortex,
Expand Down Expand Up @@ -190,7 +191,8 @@ bool CortexUpdCmd::GetNightly(const std::string& v) {

// Replace binay file
auto executable_path = file_manager_utils::GetExecutableFolderContainerPath();
auto src = executable_path / "cortex" / GetCortexBinary();
auto src = std::filesystem::temp_directory_path() / "cortex" / kCortexBinary /
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change accordingly to s3 structure

GetCortexBinary();
auto dst = executable_path / GetCortexBinary();
return ReplaceBinaryInflight(src, dst);
}
Expand Down
10 changes: 5 additions & 5 deletions engine/commands/cortex_upd_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ inline void CheckNewUpdate() {
if (current_version != latest_version) {
CLI_LOG("\nA new release of cortex is available: "
<< current_version << " -> " << latest_version);
CLI_LOG("To upgrade, run: cortex update");
// CLI_LOG(json_res["html_url"].get<std::string>());
CLI_LOG("To upgrade, run: " << GetCortexBinary() << " update");
if (CORTEX_VARIANT == file_manager_utils::kProdVariant) {
CLI_LOG(json_res["html_url"].get<std::string>());
}
}
} catch (const nlohmann::json::parse_error& e) {
CTL_INF("JSON parse error: " << e.what());
Expand All @@ -83,7 +85,7 @@ inline bool ReplaceBinaryInflight(const std::filesystem::path& src,
// Already has the newest
return true;
}
std::filesystem::path temp = std::filesystem::temp_directory_path() / "cortex_temp";
std::filesystem::path temp = dst.parent_path() / "cortex_temp";

try {
if (std::filesystem::exists(temp)) {
Expand All @@ -97,8 +99,6 @@ inline bool ReplaceBinaryInflight(const std::filesystem::path& src,
std::filesystem::perms::group_all |
std::filesystem::perms::others_read |
std::filesystem::perms::others_exec);
auto download_folder = src.parent_path();
std::filesystem::remove_all(download_folder);
} catch (const std::exception& e) {
CTL_ERR("Something wrong happened: " << e.what());
if (std::filesystem::exists(temp)) {
Expand Down
1 change: 1 addition & 0 deletions engine/e2e-test/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from test_cli_engine_install import TestCliEngineInstall
from test_cli_engine_list import TestCliEngineList
from test_cli_engine_uninstall import TestCliEngineUninstall
from test_cortex_update import TestCortexUpdate
from test_cli_server_start import TestCliServerStart
from test_create_log_folder import TestCreateLogFolder

Expand Down
14 changes: 14 additions & 0 deletions engine/e2e-test/test_cortex_update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import platform

import pytest
from test_runner import run


class TestCortexUpdate:
# We don't have stable release yet, so mark this test as skip for now
# Only able to test with beta and nightly
@pytest.mark.skip(reason="Stable release is not available yet")
def test_cortex_update(self):
exit_code, output, error = run("Update cortex", ["update"])
assert exit_code == 0, f"Something wrong happened"
assert "Update cortex sucessfully" in output
15 changes: 14 additions & 1 deletion engine/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "utils/file_logger.h"
#include "utils/file_manager_utils.h"
#include "utils/logging_utils.h"
#include "commands/cortex_upd_cmd.h"

#if defined(__APPLE__) && defined(__MACH__)
#include <libgen.h> // for dirname()
Expand Down Expand Up @@ -91,8 +92,9 @@ void ForkProcess() {
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
auto exe = commands::GetCortexBinary();
std::string cmds =
cortex_utils::GetCurrentPath() + "/cortex-cpp.exe --start-server";
cortex_utils::GetCurrentPath() + "/" + exe + " --start-server";
// Create child process
if (!CreateProcess(
NULL, // No module name (use command line)
Expand Down Expand Up @@ -133,6 +135,17 @@ void ForkProcess() {
int main(int argc, char* argv[]) {
{ file_manager_utils::CreateConfigFileIfNotExist(); }

// Delete temporary file if it exists
auto temp =
file_manager_utils::GetExecutableFolderContainerPath() / "cortex_temp";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After cortex update, we can only remove temporary file at the next start

if (std::filesystem::exists(temp)) {
try {
std::filesystem::remove(temp);
} catch (const std::exception& e) {
std::cerr << e.what() << '\n';
}
}

// Check if this process is for python execution
if (argc > 1) {
if (strcmp(argv[1], "--run_python_file") == 0) {
Expand Down
2 changes: 1 addition & 1 deletion engine/utils/file_manager_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ inline std::filesystem::path GetContainerFolderPath(
} else if (type == "CudaToolkit") {
container_folder_path = current_path;
} else if (type == "Cortex") {
container_folder_path = current_path / "cortex";
container_folder_path = std::filesystem::temp_directory_path() / "cortex";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Download binary to temp folder

} else {
container_folder_path = current_path / "misc";
}
Expand Down