feat(worker): execute remote action specs from the CAS
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 6s
VoidBuildSystem CI / sanitizers-gcc16 (push) Failing after 6s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 10s
VoidBuildSystem CI / fuzz-clang (push) Failing after 4s
VoidBuildSystem CI / wine-windows-gcc16 (push) Failing after 57s
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 6s
VoidBuildSystem CI / sanitizers-gcc16 (push) Failing after 6s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 10s
VoidBuildSystem CI / fuzz-clang (push) Failing after 4s
VoidBuildSystem CI / wine-windows-gcc16 (push) Failing after 57s
This commit is contained in:
1 parent
9d7c801e2d
commit
af2be817a5
6 files changed
+278
-7
No files matched your search
@@ -2350,3 +2350,94 @@ void build(Void::Build::Project &p) {
|
||||
}
|
||||
server.stop();
|
||||
}
|
||||
|
||||
// `vbs worker --queue` executes a remotely supplied action spec: it downloads the input blobs
|
||||
// from the CAS, runs the command, stores the outputs and submits the result.
|
||||
VOID_TEST(RegistryTests, worker_executes_remote_action_spec) {
|
||||
const auto vbs_bin = locate_vbs_binary();
|
||||
Void::Testing::expect(!vbs_bin.empty() && std::filesystem::exists(vbs_bin));
|
||||
if (vbs_bin.empty() || !std::filesystem::exists(vbs_bin)) {
|
||||
return;
|
||||
}
|
||||
Void::FileSystem::TempDir tmp{"vbs_remote_exec_"};
|
||||
RegistryConfig cfg;
|
||||
cfg.data_dir = tmp / "reg_data";
|
||||
cfg.bind_address = "127.0.0.1";
|
||||
cfg.port = 0;
|
||||
cfg.bootstrap_admin_user = "admin";
|
||||
cfg.bootstrap_admin_password = "admin_pw";
|
||||
auto svc = RegistryService::open(cfg);
|
||||
Void::Testing::expect(svc.has_value());
|
||||
if (!svc) {
|
||||
return;
|
||||
}
|
||||
Void::Testing::expect((*svc)->create_user("rex_pub", "rex_pass", Role::Publisher).has_value());
|
||||
auto tok = (*svc)->create_token("rex_pub", "rex", {"read", "publish"});
|
||||
Void::Testing::expect(tok.has_value());
|
||||
if (!tok) {
|
||||
return;
|
||||
}
|
||||
Void::Testing::expect((*svc)->start_http().has_value());
|
||||
const auto port = (*svc)->bound_port();
|
||||
const std::string reg_url = "http://127.0.0.1:" + std::to_string(port);
|
||||
const std::map<std::string, std::string, std::less<>> auth{{"Authorization", "Bearer " + *tok}};
|
||||
|
||||
const auto workdir = tmp / "workdir";
|
||||
std::filesystem::create_directories(workdir);
|
||||
const std::string input = "REMOTE_INPUT\n";
|
||||
const std::string input_sha = Util::sha256_hex(input);
|
||||
auto blob_put = send_loopback_http(port, "PUT", "/api/v1/cas/blobs/" + input_sha, auth, input);
|
||||
Void::Testing::expect(blob_put.has_value() && blob_put->status == 201);
|
||||
|
||||
const std::string action_key = Util::sha256_hex("remote-exec-action");
|
||||
const std::string spec = "{\"schema_version\":1,\"action_key\":\"" + action_key +
|
||||
"\",\"command\":[\"/bin/sh\",\"-c\",\"cat input.txt > output.txt\"],"
|
||||
"\"working_directory\":\"" +
|
||||
workdir.string() + "\",\"inputs\":{\"input.txt\":{\"sha256\":\"" +
|
||||
input_sha + "\",\"size\":" + std::to_string(input.size()) +
|
||||
",\"mode\":420}},\"output_paths\":[\"output.txt\"]}";
|
||||
auto record_put =
|
||||
send_loopback_http(port, "PUT", "/api/v1/cas/actions/" + action_key, auth, spec);
|
||||
Void::Testing::expect(record_put.has_value() && record_put->status == 201);
|
||||
auto enqueued = send_loopback_http(port, "POST", "/api/v1/queue", auth,
|
||||
"{\"action_keys\":[\"" + action_key + "\"]}");
|
||||
Void::Testing::expect(enqueued.has_value() && enqueued->status == 200);
|
||||
|
||||
Platform::ProcessRequest worker;
|
||||
worker.executable = vbs_bin;
|
||||
worker.arguments = {"worker",
|
||||
"--registry",
|
||||
reg_url,
|
||||
"--queue",
|
||||
"--once",
|
||||
"--build-dir",
|
||||
(tmp / "build").string()};
|
||||
worker.environment.set_vars["VBS_REGISTRY_TOKEN"] = *tok;
|
||||
worker.timeout = std::chrono::seconds{120};
|
||||
auto worker_res = Platform::run_supervised(worker);
|
||||
Void::Testing::expect_eq(
|
||||
worker_res ? (worker_res->succeeded() ? std::string{}
|
||||
: (worker_res->stdout_data + worker_res->stderr_data))
|
||||
: worker_res.error().message(),
|
||||
std::string{});
|
||||
|
||||
// The command ran locally and produced the declared output.
|
||||
auto local_output = Void::FileSystem::read_file(workdir / "output.txt");
|
||||
Void::Testing::require(local_output.has_value());
|
||||
Void::Testing::expect_eq(*local_output, input);
|
||||
|
||||
// The result record and output blob are now in the registry CAS.
|
||||
auto cas_record = send_loopback_http(port, "GET", "/api/v1/cas/actions/" + action_key, auth);
|
||||
Void::Testing::expect(cas_record.has_value() && cas_record->status == 200);
|
||||
if (cas_record) {
|
||||
Void::Testing::expect(cas_record->body.find("output.txt") != std::string::npos);
|
||||
Void::Testing::expect(cas_record->body.find("\"exit_code\":0") != std::string::npos);
|
||||
}
|
||||
const std::string output_sha = Util::sha256_hex(input);
|
||||
auto cas_blob = send_loopback_http(port, "GET", "/api/v1/cas/blobs/" + output_sha, auth);
|
||||
Void::Testing::expect(cas_blob.has_value() && cas_blob->status == 200);
|
||||
if (cas_blob) {
|
||||
Void::Testing::expect_eq(cas_blob->body, input);
|
||||
}
|
||||
(*svc)->stop_http();
|
||||
}
|
||||
Reference in new issue
Block a user