From 826ef3b100804c598c2af8e5c633e169c5fc1be3 Mon Sep 17 00:00:00 2001 From: Erin Abicht Date: Mon, 3 Apr 2023 01:05:08 -0400 Subject: [PATCH] Actually run build commands (only cargo rn though) --- README.md | 14 ++++++++-- forge-server/src/main.rs | 59 ++++++++++++++++++++++++++++++++-------- 2 files changed, 58 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 26ca0c8..f34d2b4 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,18 @@ On first run, `forge-server` will create a configuration file for you in the def Use this to configure options, such as the IP & port to bind on, and whether to use authentication (along with a password). Authentication will use *Argon2id* to hash and verify passwords. +Right now it only supports building `cargo` projects. -Actually building stuff is a **WIP**. +### Build +```bash +cargo run -p forge-server +$EDITOR ~/.config/forge/config.toml +cargo run -p forge-server +``` ## Client -Fully **WIP**. - Sends data to the server specified via commandline options. + +```bash +cargo run -p forge +``` diff --git a/forge-server/src/main.rs b/forge-server/src/main.rs index fe87c29..21a0f5d 100644 --- a/forge-server/src/main.rs +++ b/forge-server/src/main.rs @@ -5,6 +5,7 @@ use argon2::{ use paris::{error, info, success, warn}; use serde::{Deserialize, Serialize}; use serde_json::Result; +use std::process::Command as pCommand; use std::{fmt, fs, io, net::SocketAddr, path::PathBuf, process::exit}; use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader}; use tokio::net::{TcpListener, TcpStream}; @@ -101,7 +102,7 @@ struct Message { basename: String, } -async fn build(msg: Message, address: SocketAddr, dir: String) { +async fn build(msg: Message, address: SocketAddr, dir: PathBuf) { let mut features = String::new(); match msg.command.features { Some(f) => { @@ -115,19 +116,53 @@ async fn build(msg: Message, address: SocketAddr, dir: String) { None => features = "".to_string(), } + let mut build_dir = dir; + build_dir.push(&msg.basename); + + let mut manifest = build_dir.clone(); + manifest.push("Cargo.toml"); + success!( - "Received message from {:?}: {}\ncd {}\ngit clone {}\ncd {}\n{} {} {} {}\n", + "Received message from {:?}: {}", address, - msg.uuid.format_hyphenated(), - dir, - msg.repository, - msg.basename, - msg.command.build_system, - msg.command.subcommand, - msg.command.tag, - features, + msg.uuid, ); + let git_output = pCommand::new("git") + .arg("clone") + .arg(msg.repository.to_string()) + .arg(&build_dir) + .output() + .unwrap(); + if !git_output.status.success() { + error!("{:?}", git_output); + } else { + info!("{:?}", git_output); + } + + let build_output = match msg.command.tag { + Tag::Release => { + pCommand::new(msg.command.build_system.to_string()) + .arg(msg.command.subcommand.to_string()) + .arg(msg.command.tag.to_string()) + .arg(format!("--manifest-path={}", &manifest.display())) + // .arg(features.to_string()) + .output() + .unwrap() + } + Tag::Debug => pCommand::new(msg.command.build_system.to_string()) + .arg(msg.command.subcommand.to_string()) + .arg(format!("--manifest-path={}", &manifest.display())) + .output() + .unwrap(), + }; + + if !build_output.status.success() { + error!("{:?}", build_output); + } else { + info!("{:?}", build_output); + } + match msg.pre_exec { Some(e) => info!("Running pre-exec: {}", e), None => {} @@ -165,7 +200,7 @@ async fn process_socket( mut socket: TcpStream, address: SocketAddr, auth: AuthConfig, - dir: String, + dir: PathBuf, salt: SaltString, argon2: Argon2<'_>, ) { @@ -228,7 +263,7 @@ async fn main() -> io::Result<()> { match listener.accept().await { Ok((socket, addr)) => { let auth = config.auth.clone(); - let dir = config.host.build_directory.clone().unwrap(); + let dir = PathBuf::from(config.host.build_directory.clone().unwrap()); let m_salt = salt.clone(); let m_argon2 = argon2.clone(); tokio::spawn(async move {