Skip to content

Commit

Permalink
remote builds templated out
Browse files Browse the repository at this point in the history
  • Loading branch information
lsproule committed Nov 6, 2023
1 parent 7afc8f7 commit 5897052
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 21 deletions.
7 changes: 5 additions & 2 deletions src/Command/CommandServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,21 @@ namespace Command{
username = username_promp->Get();
return true;
}

bool getServerAuthMethod(std::string& authMethod){
Prompt<std::string> *authMethod_promp = new Prompt<std::string>("Enter the authentication method of the server[pem/password]: ");
authMethod_promp->Run();
authMethod = authMethod_promp->Get();
return true;
}

bool getServerPassword(std::string& password){
Prompt<std::string> *password_promp = new Prompt<std::string>("Enter the password of the server: ");
password_promp->Run();
password = password_promp->Get();
return true;
}

bool getServerKey(std::string& key){
Prompt<std::string> *key_promp = new Prompt<std::string>("Enter path the ssh key for the server: ");
key_promp->Run();
Expand Down Expand Up @@ -137,7 +140,7 @@ Usage server:
servers.push_back(build_server);

std::vector<json> build_server_json;
for (auto& build_server: servers){
for (BuildServer& build_server: servers){
json build_server_json_tmp = {
{"name", build_server.name},
{"address", build_server.ip},
Expand Down Expand Up @@ -212,7 +215,7 @@ Usage server:



for (auto& server : server_list){
for (json& server : server_list){
BuildServer build_server = BuildServer(
server["name"].get<std::string>(),
server["address"].get<std::string>(),
Expand Down
61 changes: 44 additions & 17 deletions src/Command/CommandWatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,25 +131,52 @@ namespace Command {

#else
std::string command = "cmake . && make && ./" + pro->build_dir + "/" + pro->project_name;
std::string current_build_server= std::string(std::getenv("HOME")) + "/.config/cmaker/" + "current_build_server.json";
json current_build_server_json = json::parse(std::ifstream(current_build_server));
if (!current_build_server_json["name"].is_null()) {
pro->build_server = BuildServer(

current_build_server_json["name"].get<std::string>(),
current_build_server_json["address"].get<std::string>(),
current_build_server_json["username"].get<std::string>(),
current_build_server_json["authMethod"].get<std::string>(),
current_build_server_json["password"].get<std::string>(),
current_build_server_json["key"].get<std::string>(),
current_build_server_json["port"].get<int>()

);
bool build_server=args->operator[]("remote-build").as<bool>();
if (build_server == true) {
std::string current_build_server= std::string(std::getenv("HOME")) + "/.config/cmaker/" + "current_build_server.json";
json current_build_server_json = json::parse(std::ifstream(current_build_server));
if (!current_build_server_json["name"].is_null()) {
pro->build_server = BuildServer(
current_build_server_json["name"].get<std::string>(),
current_build_server_json["address"].get<std::string>(),
current_build_server_json["username"].get<std::string>(),
current_build_server_json["authMethod"].get<std::string>(),
current_build_server_json["password"].get<std::string>(),
current_build_server_json["key"].get<std::string>(),
current_build_server_json["port"].get<int>()
);
}
command = "rsync -avh --exclude-from='.gitignore' --update -e 'ssh -p " + std::to_string(pro->build_server.port) + "' --progress . "
+ pro->build_server.username + "@" + pro->build_server.ip
+ ":/tmp/cmaker && ssh -p " + std::to_string(pro->build_server.port) + " " + pro->build_server.username + "@" + pro->build_server.ip
+ " 'cd /tmp/cmaker && cmake . && make && ./build/" + pro->project_name + "'";

}
command = "rsync -avh --exclude-from='.gitignore' --update -e 'ssh -p " + std::to_string(pro->build_server.port) + "' --progress . "
+ pro->build_server.username + "@" + pro->build_server.ip
+ ":/tmp/cmaker && ssh -p " + std::to_string(pro->build_server.port) + " " + pro->build_server.username + "@" + pro->build_server.ip
+ " 'cd /tmp/cmaker && cmake . && make && ./build/new'";
// else{
// std::string build_servers = std::string(std::getenv("HOME")) + "/.config/cmaker/" + "build_servers.json";
// json build_servers_json = json::parse(std::ifstream(build_servers));
// std::string build_server = args->operator[]("server").as<std::string>();
// for (auto &bserver: build_servers_json){
// if (bserver["name"].get<std::string>() == build_server){
// pro->build_server = BuildServer(
// bserver["name"].get<std::string>(),
// bserver["address"].get<std::string>(),
// bserver["username"].get<std::string>(),
// bserver["authMethod"].get<std::string>(),
// bserver["password"].get<std::string>(),
// bserver["key"].get<std::string>(),
// bserver["port"].get<int>()
//
// );
// command = "rsync -avh --exclude-from='.gitignore' --update -e 'ssh -p " + std::to_string(pro->build_server.port) + "' --progress . "
// + pro->build_server.username + "@" + pro->build_server.ip
// + ":/tmp/cmaker && ssh -p " + std::to_string(pro->build_server.port) + " " + pro->build_server.username + "@" + pro->build_server.ip
// + " 'cd /tmp/cmaker && cmake . && make && ./build/" + pro->project_name + "'";
// break;
// }
// }
// }
if (args->count("args") != 0) {
std::cout << "estamos aqui" << std::endl;
std::vector<std::string> args_vec = args->operator[]("args").as<std::vector<std::string>>();
Expand Down
3 changes: 1 addition & 2 deletions src/Command/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace Command {
("o,ours", "watches cmaker source", cxxopts::value<bool>())
#endif
("command", "Command to run", cxxopts::value<std::string>()->default_value("help"))
("b,build-server", "Build server to use", cxxopts::value<std::string>())
("b,remote-build", "Build server to use", cxxopts::value<bool>()->default_value("false"))
("c,args", "command to pass to dev", cxxopts::value<std::vector<std::string>>())
("y,skip-init", "skip init", cxxopts::value<bool>()->default_value("true"))
("v,verbose", "Verbose output", cxxopts::value<bool>()->default_value("false"));
Expand All @@ -100,7 +100,6 @@ namespace Command {
#endif
("command", "Command to run", cxxopts::value<std::string>()->default_value("help"))
("subcommand", "Subcommand to run", cxxopts::value<std::string>())("h,help", "Print usage")
("c,args", "command to pass to dev", cxxopts::value<std::vector<std::string>>())
("y,skip-init", "skip init", cxxopts::value<bool>()->default_value("true"))
("v,verbose", "Verbose output", cxxopts::value<bool>()->default_value("false"));
return interface->parse();
Expand Down

0 comments on commit 5897052

Please sign in to comment.