|
|
|
@ -1,17 +1,14 @@
|
|
|
|
|
#include "config.hpp"
|
|
|
|
|
#include "network.hpp"
|
|
|
|
|
#include "program.hpp"
|
|
|
|
|
#include "runner.hpp"
|
|
|
|
|
#include <filesystem>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <queue>
|
|
|
|
|
#include <spawn.h>
|
|
|
|
|
#include <string_view>
|
|
|
|
|
#include <toml++/toml.h>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <wait.h>
|
|
|
|
|
|
|
|
|
|
#include "host.hpp"
|
|
|
|
|
#include "zmq_addon.hpp"
|
|
|
|
|
|
|
|
|
|
static constexpr uint32_t JOB_ID_LEN = 32;
|
|
|
|
@ -33,19 +30,41 @@ sk::runner_backend detect_backend() {
|
|
|
|
|
return sk::runner_backend::BubbleWrap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
std::vector<sk::host> listsHosts = sk::config::loadHostsFromToml("../conf.toml");
|
|
|
|
|
std::priority_queue<sk::host> hosts(listsHosts.begin(), listsHosts.end());
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
|
int opt;
|
|
|
|
|
std::optional<sk::runner_backend> selected_backend;
|
|
|
|
|
while ((opt = getopt(argc, argv, "bc")) != -1) {
|
|
|
|
|
switch (opt) {
|
|
|
|
|
case 'b':
|
|
|
|
|
selected_backend = sk::runner_backend::BubbleWrap;
|
|
|
|
|
break;
|
|
|
|
|
case 'c':
|
|
|
|
|
selected_backend = sk::runner_backend::Docker;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
std::cerr << "Usage: %s [-bc] [script]\n";
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::queue<sk::program> programQueue;
|
|
|
|
|
sk::runner runner(selected_backend.has_value() ? selected_backend.value() : detect_backend());
|
|
|
|
|
|
|
|
|
|
if (hosts.empty()) {
|
|
|
|
|
std::cerr << "Pas de host" << std::endl;
|
|
|
|
|
exit(1);
|
|
|
|
|
if (optind < argc) {
|
|
|
|
|
std::ifstream t(argv[optind]);
|
|
|
|
|
if (!t) {
|
|
|
|
|
std::cerr << "Unable to open file " << argv[optind] << std::endl;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
std::stringstream buffer;
|
|
|
|
|
buffer << t.rdbuf();
|
|
|
|
|
std::string code = buffer.str();
|
|
|
|
|
sk::program program{code, "ghcr.io/moshell-lang/moshell"};
|
|
|
|
|
sk::run_result result = runner.run_blocking(program);
|
|
|
|
|
std::cout << "out: " << result.out << "\n";
|
|
|
|
|
std::cout << "err: " << result.err << "\n";
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sk::runner runner(detect_backend());
|
|
|
|
|
|
|
|
|
|
zmq::context_t context(1);
|
|
|
|
|
zmq::socket_t receiver(context, zmq::socket_type::pull);
|
|
|
|
|
receiver.connect("tcp://localhost:5557");
|
|
|
|
|