mirror of
https://git.asonix.dog/asonix/relay.git
synced 2024-12-23 03:36:30 +00:00
Include version info in builds
This commit is contained in:
parent
d26ff4a7cb
commit
a53c8a0a63
8 changed files with 110 additions and 21 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1969,6 +1969,7 @@ dependencies = [
|
||||||
"sled",
|
"sled",
|
||||||
"structopt",
|
"structopt",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
|
"toml",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-actix-web",
|
"tracing-actix-web",
|
||||||
"tracing-error",
|
"tracing-error",
|
||||||
|
|
|
@ -73,6 +73,7 @@ branch = "asonix/tracing-error-work-around"
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
dotenv = "0.15.0"
|
dotenv = "0.15.0"
|
||||||
ructe = { version = "0.13.0", features = ["sass", "mime03"] }
|
ructe = { version = "0.13.0", features = ["sass", "mime03"] }
|
||||||
|
toml = "0.5.8"
|
||||||
|
|
||||||
[profile.dev.package.rsa]
|
[profile.dev.package.rsa]
|
||||||
opt-level = 3
|
opt-level = 3
|
||||||
|
|
44
src/build.rs
44
src/build.rs
|
@ -1,8 +1,52 @@
|
||||||
use ructe::Ructe;
|
use ructe::Ructe;
|
||||||
|
use std::{fs::File, io::Read, path::Path, process::Command};
|
||||||
|
|
||||||
|
fn git_info() {
|
||||||
|
if let Ok(output) = Command::new("git").args(["rev-parse", "HEAD"]).output() {
|
||||||
|
if output.status.success() {
|
||||||
|
let git_hash = String::from_utf8_lossy(&output.stdout);
|
||||||
|
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(output) = Command::new("git")
|
||||||
|
.args(["rev-parse", "--abbrev-ref", "HEAD"])
|
||||||
|
.output()
|
||||||
|
{
|
||||||
|
if output.status.success() {
|
||||||
|
let git_branch = String::from_utf8_lossy(&output.stdout);
|
||||||
|
println!("cargo:rustc-env=GIT_BRANCH={}", git_branch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn version_info() -> Result<(), anyhow::Error> {
|
||||||
|
let cargo_toml = Path::new(&std::env::var("CARGO_MANIFEST_DIR")?).join("Cargo.toml");
|
||||||
|
|
||||||
|
let mut file = File::open(&cargo_toml)?;
|
||||||
|
|
||||||
|
let mut cargo_data = String::new();
|
||||||
|
file.read_to_string(&mut cargo_data)?;
|
||||||
|
|
||||||
|
let data: toml::Value = toml::from_str(&cargo_data)?;
|
||||||
|
|
||||||
|
if let Some(version) = data["package"]["version"].as_str() {
|
||||||
|
println!("cargo:rustc-env=PKG_VERSION={}", version);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(name) = data["package"]["name"].as_str() {
|
||||||
|
println!("cargo:rustc-env=PKG_NAME={}", name);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), anyhow::Error> {
|
fn main() -> Result<(), anyhow::Error> {
|
||||||
dotenv::dotenv().ok();
|
dotenv::dotenv().ok();
|
||||||
|
|
||||||
|
git_info();
|
||||||
|
version_info()?;
|
||||||
|
|
||||||
let mut ructe = Ructe::from_env()?;
|
let mut ructe = Ructe::from_env()?;
|
||||||
let mut statics = ructe.statics()?;
|
let mut statics = ructe.statics()?;
|
||||||
statics.add_sass_file("scss/index.scss")?;
|
statics.add_sass_file("scss/index.scss")?;
|
||||||
|
|
|
@ -144,12 +144,49 @@ impl Config {
|
||||||
format!("relay@{}", self.hostname)
|
format!("relay@{}", self.hostname)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn software_name(&self) -> String {
|
pub(crate) fn software_name() -> &'static str {
|
||||||
"AodeRelay".to_owned()
|
"AodeRelay"
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn software_version(&self) -> String {
|
pub(crate) fn software_version() -> String {
|
||||||
"v0.3.0-main".to_owned()
|
if let Some(git) = Self::git_version() {
|
||||||
|
return format!("v{}-{}", Self::version(), git);
|
||||||
|
}
|
||||||
|
|
||||||
|
format!("v{}", Self::version())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn git_version() -> Option<String> {
|
||||||
|
let branch = Self::git_branch()?;
|
||||||
|
let hash = Self::git_hash()?;
|
||||||
|
|
||||||
|
Some(format!("{}-{}", branch, hash))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn name() -> &'static str {
|
||||||
|
env!("PKG_NAME")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn version() -> &'static str {
|
||||||
|
env!("PKG_VERSION")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn git_branch() -> Option<&'static str> {
|
||||||
|
option_env!("GIT_BRANCH")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn git_hash() -> Option<&'static str> {
|
||||||
|
option_env!("GIT_HASH")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn user_agent(&self) -> String {
|
||||||
|
format!(
|
||||||
|
"{} ({}/{}; +{})",
|
||||||
|
Self::software_name(),
|
||||||
|
Self::name(),
|
||||||
|
Self::software_version(),
|
||||||
|
self.generate_url(UrlKind::Index),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn source_code(&self) -> &Url {
|
pub(crate) fn source_code(&self) -> &Url {
|
||||||
|
|
|
@ -48,12 +48,7 @@ impl State {
|
||||||
Requests::new(
|
Requests::new(
|
||||||
self.config.generate_url(UrlKind::MainKey).to_string(),
|
self.config.generate_url(UrlKind::MainKey).to_string(),
|
||||||
self.private_key.clone(),
|
self.private_key.clone(),
|
||||||
format!(
|
self.config.user_agent(),
|
||||||
"Actix Web 4.0.0-beta.9 ({}/{}; +{})",
|
|
||||||
self.config.software_name(),
|
|
||||||
self.config.software_version(),
|
|
||||||
self.config.generate_url(UrlKind::Index),
|
|
||||||
),
|
|
||||||
self.breakers.clone(),
|
self.breakers.clone(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
27
src/main.rs
27
src/main.rs
|
@ -1,3 +1,4 @@
|
||||||
|
use activitystreams::url::Url;
|
||||||
use actix_web::{web, App, HttpServer};
|
use actix_web::{web, App, HttpServer};
|
||||||
use opentelemetry::{sdk::Resource, KeyValue};
|
use opentelemetry::{sdk::Resource, KeyValue};
|
||||||
use opentelemetry_otlp::WithExportConfig;
|
use opentelemetry_otlp::WithExportConfig;
|
||||||
|
@ -27,12 +28,10 @@ use self::{
|
||||||
routes::{actor, inbox, index, nodeinfo, nodeinfo_meta, statics},
|
routes::{actor, inbox, index, nodeinfo, nodeinfo_meta, statics},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[actix_rt::main]
|
fn init_subscriber(
|
||||||
async fn main() -> Result<(), anyhow::Error> {
|
software_name: &'static str,
|
||||||
dotenv::dotenv().ok();
|
opentelemetry_url: Option<&Url>,
|
||||||
|
) -> Result<(), anyhow::Error> {
|
||||||
let config = Config::build()?;
|
|
||||||
|
|
||||||
LogTracer::init()?;
|
LogTracer::init()?;
|
||||||
|
|
||||||
let env_filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));
|
let env_filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));
|
||||||
|
@ -46,12 +45,12 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||||
.with(ErrorLayer::default())
|
.with(ErrorLayer::default())
|
||||||
.with(format_layer);
|
.with(format_layer);
|
||||||
|
|
||||||
if let Some(url) = config.opentelemetry_url() {
|
if let Some(url) = opentelemetry_url {
|
||||||
let tracer =
|
let tracer =
|
||||||
opentelemetry_otlp::new_pipeline()
|
opentelemetry_otlp::new_pipeline()
|
||||||
.tracing()
|
.tracing()
|
||||||
.with_trace_config(opentelemetry::sdk::trace::config().with_resource(
|
.with_trace_config(opentelemetry::sdk::trace::config().with_resource(
|
||||||
Resource::new(vec![KeyValue::new("service.name", config.software_name())]),
|
Resource::new(vec![KeyValue::new("service.name", software_name)]),
|
||||||
))
|
))
|
||||||
.with_exporter(
|
.with_exporter(
|
||||||
opentelemetry_otlp::new_exporter()
|
opentelemetry_otlp::new_exporter()
|
||||||
|
@ -68,6 +67,17 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||||
tracing::subscriber::set_global_default(subscriber)?;
|
tracing::subscriber::set_global_default(subscriber)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_rt::main]
|
||||||
|
async fn main() -> Result<(), anyhow::Error> {
|
||||||
|
dotenv::dotenv().ok();
|
||||||
|
|
||||||
|
let config = Config::build()?;
|
||||||
|
|
||||||
|
init_subscriber(Config::software_name(), config.opentelemetry_url())?;
|
||||||
|
|
||||||
let db = Db::build(&config)?;
|
let db = Db::build(&config)?;
|
||||||
|
|
||||||
let args = Args::new();
|
let args = Args::new();
|
||||||
|
@ -133,6 +143,7 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||||
.bind(bind_address)?
|
.bind(bind_address)?
|
||||||
.run()
|
.run()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,8 +31,8 @@ pub(crate) async fn route(
|
||||||
web::Json(NodeInfo {
|
web::Json(NodeInfo {
|
||||||
version: NodeInfoVersion,
|
version: NodeInfoVersion,
|
||||||
software: Software {
|
software: Software {
|
||||||
name: config.software_name().to_lowercase(),
|
name: Config::software_name().to_lowercase(),
|
||||||
version: config.software_version(),
|
version: Config::software_version(),
|
||||||
},
|
},
|
||||||
protocols: vec![Protocol::ActivityPub],
|
protocols: vec![Protocol::ActivityPub],
|
||||||
services: Services {
|
services: Services {
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
<body>
|
<body>
|
||||||
<header>
|
<header>
|
||||||
<div class="header-text">
|
<div class="header-text">
|
||||||
<h1>@config.software_name()<span class="smaller">@config.software_version()</span></h1>
|
<h1>@Config::software_name()<span class="smaller">@Config::software_version()</span></h1>
|
||||||
<p>on @config.hostname()</p>
|
<p>on @config.hostname()</p>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
Loading…
Reference in a new issue