WIP cargo aoc bench on webhook
This commit is contained in:
commit
6248844714
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/target
|
||||||
2491
Cargo.lock
generated
Normal file
2491
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
14
Cargo.toml
Normal file
14
Cargo.toml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
[package]
|
||||||
|
name = "aocsync"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
rocket = "0.5.0-rc.2"
|
||||||
|
glog = {version = "0.1.0", git = "https://github.com/wathiede/glog-rs"}
|
||||||
|
log = "0.4.17"
|
||||||
|
serde = { version = "1.0.148", features = ["serde_derive"] }
|
||||||
|
rocket_anyhow = "0.1.1"
|
||||||
|
thiserror = "1.0.37"
|
||||||
17
README.md
Normal file
17
README.md
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# `git-sync` webhook
|
||||||
|
|
||||||
|
```
|
||||||
|
POST /-/reload?repo=akramer HTTP/1.1
|
||||||
|
Host: aocperf.z.xinu.tv
|
||||||
|
X-Real-IP: 172.17.0.7
|
||||||
|
X-Forwarded-For: 172.17.0.7
|
||||||
|
X-Forwarded-Proto: https
|
||||||
|
X-Forwarded-Host: aocperf.z.xinu.tv
|
||||||
|
X-Forwarded-Server: aocperf.z.xinu.tv
|
||||||
|
Connection: close
|
||||||
|
Content-Length: 0
|
||||||
|
gitsync-hash: 6f498804bf7203ab69fa7aa8e9f441d20d07ac67
|
||||||
|
accept-encoding: gzip
|
||||||
|
user-agent: Go-http-client/2.0
|
||||||
|
```
|
||||||
|
|
||||||
13
Rocket.toml
Normal file
13
Rocket.toml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
[release]
|
||||||
|
address = "0.0.0.0"
|
||||||
|
port = 9346
|
||||||
|
|
||||||
|
[debug]
|
||||||
|
address = "0.0.0.0"
|
||||||
|
port = 9346
|
||||||
|
# Uncomment to make it production like.
|
||||||
|
#log_level = "critical"
|
||||||
|
|
||||||
|
source_root = "/net/nasx/mnt/storage/aoc/"
|
||||||
|
build_root = "/tmp/aocsync/"
|
||||||
|
www_root = "/tmp/aocsync-serve/"
|
||||||
117
src/main.rs
Normal file
117
src/main.rs
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
#[macro_use]
|
||||||
|
extern crate rocket;
|
||||||
|
use std::{
|
||||||
|
fs, io,
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
process::Command,
|
||||||
|
};
|
||||||
|
|
||||||
|
use glog::Flags;
|
||||||
|
use log::info;
|
||||||
|
use rocket::{fairing::AdHoc, response::Responder, State};
|
||||||
|
use serde::Deserialize;
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
|
#[derive(Error, Debug, Responder)]
|
||||||
|
pub enum SyncError {
|
||||||
|
#[error("IO error")]
|
||||||
|
IoError(#[from] io::Error),
|
||||||
|
}
|
||||||
|
|
||||||
|
// For testing
|
||||||
|
#[get("/-/reload/<repo>")]
|
||||||
|
fn get_reload(config: &State<Config>, repo: &str) -> Result<String, SyncError> {
|
||||||
|
reload(config, repo)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[post("/-/reload/<repo>")]
|
||||||
|
fn post_reload(config: &State<Config>, repo: &str) -> Result<String, SyncError> {
|
||||||
|
reload(config, repo)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn reload(config: &State<Config>, repo: &str) -> Result<String, SyncError> {
|
||||||
|
info!("Need to reload '{}': {:?}", repo, config);
|
||||||
|
let source_path = config.source_root.join(repo);
|
||||||
|
let build_path = config.build_root.join(repo);
|
||||||
|
dbg!(&build_path);
|
||||||
|
dbg!(&source_path);
|
||||||
|
let needs_clone = false;
|
||||||
|
let mut output = String::new();
|
||||||
|
if needs_clone {
|
||||||
|
output += &format!(
|
||||||
|
"{:?}",
|
||||||
|
Command::new("/run/current-system/sw/bin/git")
|
||||||
|
.current_dir(&config.build_root)
|
||||||
|
.arg("clone")
|
||||||
|
.arg(&source_path)
|
||||||
|
.arg(&build_path)
|
||||||
|
.output()?
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// Make sure buildable clone is up to date
|
||||||
|
output += &format!(
|
||||||
|
"{:?}",
|
||||||
|
Command::new("/run/current-system/sw/bin/git")
|
||||||
|
.current_dir(&build_path)
|
||||||
|
.arg("pull")
|
||||||
|
.output()?
|
||||||
|
);
|
||||||
|
// Run `cargo aoc bench`
|
||||||
|
output += &format!(
|
||||||
|
"{:?}",
|
||||||
|
Command::new("cargo")
|
||||||
|
.current_dir(&build_path)
|
||||||
|
.arg("aoc")
|
||||||
|
.arg("bench")
|
||||||
|
.output()?
|
||||||
|
);
|
||||||
|
// Copy files from `target/` to serving directory
|
||||||
|
let bench_path = build_path.join("target/aoc/aoc-autobench/target/criterion");
|
||||||
|
copy_dir_all(bench_path, config.www_root.join(repo))?;
|
||||||
|
let response = format!("{:?}", output);
|
||||||
|
info!("{}", response);
|
||||||
|
Ok(response)
|
||||||
|
}
|
||||||
|
|
||||||
|
// From https://stackoverflow.com/questions/26958489/how-to-copy-a-folder-recursively-in-rust
|
||||||
|
fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> {
|
||||||
|
fs::create_dir_all(&dst)?;
|
||||||
|
for entry in fs::read_dir(src)? {
|
||||||
|
let entry = entry?;
|
||||||
|
let ty = entry.file_type()?;
|
||||||
|
if ty.is_dir() {
|
||||||
|
copy_dir_all(entry.path(), dst.as_ref().join(entry.file_name()))?;
|
||||||
|
} else {
|
||||||
|
fs::copy(entry.path(), dst.as_ref().join(entry.file_name()))?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/")]
|
||||||
|
fn index() -> &'static str {
|
||||||
|
info!("Hello world");
|
||||||
|
"Hello, world!"
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
struct Config {
|
||||||
|
source_root: PathBuf,
|
||||||
|
build_root: PathBuf,
|
||||||
|
www_root: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[launch]
|
||||||
|
fn rocket() -> _ {
|
||||||
|
glog::new()
|
||||||
|
.init(Flags {
|
||||||
|
colorlogtostderr: true,
|
||||||
|
//alsologtostderr: true, // use logtostderr to only write to stderr and not to files
|
||||||
|
logtostderr: true,
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
rocket::build()
|
||||||
|
.mount("/", routes![index, get_reload, post_reload])
|
||||||
|
.attach(AdHoc::config::<Config>())
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user