From 455003d0e924414db339395e8367166e7820c5da Mon Sep 17 00:00:00 2001 From: Alberto Sartori Date: Mon, 24 Feb 2025 14:16:42 +0100 Subject: just serve: allow clients to access execution endpoint with a different address To properly use `just serve`, both the client and the serve instance must talk to the very same execution endpoint. Typically, both the client and serve can reach out to the execution endpoint via the same IP address. However, it might be possible that the client and a serve instance know the same execution endpoint by means of differnet IP addresses. For example, the client knows the execution endpoint address through an _external_ IP address, while the serve instance, deployed within the same network infrastructure, only knows the _internal_ IP address. This patch adds the subkey `"client address"` -- of the key `"execution endpoint"` -- in the serve configuration file, to specify the alternative pair `address:port` used by the client. --- src/buildtool/serve_api/serve_service/TARGETS | 1 + src/buildtool/serve_api/serve_service/configuration.cpp | 8 +++++++- src/buildtool/serve_api/serve_service/configuration.hpp | 10 +++++++--- .../serve_api/serve_service/serve_server_implementation.cpp | 3 ++- 4 files changed, 17 insertions(+), 5 deletions(-) (limited to 'src/buildtool/serve_api/serve_service') diff --git a/src/buildtool/serve_api/serve_service/TARGETS b/src/buildtool/serve_api/serve_service/TARGETS index 7b459f60..2a2928e5 100644 --- a/src/buildtool/serve_api/serve_service/TARGETS +++ b/src/buildtool/serve_api/serve_service/TARGETS @@ -170,6 +170,7 @@ , ["@", "gsl", "", "gsl"] , ["src/buildtool/crypto", "hash_function"] , ["src/buildtool/execution_api/remote", "config"] + , ["src/buildtool/serve_api/remote", "config"] ] , "stage": ["src", "buildtool", "serve_api", "serve_service"] , "private-deps": diff --git a/src/buildtool/serve_api/serve_service/configuration.cpp b/src/buildtool/serve_api/serve_service/configuration.cpp index 2c1a14e4..503267f9 100644 --- a/src/buildtool/serve_api/serve_service/configuration.cpp +++ b/src/buildtool/serve_api/serve_service/configuration.cpp @@ -27,7 +27,13 @@ auto ConfigurationService::RemoteExecutionEndpoint( const ::justbuild::just_serve::RemoteExecutionEndpointRequest* /*request*/, ::justbuild::just_serve::RemoteExecutionEndpointResponse* response) -> ::grpc::Status { - auto address = remote_config_.remote_address; + std::optional address; + if (serve_config_.client_execution_address.has_value()) { + address = serve_config_.client_execution_address; + } + else { + address = remote_config_.remote_address; + } response->set_address(address ? address->ToJson().dump() : std::string()); return ::grpc::Status::OK; } diff --git a/src/buildtool/serve_api/serve_service/configuration.hpp b/src/buildtool/serve_api/serve_service/configuration.hpp index 35431b7f..ce37c31d 100644 --- a/src/buildtool/serve_api/serve_service/configuration.hpp +++ b/src/buildtool/serve_api/serve_service/configuration.hpp @@ -22,6 +22,7 @@ #include "justbuild/just_serve/just_serve.pb.h" #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/remote/config.hpp" +#include "src/buildtool/serve_api/remote/config.hpp" // This service can be used by the client to double-check the server // configuration. @@ -30,9 +31,11 @@ class ConfigurationService final public: explicit ConfigurationService( HashFunction::Type hash_type, - gsl::not_null const& - remote_config) noexcept - : hash_type_{hash_type}, remote_config_{*remote_config} {}; + gsl::not_null const& remote_config, + gsl::not_null const& serve_config) noexcept + : hash_type_{hash_type}, + remote_config_{*remote_config}, + serve_config_{*serve_config} {} // Returns the address of the associated remote endpoint, if set, // or an empty string signaling that the serve endpoint acts also @@ -58,6 +61,7 @@ class ConfigurationService final private: HashFunction::Type hash_type_; RemoteExecutionConfig const& remote_config_; + RemoteServeConfig const& serve_config_; }; #endif // INCLUDED_SRC_BUILD_SERVE_API_SERVE_SERVICE_CONFIGURATION_HPP 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 f6405651..c8426469 100644 --- a/src/buildtool/serve_api/serve_service/serve_server_implementation.cpp +++ b/src/buildtool/serve_api/serve_service/serve_server_implementation.cpp @@ -138,7 +138,8 @@ auto ServeServerImpl::Run( &apis, lock_, serve ? &*serve : nullptr}; - ConfigurationService cs{hash_type, remote_context->exec_config}; + ConfigurationService cs{ + hash_type, remote_context->exec_config, &serve_config}; // For the SourceTreeService we need to always have access to a native // storage. In compatible mode, this requires creating a second local -- cgit v1.2.3