refactor(ptth_relay): replace custom Git version embedding with `git-version` crate

main
_ 2024-01-21 20:05:18 -06:00
parent 804ab9d8ff
commit 57058e5c0f
7 changed files with 59 additions and 39 deletions

72
Cargo.lock generated
View File

@ -65,7 +65,7 @@ checksum = "31e6e93155431f3931513b243d371981bb2770112b370c82745a1d19d2f99364"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.105",
] ]
[[package]] [[package]]
@ -315,7 +315,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"scratch", "scratch",
"syn", "syn 1.0.105",
] ]
[[package]] [[package]]
@ -332,7 +332,7 @@ checksum = "1362b0ddcfc4eb0a1f57b68bd77dd99f0e826958a96abd0ae9bd092e114ffed6"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.105",
] ]
[[package]] [[package]]
@ -526,7 +526,7 @@ checksum = "bdfb8ce053d86b91919aad980c220b1fb8401a9394410e1c289ed7e66b61835d"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.105",
] ]
[[package]] [[package]]
@ -589,6 +589,26 @@ dependencies = [
"wasi 0.11.0+wasi-snapshot-preview1", "wasi 0.11.0+wasi-snapshot-preview1",
] ]
[[package]]
name = "git-version"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ad568aa3db0fcbc81f2f116137f263d7304f512a1209b35b85150d3ef88ad19"
dependencies = [
"git-version-macro",
]
[[package]]
name = "git-version-macro"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53010ccb100b96a67bc32c0175f0ed1426b31b655d562898e57325f81c023ac0"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.48",
]
[[package]] [[package]]
name = "h2" name = "h2"
version = "0.3.15" version = "0.3.15"
@ -1010,7 +1030,7 @@ checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.105",
] ]
[[package]] [[package]]
@ -1112,7 +1132,7 @@ dependencies = [
"pest_meta", "pest_meta",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.105",
] ]
[[package]] [[package]]
@ -1143,7 +1163,7 @@ checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.105",
] ]
[[package]] [[package]]
@ -1179,7 +1199,7 @@ dependencies = [
"proc-macro-error-attr", "proc-macro-error-attr",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.105",
"version_check", "version_check",
] ]
@ -1196,9 +1216,9 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.47" version = "1.0.78"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@ -1344,6 +1364,7 @@ dependencies = [
"dashmap", "dashmap",
"futures", "futures",
"futures-util", "futures-util",
"git-version",
"handlebars", "handlebars",
"http", "http",
"hyper", "hyper",
@ -1498,9 +1519,9 @@ dependencies = [
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.21" version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
] ]
@ -1702,7 +1723,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"rust-embed-utils", "rust-embed-utils",
"syn", "syn 1.0.105",
"walkdir", "walkdir",
] ]
@ -1866,7 +1887,7 @@ checksum = "255abe9a125a985c05190d687b320c12f9b1f0b99445e608c21ba0782c719ad8"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.105",
] ]
[[package]] [[package]]
@ -2009,7 +2030,7 @@ dependencies = [
"proc-macro-error", "proc-macro-error",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.105",
] ]
[[package]] [[package]]
@ -2029,6 +2050,17 @@ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "syn"
version = "2.0.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]] [[package]]
name = "tempfile" name = "tempfile"
version = "3.3.0" version = "3.3.0"
@ -2078,7 +2110,7 @@ checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.105",
] ]
[[package]] [[package]]
@ -2160,7 +2192,7 @@ checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.105",
] ]
[[package]] [[package]]
@ -2244,7 +2276,7 @@ checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.105",
] ]
[[package]] [[package]]
@ -2504,7 +2536,7 @@ dependencies = [
"once_cell", "once_cell",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.105",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
@ -2538,7 +2570,7 @@ checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.105",
"wasm-bindgen-backend", "wasm-bindgen-backend",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]

View File

@ -78,7 +78,4 @@ WORKDIR /home/ptth_user
COPY --from=build /ptth/target/release/ptth_relay ./ COPY --from=build /ptth/target/release/ptth_relay ./
COPY --from=build /ptth/handlebars/relay ./handlebars/relay COPY --from=build /ptth/handlebars/relay ./handlebars/relay
ARG git_version
RUN echo -n "$git_version" > ./git_version.txt
CMD ["/usr/bin/tini", "--", "./ptth_relay"] CMD ["/usr/bin/tini", "--", "./ptth_relay"]

View File

@ -8,12 +8,11 @@ DOCKER_TAG="ptth:latest"
mkdir -p app_packages mkdir -p app_packages
git archive --format=tar "$GIT_COMMIT" | sudo docker build -t "$DOCKER_TAG" --build-arg "git_version=$GIT_COMMIT" - git archive --format=tar "$GIT_COMMIT" | sudo docker build -t "$DOCKER_TAG" -
sudo docker run --rm "$DOCKER_TAG" tar -c \ sudo docker run --rm "$DOCKER_TAG" tar -c \
ptth_relay \ ptth_relay \
handlebars \ handlebars \
git_version.txt \
| gzip > "app_packages/ptth_relay_$GIT_COMMIT_SHORT.tar.gz" | gzip > "app_packages/ptth_relay_$GIT_COMMIT_SHORT.tar.gz"
sudo docker build -f app_package_Dockerfile -t ptth_app_host:latest . sudo docker build -f app_package_Dockerfile -t ptth_app_host:latest .

View File

@ -38,6 +38,7 @@ tracing-futures = "0.2.4"
tracing-subscriber = "0.2.15" tracing-subscriber = "0.2.15"
ptth_core = { path = "../ptth_core", version = "2.0.0" } ptth_core = { path = "../ptth_core", version = "2.0.0" }
git-version = "0.3.9"
[dependencies.reqwest] [dependencies.reqwest]
version = "0.11.13" version = "0.11.13"

View File

@ -1,3 +1,3 @@
pub async fn read () -> Option <String> { pub fn read () -> &'static str {
tokio::fs::read_to_string ("git_version.txt").await.ok () git_version::git_version!(args = ["--abbrev=16", "--always", "--dirty=-modified"])
} }

View File

@ -264,7 +264,7 @@ struct ServerEntry <'a> {
#[derive (Serialize)] #[derive (Serialize)]
struct ServerListPage <'a> { struct ServerListPage <'a> {
dev_mode: bool, dev_mode: bool,
git_version: Option <String>, git_version: &'static str,
servers: Vec <ServerEntry <'a>>, servers: Vec <ServerEntry <'a>>,
news_url: Option <String>, news_url: Option <String>,
connected_server_count: usize, connected_server_count: usize,
@ -308,7 +308,7 @@ async fn handle_server_list_internal (state: &Relay)
dev_mode = guard.iso.dev_mode.is_some (); dev_mode = guard.iso.dev_mode.is_some ();
news_url = guard.news_url.clone (); news_url = guard.news_url.clone ();
} }
let git_version = git_version::read ().await; let git_version = git_version::read ();
let server_list = scraper_api::v1_server_list (&state).await; let server_list = scraper_api::v1_server_list (&state).await;
@ -780,12 +780,7 @@ pub async fn run_relay (
{ {
let handlebars = Arc::new (load_templates (asset_root)?); let handlebars = Arc::new (load_templates (asset_root)?);
if let Some (x) = git_version::read ().await { info! ("ptth_relay Git version: {}", git_version::read ());
info! ("ptth_relay Git version: {:?}", x);
}
else {
info! ("ptth_relay not built from Git");
}
if let Some (config_reload_path) = config_reload_path { if let Some (config_reload_path) = config_reload_path {
let state_2 = state.clone (); let state_2 = state.clone ();

View File

@ -90,11 +90,7 @@ AIABAACAAQAAgAEAAIABAACAAQAAgAEAAIABAACAAQAA" rel="icon" type="image/x-icon" />
<a href="../audit_log">Audit log</a> <a href="../audit_log">Audit log</a>
<div style="color: #888; padding-top: 1em;"> <div style="color: #888; padding-top: 1em;">
{{#if git_version}}
Git version: {{git_version}} Git version: {{git_version}}
{{else}}
Not built from Git
{{/if}}
<p> <p>
Rendered by PTTH relay server. Rendered by PTTH relay server.