Initial binary definition
This commit is contained in:
parent
347ceb8df8
commit
ffcf553126
2 changed files with 79 additions and 0 deletions
24
Cargo.toml
Normal file
24
Cargo.toml
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
[package]
|
||||
name = "microdeploy"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
axum = { version = "0.8.1" }
|
||||
bollard = { version = "0.18.1", registry = "cratesio" }
|
||||
tokio = { version = "1.43.0", features = ["full"] }
|
||||
tower-http = { version = "0.6.2", features = ["trace"] }
|
||||
tracing = { version = "0.1.41" }
|
||||
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
|
||||
|
||||
[[bin]]
|
||||
name = "microdeploy"
|
||||
path = "src/bin/main.rs"
|
||||
|
||||
[profile.release]
|
||||
debug = false
|
||||
lto = false
|
||||
codegen-units = 1
|
||||
strip = "debuginfo"
|
||||
incremental = false
|
||||
panic = "abort"
|
||||
55
src/bin/main.rs
Normal file
55
src/bin/main.rs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
use std::process::ExitCode;
|
||||
|
||||
use axum::Router;
|
||||
use bollard::Docker;
|
||||
use tower_http::trace::TraceLayer;
|
||||
use tracing::level_filters::LevelFilter;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> ExitCode {
|
||||
let docker = match Docker::connect_with_socket_defaults() {
|
||||
Ok(docker) => docker,
|
||||
Err(error) => {
|
||||
eprintln!("failed to connect docker socket: {error}");
|
||||
return ExitCode::FAILURE;
|
||||
}
|
||||
};
|
||||
|
||||
match docker.version().await {
|
||||
Ok(version) => println!("docker version: {version:?}"),
|
||||
Err(error) => {
|
||||
eprintln!("failed to read docker version: {error}");
|
||||
return ExitCode::FAILURE;
|
||||
}
|
||||
};
|
||||
|
||||
let bind = std::env::var("BIND").unwrap_or("0.0.0.0:8080".into());
|
||||
|
||||
if let Err(error) = tracing_subscriber::fmt()
|
||||
.with_max_level(LevelFilter::DEBUG)
|
||||
.try_init()
|
||||
{
|
||||
eprintln!("failed to register a global tracing logger: {error}");
|
||||
return ExitCode::FAILURE;
|
||||
}
|
||||
|
||||
tracing::info!("Launching microdeploy on {bind}");
|
||||
|
||||
let listener = match tokio::net::TcpListener::bind(&bind).await {
|
||||
Ok(listener) => listener,
|
||||
Err(error) => {
|
||||
tracing::error!("TcpListener::bind({bind}): {error}");
|
||||
return ExitCode::FAILURE;
|
||||
}
|
||||
};
|
||||
|
||||
let app = Router::new().layer(TraceLayer::new_for_http());
|
||||
|
||||
match axum::serve(listener, app).await {
|
||||
Ok(()) => ExitCode::SUCCESS,
|
||||
Err(error) => {
|
||||
tracing::error!("axum::serve: {error}");
|
||||
ExitCode::FAILURE
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue