diff options
author | Alberto Sartori <alberto.sartori@huawei.com> | 2023-11-13 16:01:41 +0100 |
---|---|---|
committer | Alberto Sartori <alberto.sartori@huawei.com> | 2023-11-15 20:19:18 +0100 |
commit | 67df0b309e6c84d6a5c6239706333848bd02c518 (patch) | |
tree | b9b8fb6ecbfaf2efc5843eafbd91c681c0ac7e3d /src | |
parent | 0a55a1debd0cdd9ca5832ef824e51f583111928c (diff) | |
download | justbuild-67df0b309e6c84d6a5c6239706333848bd02c518.tar.gz |
just-serve: start a just-execute instance if the user does not provide...
...a remote execution end-point for just-serve.
Diffstat (limited to 'src')
4 files changed, 57 insertions, 18 deletions
diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp index b6e7b63f..d6b06471 100644 --- a/src/buildtool/main/main.cpp +++ b/src/buildtool/main/main.cpp @@ -971,7 +971,8 @@ auto main(int argc, char* argv[]) -> int { if (arguments.cmd == SubCommand::kServe) { SetupServeServiceConfig(arguments.service); - if (!ServeServerImpl::Instance().Run()) { + if (!ServeServerImpl::Instance().Run( + !RemoteExecutionConfig::RemoteAddress())) { return kExitFailure; } return kExitSuccess; diff --git a/src/buildtool/serve_api/serve_service/TARGETS b/src/buildtool/serve_api/serve_service/TARGETS index 953da5d6..5e00b3d1 100644 --- a/src/buildtool/serve_api/serve_service/TARGETS +++ b/src/buildtool/serve_api/serve_service/TARGETS @@ -53,6 +53,12 @@ , ["src/buildtool/common/remote", "port"] , ["src/buildtool/compatibility", "compatibility"] , ["src/buildtool/storage", "config"] + , ["src/buildtool/execution_api/execution_service", "execution_server"] + , ["src/buildtool/execution_api/execution_service", "ac_server"] + , ["src/buildtool/execution_api/execution_service", "cas_server"] + , ["src/buildtool/execution_api/execution_service", "bytestream_server"] + , ["src/buildtool/execution_api/execution_service", "capabilities_server"] + , ["src/buildtool/execution_api/execution_service", "operations_server"] ] } } diff --git a/src/buildtool/serve_api/serve_service/serve_server_implementation.cpp b/src/buildtool/serve_api/serve_service/serve_server_implementation.cpp index f1113cdd..7eea7d91 100644 --- a/src/buildtool/serve_api/serve_service/serve_server_implementation.cpp +++ b/src/buildtool/serve_api/serve_service/serve_server_implementation.cpp @@ -25,6 +25,12 @@ #include "src/buildtool/auth/authentication.hpp" #include "src/buildtool/common/remote/port.hpp" #include "src/buildtool/compatibility/compatibility.hpp" +#include "src/buildtool/execution_api/execution_service/ac_server.hpp" +#include "src/buildtool/execution_api/execution_service/bytestream_server.hpp" +#include "src/buildtool/execution_api/execution_service/capabilities_server.hpp" +#include "src/buildtool/execution_api/execution_service/cas_server.hpp" +#include "src/buildtool/execution_api/execution_service/execution_server.hpp" +#include "src/buildtool/execution_api/execution_service/operations_server.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/file_system/git_repo.hpp" #include "src/buildtool/logging/logger.hpp" @@ -46,13 +52,44 @@ auto TryWrite(std::string const& file, T const& content) noexcept -> bool { } } // namespace -auto ServeServerImpl::Run() -> bool { +auto ServeServerImpl::Run(bool with_execute) -> bool { + // make sure the git root directory is properly initialized + if (not FileSystemManager::CreateDirectory(StorageConfig::GitRoot())) { + Logger::Log(LogLevel::Error, + "Could not create directory {}. Aborting", + StorageConfig::GitRoot().string()); + return false; + } + if (not GitRepo::InitAndOpen(StorageConfig::GitRoot(), true)) { + Logger::Log(LogLevel::Error, + fmt::format("could not initialize bare git repository {}", + StorageConfig::GitRoot().string())); + return false; + } + SourceTreeService sts{}; grpc::ServerBuilder builder; builder.RegisterService(&sts); + // the user has not given any remote-execution endpoint + // so we start a "just-execute instance" on the same process + [[maybe_unused]] ExecutionServiceImpl es{}; + [[maybe_unused]] ActionCacheServiceImpl ac{}; + [[maybe_unused]] CASServiceImpl cas{}; + [[maybe_unused]] BytestreamServiceImpl b{}; + [[maybe_unused]] CapabilitiesServiceImpl cap{}; + [[maybe_unused]] OperarationsServiceImpl op{}; + if (with_execute) { + builder.RegisterService(&es) + .RegisterService(&ac) + .RegisterService(&cas) + .RegisterService(&b) + .RegisterService(&cap) + .RegisterService(&op); + } + std::shared_ptr<grpc::ServerCredentials> creds; if (Auth::GetAuthMethod() == AuthMethod::kTLS) { auto tls_opts = grpc::SslServerCredentialsOptions{}; @@ -69,20 +106,6 @@ auto ServeServerImpl::Run() -> bool { creds = grpc::InsecureServerCredentials(); } - // make sure the git root directory is properly initialized - if (not FileSystemManager::CreateDirectory(StorageConfig::GitRoot())) { - Logger::Log(LogLevel::Error, - "Could not create directory {}. Aborting", - StorageConfig::GitRoot().string()); - return false; - } - if (not GitRepo::InitAndOpen(StorageConfig::GitRoot(), true)) { - Logger::Log(LogLevel::Error, - fmt::format("could not initialize bare git repository {}", - StorageConfig::GitRoot().string())); - return false; - } - builder.AddListeningPort( fmt::format("{}:{}", interface_, port_), creds, &port_); @@ -92,6 +115,13 @@ auto ServeServerImpl::Run() -> bool { return false; } + if (with_execute and !RemoteExecutionConfig::SetRemoteAddress( + fmt::format("{}:{}", interface_, port_))) { + Logger::Log(LogLevel::Error, + "Internal error: cannot set the remote address"); + return false; + } + auto pid = getpid(); nlohmann::json const& info = { @@ -106,8 +136,10 @@ auto ServeServerImpl::Run() -> bool { auto const& info_str = nlohmann::to_string(info); Logger::Log(LogLevel::Info, - fmt::format("{}serve service started: {}", + fmt::format("{}serve{} service{} started: {}", Compatibility::IsCompatible() ? "compatible " : "", + with_execute ? " and execute" : "", + with_execute ? "s" : "", info_str)); if (!info_file_.empty()) { diff --git a/src/buildtool/serve_api/serve_service/serve_server_implementation.hpp b/src/buildtool/serve_api/serve_service/serve_server_implementation.hpp index f756a104..494165ed 100644 --- a/src/buildtool/serve_api/serve_service/serve_server_implementation.hpp +++ b/src/buildtool/serve_api/serve_service/serve_server_implementation.hpp @@ -47,7 +47,7 @@ class ServeServerImpl { ServeServerImpl(ServeServerImpl&&) noexcept = delete; auto operator=(ServeServerImpl&&) noexcept -> ServeServerImpl& = delete; - auto Run() -> bool; + auto Run(bool with_execute) -> bool; ~ServeServerImpl() = default; private: |