Add git2 to access git
This commit is contained in:
parent
ffcf553126
commit
2570644a90
2 changed files with 36 additions and 3 deletions
|
|
@ -6,6 +6,7 @@ edition = "2021"
|
|||
[dependencies]
|
||||
axum = { version = "0.8.1" }
|
||||
bollard = { version = "0.18.1", registry = "cratesio" }
|
||||
git2 = { version = "0.20.0" }
|
||||
tokio = { version = "1.43.0", features = ["full"] }
|
||||
tower-http = { version = "0.6.2", features = ["trace"] }
|
||||
tracing = { version = "0.1.41" }
|
||||
|
|
|
|||
|
|
@ -1,10 +1,32 @@
|
|||
use std::process::ExitCode;
|
||||
|
||||
use axum::Router;
|
||||
use axum::{routing::get, Router};
|
||||
use bollard::Docker;
|
||||
use git2::Repository;
|
||||
use tower_http::trace::TraceLayer;
|
||||
use tracing::level_filters::LevelFilter;
|
||||
|
||||
#[tokio::main]
|
||||
async fn download_repository(url: &str, name: &str) {
|
||||
let folder = format!("/tmp/{name}");
|
||||
|
||||
match tokio::fs::try_exists(&folder).await {
|
||||
Ok(true) => {
|
||||
let repo = Repository::open(folder).unwrap();
|
||||
repo.find_remote("origin")
|
||||
.unwrap()
|
||||
.fetch(&["main"], None, None)
|
||||
.unwrap();
|
||||
}
|
||||
Ok(false) => {
|
||||
Repository::clone(url, folder).unwrap();
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::error!("{error}");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> ExitCode {
|
||||
let docker = match Docker::connect_with_socket_defaults() {
|
||||
|
|
@ -33,7 +55,7 @@ async fn main() -> ExitCode {
|
|||
return ExitCode::FAILURE;
|
||||
}
|
||||
|
||||
tracing::info!("Launching microdeploy on {bind}");
|
||||
tracing::info!("launching microdeploy on {bind}");
|
||||
|
||||
let listener = match tokio::net::TcpListener::bind(&bind).await {
|
||||
Ok(listener) => listener,
|
||||
|
|
@ -43,7 +65,17 @@ async fn main() -> ExitCode {
|
|||
}
|
||||
};
|
||||
|
||||
let app = Router::new().layer(TraceLayer::new_for_http());
|
||||
let app = Router::new()
|
||||
.route(
|
||||
"/api/v1/image/build",
|
||||
get({
|
||||
download_repository("URL", "microdeploy");
|
||||
|
||||
"todo"
|
||||
}),
|
||||
)
|
||||
.route("/api/v1/image/serve", get("todo"))
|
||||
.layer(TraceLayer::new_for_http());
|
||||
|
||||
match axum::serve(listener, app).await {
|
||||
Ok(()) => ExitCode::SUCCESS,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue