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/remote/config.hpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'src/buildtool/serve_api/remote/config.hpp') diff --git a/src/buildtool/serve_api/remote/config.hpp b/src/buildtool/serve_api/remote/config.hpp index 582727e0..82119828 100644 --- a/src/buildtool/serve_api/remote/config.hpp +++ b/src/buildtool/serve_api/remote/config.hpp @@ -34,9 +34,12 @@ struct RemoteServeConfig final { class Builder; - // Server address of remote execution. + // Server address of the serve endpoint. std::optional const remote_address; + // Execution endpoint used by the client. + std::optional const client_execution_address; + // Known Git repositories to serve server. std::vector const known_repositories; @@ -55,6 +58,13 @@ struct RemoteServeConfig final { class RemoteServeConfig::Builder final { public: + // Set remote execution and cache address, unsets if parsing `address` fails + auto SetClientExecutionAddress(std::optional value) noexcept + -> Builder& { + client_execution_address_ = std::move(value); + return *this; + } + // Set remote execution and cache address, unsets if parsing `address` fails auto SetRemoteAddress(std::optional value) noexcept -> Builder& { @@ -110,7 +120,15 @@ class RemoteServeConfig::Builder final { *remote_address_)}; } } - + auto client_execution_address = default_config.client_execution_address; + if (client_execution_address_.has_value()) { + client_execution_address = ParseAddress(*client_execution_address_); + if (not client_execution_address) { + return unexpected{ + fmt::format("Setting client execution address '{}' failed.", + *client_execution_address_)}; + } + } auto known_repositories = default_config.known_repositories; if (known_repositories_.has_value()) { try { @@ -154,6 +172,7 @@ class RemoteServeConfig::Builder final { return RemoteServeConfig{ .remote_address = std::move(remote_address), + .client_execution_address = std::move(client_execution_address), .known_repositories = std::move(known_repositories), .jobs = jobs, .build_jobs = build_jobs, @@ -162,9 +181,12 @@ class RemoteServeConfig::Builder final { } private: - // Server address of remote execution. + // Server address of the serve endpoint. std::optional remote_address_; + // Execution endpoint used by the client. + std::optional client_execution_address_; + // Known Git repositories to serve server. std::optional> known_repositories_; -- cgit v1.2.3