forked from github-starred/komodo
write the basic git clone function
This commit is contained in:
5
Cargo.lock
generated
5
Cargo.lock
generated
@@ -745,6 +745,11 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "git"
|
name = "git"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"async_timing_util",
|
||||||
|
"run_command",
|
||||||
|
"types",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "h2"
|
name = "h2"
|
||||||
|
|||||||
@@ -6,3 +6,6 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
types = { path = "../types" }
|
||||||
|
run_command = "0.0.5"
|
||||||
|
async_timing_util = "0.1.11"
|
||||||
@@ -1,3 +1,45 @@
|
|||||||
pub struct GitClient;
|
#![allow(unused)]
|
||||||
|
|
||||||
impl GitClient {}
|
use async_timing_util::unix_timestamp_ms;
|
||||||
|
use run_command::async_run_command;
|
||||||
|
use types::Log;
|
||||||
|
|
||||||
|
pub async fn clone_build_repo() {}
|
||||||
|
|
||||||
|
pub async fn clone_deployment_repo() {}
|
||||||
|
|
||||||
|
async fn clone(
|
||||||
|
repo: &str,
|
||||||
|
destination: &str,
|
||||||
|
branch: Option<String>,
|
||||||
|
access_token: Option<String>,
|
||||||
|
) -> Log {
|
||||||
|
let _ = std::fs::remove_dir_all(destination);
|
||||||
|
let access_token = match access_token {
|
||||||
|
Some(token) => {
|
||||||
|
format!("{token}@")
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
format!("")
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let branch = branch.unwrap_or("main".to_string());
|
||||||
|
let repo_url = format!("https://{access_token}github.com/{repo}.git");
|
||||||
|
let command = format!("git clone {repo_url} {destination} -b {branch}");
|
||||||
|
let start_ts = unix_timestamp_ms() as i64;
|
||||||
|
let output = async_run_command(&command).await;
|
||||||
|
let command = if access_token.len() > 0 {
|
||||||
|
command.replace(&access_token, "<TOKEN>")
|
||||||
|
} else {
|
||||||
|
command
|
||||||
|
};
|
||||||
|
Log {
|
||||||
|
stage: "clone repo".to_string(),
|
||||||
|
command,
|
||||||
|
success: output.success(),
|
||||||
|
stdout: output.stdout,
|
||||||
|
stderr: output.stderr,
|
||||||
|
start_ts,
|
||||||
|
end_ts: unix_timestamp_ms() as i64,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use anyhow::{anyhow, Context};
|
|||||||
use reqwest::StatusCode;
|
use reqwest::StatusCode;
|
||||||
use serde::{de::DeserializeOwned, Serialize};
|
use serde::{de::DeserializeOwned, Serialize};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use types::{BasicContainerInfo, Server, Log, Deployment};
|
use types::{BasicContainerInfo, Deployment, Log, Server};
|
||||||
|
|
||||||
pub struct PeripheryClient {
|
pub struct PeripheryClient {
|
||||||
http_client: reqwest::Client,
|
http_client: reqwest::Client,
|
||||||
@@ -32,7 +32,7 @@ impl PeripheryClient {
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn container_stop(
|
pub async fn container_stop(
|
||||||
&self,
|
&self,
|
||||||
server: &Server,
|
server: &Server,
|
||||||
container_name: &str,
|
container_name: &str,
|
||||||
@@ -45,7 +45,7 @@ impl PeripheryClient {
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn container_remove(
|
pub async fn container_remove(
|
||||||
&self,
|
&self,
|
||||||
server: &Server,
|
server: &Server,
|
||||||
container_name: &str,
|
container_name: &str,
|
||||||
@@ -59,12 +59,8 @@ impl PeripheryClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn deploy(&self, server: &Server, deployment: &Deployment) -> anyhow::Result<Log> {
|
pub async fn deploy(&self, server: &Server, deployment: &Deployment) -> anyhow::Result<Log> {
|
||||||
self.post_json(
|
self.post_json(server, &format!("/container/deploy"), deployment)
|
||||||
server,
|
.await
|
||||||
&format!("/container/deploy"),
|
|
||||||
deployment,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_json<R: DeserializeOwned>(
|
async fn get_json<R: DeserializeOwned>(
|
||||||
|
|||||||
@@ -1,2 +1,10 @@
|
|||||||
pub mod container;
|
use axum::Router;
|
||||||
pub mod stats;
|
|
||||||
|
mod container;
|
||||||
|
mod stats;
|
||||||
|
|
||||||
|
pub fn router() -> Router {
|
||||||
|
Router::new()
|
||||||
|
.nest("/container", container::router())
|
||||||
|
.nest("/stats", stats::router())
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,9 +14,7 @@ use api::*;
|
|||||||
async fn main() {
|
async fn main() {
|
||||||
let (port, secrets) = config::load();
|
let (port, secrets) = config::load();
|
||||||
|
|
||||||
let app = Router::new()
|
let app = api::router();
|
||||||
.nest("/container", container::router())
|
|
||||||
.nest("/stats", stats::router());
|
|
||||||
|
|
||||||
println!("starting montior periphery on port {port}");
|
println!("starting montior periphery on port {port}");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user